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 mismatch at {{ "" }} inside v-for

See original GitHub issue

Version

2.6.14

Reproduction link

codesandbox.io

Steps to reproduce

  • nuxt: v2.15.18
  • node: v16.14.0
<span v-for="(obj, index) in objs" :key="obj.id">{{ "" }}<span>Test</span></span>

Important for me was it in this usecase

<span v-for="(obj, index) in objs" :key="obj.id">{{ index > 0 ? ", " : "" }}<wbr v-if="index > 0"><span>{{obj.text}}</span></span>

I don’t know that much about vue without nuxt, so I can’t say how to reproduce sss, just came here by this comment https://github.com/nuxt/nuxt.js/issues/10390#issuecomment-1100752569

I used nuxt dev with target: 'static' in nuxt.config.

What is expected?

normal hydration

What is actually happening?

I get a hydration mismatch because nuxt on ssr somehow thinks there is a node with empty content and undefined type and on clientside there correctly no node.


Workaround

use instead:

<span v-for="(obj, index) in objs" :key="obj.id"><span>{{ "" }}</span><span>Test</span></span>

resp.

<span v-for="(obj, index) in objs" :key="obj.id"><span v-if="index > 0">, </span><wbr v-if="index > 0"><span>Test</span></span>

First posted issue here: https://github.com/nuxt/nuxt.js/issues/10390

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

8reactions
ywymoshicommented, Apr 18, 2022

<span v-for="(obj, index) in objs" :key="obj.id">{{ index > 0 ", " : "" }}<wbr v-if="index > 0"><span>{{obj.text}}</span></span>

{{ index > 0 ", " : “” }} This sentence is missing a question mark, it should be {{ index > 0 ? ", " : “” }}

3reactions
Fabionicommented, Apr 18, 2022

<span v-for="(obj, index) in objs" :key="obj.id">{{ index > 0 ", " : "" }}<wbr v-if="index > 0"><span>{{obj.text}}</span></span>

{{ index > 0 ", " : “” }} This sentence is missing a question mark, it should be {{ index > 0 ? ", " : “” }}

Obviously just a typo in my question 😄 I corrected it

Read more comments on GitHub >

github_iconTop Results From Across the Web

React 18: Non-recoverable hydration mismatch if ... - GitHub
The hydration mismatch happened due to a mismatch of process.env.NODE_ENV between client and server. The current behavior. Whole UI is unmounted ...
Read more >
Avoiding hydration mismatch when using React hooks
Avoiding hydration mismatch when using React hooks. One of the most difficult classes of bugs to track down and fix are those which...
Read more >
react-hydration-error - Next.js
When css-in-js libraries are not set up for pre-rendering (SSR/SSG) it will often lead to a hydration mismatch. In general this means the...
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 >
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 >

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