[Proof of concept] Portals API + Navigation block #36235
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Portals API
The WICG Portals proposal aims to create an API for enabling seamless navigations between sites or pages. One of the use cases is enabling seamless navigations in multi-page applications (like WordPress) enabling the kind of user experience currently reserved for single page applications built with Next.js, Frontity and the like.
chrome://flags/#enable-portals
The document proposes adding a
<portal>
element to to HTML, which would would have a functionality similar to<iframe>
and<link>
combined. The key difference from an iframe being that the<portal>
element would have aportal.activate()
method which when called would seamlessly navigate to the page that was rendered in the portal.Another way of conceptualizing portals would be as a way to safely prerender/preload content. There have been previous attempts at standardizing a similar functionality via
<link rel="prerender">
but it does not actually prerender content as currently implemented in major browsers.At the same time, the support for "high-level navigation patterns" is not planned to be included in the Portals API. To quote from the explainer:
There are many more details included in the explainer which I would encourage you to read because it both explains the objectives and use cases as well as detail other considerations like Security and Accessibility.
This PR
This PR is a simple integration of the Portals API into the Navigation block. The script will preload all pages that a user has added to the Navigation block. For now it is not much more than a proof of concept for how we might want to use the Portals API in the future.
How to see it in action
Some Concerns
Loading multiple portals
After having played around with the API in this PR, I notice that there is no ability to re-use portal elements across different pages. For example, you are on a
/products
page and the Navigation block has created some portals to other pages. You navigate to another page via a portal, let's say a/blog
page. Now, the Navigation block on the/blog
page has to re-create the same portals to other pages again!I have explained this in more details in WICG/portals#276
This is somewhat wasteful and would make it hard to create a user experience on par with that offered by SPAs today.
Accessibility
There are some ongoing discussion as to whether the
<portal>
s should be exposed as links or buttons.Also currently, portals cannot be opened in a new tab in the same way that links do.
Browser support
Currently, only Chrome has implemented a version of this Portals proposal and other browsers have so far postponed even declaring an intent to implement it (Firefox) or have not even acknowledged it officially (Safari, others) https://github.com/WICG/portals#stakeholder-feedback