Skip to content
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

<RenderCacheable> causes Hydration Error when wrapped in <Teleport> #81

Closed
VladStepanov opened this issue Nov 14, 2024 · 3 comments
Closed

Comments

@VladStepanov
Copy link

VladStepanov commented Nov 14, 2024

<RenderCacheable> wrapped in <Teleport> causes Hydration error

[Vue warn]: Hydration node mismatch:
- rendered on server: <!--teleport anchor-->
- expected on client: div 

Reproduction: https://stackblitz.com/edit/nuxt-starter-wmm2fr?file=app.vue

Steps to reproduce:

  • Open sandbox
  • Open devtools
  • Wait for nuxt start
  • Catch hydration error

If you have any ideas please share with me. I'm ready to fix

@VladStepanov VladStepanov changed the title Does not work when wrapped in <Teleport> <RenderCacheable> Does not work when wrapped in <Teleport> Nov 14, 2024
@VladStepanov VladStepanov changed the title <RenderCacheable> Does not work when wrapped in <Teleport> <RenderCacheable> causes Hydration Error when wrapped in <Teleport> Nov 14, 2024
@dulnan
Copy link
Owner

dulnan commented Nov 14, 2024

I think this is a bug in Nuxt. Let's use this simple component instead of <RenderCacheable>:

export default defineComponent({
  name: 'TestRender',

  async setup() {
    return () => h('div', 'Test')
  },
})

And then render it like this:

<Teleport to="body">
  <TestRender />
</Teleport>

Which gives the same hydration error:

runtime-core.esm-bundler.js:51 [Vue warn]: Hydration node mismatch:
- rendered on server: <!--teleport anchor-->  
- expected on client: div 
  at <TestRender> 
  at <Default ref=Ref< undefined > > 
  at <LayoutLoader key="default" layoutProps= {ref: RefImpl} name="default" > 
  at <NuxtLayoutProvider layoutProps= {ref: RefImpl} key="default" name="default"  ... > 
  at <NuxtLayout> 
  at <App key=4 > 
  at <NuxtRoot>

However: The moment we remove async from the setup() function, it works:

export default defineComponent({
  name: 'TestRender',

  setup() {
    return () => h('div', 'Test')
  },
})

So it seems to happen only for async components. Since <RenderCacheable> needs to await loading the cached markup it must be async.

I've reported the bug here: nuxt/nuxt#29919

@VladStepanov
Copy link
Author

Seems like I found a relevant issue vuejs/core#6207

@dulnan
Copy link
Owner

dulnan commented Nov 15, 2024

Indeed, looks like it. I have added a note in the docs that using <Teleport> is not possible. I would assume that once the bug has been fixed in Vue it will also work here.

@dulnan dulnan closed this as completed Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants