Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

feat(nitro): support for rendering ssr teleports to body #3909

Merged
merged 16 commits into from
Apr 1, 2022
Merged

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Mar 25, 2022

πŸ”— Linked issue

resolves nuxt/nuxt#12766, nuxt/nuxt#13431

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR adds support for using teleports in Nuxt 3, including an example based on https://vuejs.org/guide/built-ins/teleport.html.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe danielroe added enhancement New feature or request nitro 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing labels Mar 25, 2022
@danielroe danielroe requested a review from pi0 March 25, 2022 16:30
@danielroe danielroe self-assigned this Mar 25, 2022
@netlify
Copy link

netlify bot commented Mar 25, 2022

βœ… Deploy Preview for nuxt3-docs ready!

Name Link
πŸ”¨ Latest commit a963bc0
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/6247000f8266520009b3a51c
😎 Deploy Preview https://deploy-preview-3909--nuxt3-docs.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@danielroe danielroe marked this pull request as draft March 25, 2022 16:47
@pi0
Copy link
Member

pi0 commented Mar 25, 2022

This is a nice initiative, however obviously not best solution using cheerio nor vue3 seems have a proper solution for SSR teleports right now.

It would be nice if we could have a limited parser (maybe #id only selectors) to do a quick replacement?

Before that, it would be nice having a section in docs for Teleports to mention usage limitations and workaround.

Ideally by moving this feature to nitropack, we could make a nitro plugin, and start support teleport behind a flag to avoid overhead when not needed bit nice to try here in meantime.

Another note: If ever we want to start supporting streaming, SSR teleport would be a problem. Which is why thinking focusing on docs and stable client-only support would worth.

@danielroe
Copy link
Member Author

Agreed.

Maybe, priority list of:

  1. docs with workaround for client-only teleport support
  2. implementation with parser supporting <body> (likely the most common) and #id only
  3. (possibly not needed) flag for full cheerio support (or a more advanced custom parser)

For anyone else's reference, teleport SSR support is up to frameworks to implement: see vuejs/core#3869 (comment).

@toniengelhardt
Copy link
Contributor

Small side-node regarding the client-only solution: it would be amazing if the <Teleport> tag would be implicitly client-only and would not require wrapping into a <ClientOnly> tag.

@danielroe
Copy link
Member Author

I've adapted this PR for an ultra-minimal support for teleports, using the existing template. I think that this is a reasonable approach to include out-of-the-box, with more advanced use cases to be developed under a flag later on. (Given that teleports are meant to be outside the Vue app, the body target should cover most use cases, with the client-only approach being an escape hatch only...)

@danielroe danielroe marked this pull request as ready for review March 28, 2022 09:29
docs/content/3.docs/1.usage/10.teleports.md Outdated Show resolved Hide resolved
packages/nuxt3/src/core/templates.ts Outdated Show resolved Hide resolved
@pi0 pi0 changed the title feat(nitro): add support for rendering teleports feat(nitro): support for rendering ssr teleports to body Apr 1, 2022
@pi0 pi0 merged commit fdd38f9 into main Apr 1, 2022
@pi0 pi0 deleted the feat/teleports branch April 1, 2022 14:06
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x enhancement New feature or request nitro 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hydration Error at use teleport
3 participants