question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hydration node mismatch with `.server`/`.client` components

See original GitHub issue

Environment

  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0
  • Nitro Version: 1.0.0
  • Package Manager: npm@7.17.0
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-uy1uwl?file=app.vue

Describe the bug

According to the docs, server-side rendered .server components are replaced with their .client counterparts on the client-side. Unfortunately, this isn’t working as expected and Vue throws an Hydration node mismatch warning even though both files contain the same template without any state dependent dynamic content.

<template>
  <h1>Hello World!</h1>
</template>

Additional context

No response

Logs

[Vue warn]: Hydration node mismatch:
- Client vnode: div 
- Server rendered DOM: <h1>​Hello World!​</h1>​  
  at <Headline.client> 
  at <App key=1 > 
  at <NuxtRoot>

Issue Analytics

  • State:open
  • Created 10 months ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
RajendraUppucommented, Nov 21, 2022

@harlan-zw it’s weird… i’ve checked it out… but take a look at this once: https://stackblitz.com/edit/github-uy1uwl-8peita?file=app.vue it’s some how working fine with this approach in this repo.

1reaction
fkammercommented, Nov 21, 2022

@RajendraUppu you added the <div> tag in app.vue while @harlan-zw added it to the component template.

I can confirm that wrapping <Headline /> inside a <div> in app.vue resolves the issue. If that is for technical reasons, we should point it out in the docs. I consider wrapping everything in a div for no reason bad practice and wouldn’t normally do that.

The duplication of the component @harlan-zw pointed out seems to be an issue on its own. It still happens if the hydration error is resolved with the approach above. I suggest we move that to its own issue.

Therefore the remaining question on this issue is: Do we need a <div> around the component in the parent element or is it a bug?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Vue warn]: Hydration node mismatch: · Issue #1310 - GitHub
[Vue warn]: Failed to resolve component: client-only If this is a native custom element, make sure to exclude it from component resolution via ......
Read more >
Understand and solve hydration errors in Vue.js - sum.cumo
Hydration refers to the client-side process during which Vue takes over the static HTML sent by the server and turns it into dynamic...
Read more >
Hydration Mismatch - vite-plugin-ssr
A hydration mismatch is when the content rendered to HTML in Node.js is not the same than the content rendered in the browser....
Read more >
Should I ignore these kind of warnings? "Hydration node ...
I am using this package "FormKit" for handling forms and validation. it shows this warning for every element I use and I can't...
Read more >
Handling the React server hydration mismatch error
How to resolve the server mismatch error when hydrating a shared React component that can be used in client-side only or server-side rendered ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found