Portals #1032
Replies: 2 comments 6 replies
-
This seems completely doable from userland as an integration. Enabling it (regardless if by an integration or built into Astro) would disable streaming responses for any page containing a portal tho, since it's contents can only be known when every component renders. |
Beta Was this translation helpful? Give feedback.
-
Are there any new thoughts about this functionality? I was thinking about not adding React-portal functionality since Portals in React are pure client-side components and are related to the interactive content, but rather server-side global slots. For instance, I would expect to have in the layout something like the following:
and inside any other component, I would like to use it as any other slot:
Potentially, if the slot is placed at the end of the document, nothing can affect streaming, but I guess the As far as I can see, there is no possible way to do this in the userland. However, I am pretty new to Astro. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
In addition to slots that work on parent-children relationship, introduce a concept of portals that works from any-level of nesting.
Background & Motivation
The component hierarchy is directly tied to the DOM hierarchy which is not always the best structure for implementing a specific feature.
I am currently thinking of 2 use cases though some more might emerge during discussions:
<head>
section. It's certainly not clean, but I suspect it does have an impact on SEO too.For the first use case, at the moment you may use portals from your favorite client-side library, maybe this would just need some documentation to tell whether portals are supported or not.
However for proper SEO you may want the injection into the head tag to happen during server-side rendering only, it would be ideal to support this directly in Astro.
I've encountered the second use case while working on improving TutorialKit metadata.
Multiple changes were needed to make a proper connection between
.mdx
files and theLayout
component that renders the meta tags:And we still only support a few metadata : image, title, description. A similar work would be needed for more advanced tags like alternate links.
Goals
Example
Related:
stackblitz/tutorialkit#342
withastro/astro#8703
https://react.dev/reference/react-dom/createPortal
Beta Was this translation helpful? Give feedback.
All reactions