-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vue Teleport Support #173
Comments
I’ve got a working local pnpm patch based on this Nuxt PR. Misc. notes:
|
Do you have a example of it causing a hydration error? I currently use Teleport perfectly fine within my vite-ssr app. Is the element you're teleporting to rendered by Vue or outside of it like in the raw html? |
I am teleporting to an element outside of Vue in the raw html. I’ve created a simple reproduction on top of the vitesse template. Oddly enough I’m not getting a hydration error. However, the teleported elements are not being rendered on the server (verified using view Page Source). |
Has the problem been solved in the meantime? |
@michaelkplai can you share please an example? |
I have found a test in vue source code: ssrTeleport.spec.ts And here we see how vite-ssr does And here the vue core docs about SSR and teleport: https://vuejs.org/guide/scaling-up/ssr.html#teleports And here the nuxt code with html part bodyPrepend: renderer.ts#L308 And here an example: server.js So, the problem adding a |
I haven't looked at this problem in the last year and have since migrated away from the library. I created a reproduction previously:
Here's the pnpm patch I used before:
|
Like described in the official documentation of vue, we should consider to use an own DOM node: Avoid targeting body when using Teleports and SSR together - usually, will contain other server-rendered content which makes it impossible for Teleports to determine the correct starting location for hydration. Instead, prefer a dedicated container, e.g. We have two possible solutions:
<ClientOnly>
<Teleport to="body">
...
</Teleport>
</ClientOnly>
<Teleport to="#teleported">
...
</Teleport> with ...
<body>
<div id="app"></div>
<div id="teleported"></div>
</body> SSR rendering does something like: teleported = context.teleports['#teleported']
...
// Replace <div id="teleported"> with <div id="teleported" data-server-rendered="true">${teleported} This is a solution for body teleports and SSR only! |
@michaelkplai please take a look at PR #207 |
I wanted to ask about support for Vue’s Teleport Component. Currently, using teleport leads to a hydration error.
Teleport SSR considerations have been documented here. Teleport content is exposed in the Vue context object and must be manually injected into the HTML.
I think this can be implemented by adding a teleports field to
DocParts
and adjusting buildHtmlDocument to inject the teleport content.In the beginning we can support only teleporting to body like Nuxt does. Additional teleport support could be added (full CSS selectors), but it would require a DOM parser or clever regex.
Please let me know if this is a feature we would be interested in adding. I’d be happy to look into creating a PR.
The text was updated successfully, but these errors were encountered: