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

fix(ssr): fix hydration mismatch warning about mutiple continuous tex… #7301

Closed
wants to merge 1 commit into from

Conversation

zhangzhonghe
Copy link
Member

@zhangzhonghe zhangzhonghe commented Dec 8, 2022

…t vnodes (#7285)

fix #7285

The following Comp will be rendered as a "<div>foo</div>" on the ssr side.

const Comp = defineComponent(() => h('div', ['fo', 'o']))

The "<div>foo</div>" will be rendered as a div element with a single child text node in the browser, but the above Comp will be rendered by Vue as a div element with two child vnodes, so will cause a mismatch warning during hydration.

Copy link

@PraveenNanda124 PraveenNanda124 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@dwin0
Copy link

dwin0 commented Jul 31, 2023

@zhangzhonghe Thanks for providing a fix for this problem. Do you know when it will be merged?

@Ives7
Copy link

Ives7 commented Aug 15, 2023

when it merge?

@skirtles-code
Copy link
Contributor

This fixes the problem for the initial hydration, but it throws an error if the text is subsequently updated:

I think most real use cases will need support for updates.

@sxzz sxzz linked an issue May 25, 2024 that may be closed by this pull request
const nextNode = nextSibling(node)
// because the node's text has been inserted to the container,
// so we need to remove it
remove(node)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an error thrown by the mutation of the component's own state that spawns at renderer.ts line 1494 and it bubbles up until reaching the remove() function

Maybe that remove() function is trying to access the parentNode from the removed node here?

The error stack:

vue.runtime.esm-browser.js:9092 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'parentNode')
    at remove (vue.runtime.esm-browser.js:9092:26)
    at performRemove (vue.runtime.esm-browser.js:7636:7)
    at remove (vue.runtime.esm-browser.js:7650:7)
    at unmount (vue.runtime.esm-browser.js:7605:9)
    at patchKeyedChildren (vue.runtime.esm-browser.js:7402:9)
    at patchChildren (vue.runtime.esm-browser.js:7258:11)
    at patchElement (vue.runtime.esm-browser.js:6722:7)
    at processElement (vue.runtime.esm-browser.js:6557:7)
    at patch (vue.runtime.esm-browser.js:6418:11)
    at ReactiveEffect.componentUpdateFn [as fn] (vue.runtime.esm-browser.js:7152:9)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Rejected
Development

Successfully merging this pull request may close these issues.

Hydration mismatch when using with JSX Vue SSR hydration error (functional components)
8 participants