-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
TransitionGroup fails to hydrate when child has v-if #6715
Comments
I found that this is because the SSR side allows comment nodes in the TransitionGroup, while on the client side it skips the rendering of comment nodes, so it causes a mismatch warning during hydration. Here is the source code snippet that skips the rendering of comment nodes: core/packages/runtime-core/src/components/BaseTransition.ts Lines 502 to 505 in 5381abc
|
Yup! Looking into it atm. I think one approach would be to pass I suspect the first option causes issues because then the comment node is passed to |
Is there any workaround available for this issue? |
For me it not only happens with v-if child, but also when you have a slot in a reusable transition component (as mentioned in this closed issue #6922): |
Replacing the <!-- error -->
<p v-if="shouldShow">Hello!</p>
<!-- works -->
<p v-for="_ in shouldShow ? [1] : []">Hello!</p> |
I've just run into the same issue using Nuxt. The workaround I found was simply providing a v-else condition to render a self-closing empty element in case the v-if condition returns falsy which seems to solve the comment problem
|
This works for me :
|
It's been a year, Can we consider this now? @sodatea |
This worked for me too, had to make the element hidden so it doesn't mess with my styling, <div class="hidden" v-else /> |
|
Hey, I just experienced the same issue. |
This doesn't reproduce (anymore?). But |
Vue version
3.2.39
Link to minimal reproduction
https://sfc.vuejs.org/#__SSR__eNp9j81uwyAQhF8F7TmAmpxq0Sg99QV65ELiTUNjYLVgV1Xkdy9urCg/Um4wM7vf7AneidTQIzRgCgbqXMG1jUKYT3Yx++JT/ODU01ls/SCO+PtmwVkQg/T7+ty7LqOF9e7gu1a8GF1T5zjN4e3FXRo9r9KPAKMvFWABPlDiIoMj9Z1TrA1P06CdjWyhEf/KpNUTpr+FQymUG637SMcvtUtBb6qnuY/FB5RtCpuVWqrVa22Zy7WuMAe55fSTkSvRwuJqua7igCwZY4uM/BR2l70B3nkP0Ik52jjC+AeJqoxU
Steps to reproduce
No steps necessary, check the rendered output and the warning
What is expected?
The children inside
<TransitionGroup>
are rendered just once and the hydration succeedsWhat is actually happening?
The child in
<TransitionGroup>
is rendered twice and a hydration warning appearsSystem Info
No response
Any additional comments?
I suppose that happens because
<TransitionGroup>
skips comment nodes (they can't be transitioned and have no boundingClientRect), so it expects the actual child but finds a comment node, "fixes" that by adding the expected child node even though it's already there, just one position behindThe text was updated successfully, but these errors were encountered: