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(hydration): handle text nodes with 0 during hydration #11772

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ describe('SSR hydration', () => {
// #7285
test('element with multiple continuous text vnodes', async () => {
// should no mismatch warning
const { container } = mountWithHydration('<div>fooo</div>', () =>
h('div', ['fo', createTextVNode('o'), 'o']),
const { container } = mountWithHydration('<div>foo0o</div>', () =>
h('div', ['fo', createTextVNode('o'), 0, 'o']),
)
expect(container.textContent).toBe('fooo')
expect(container.textContent).toBe('foo0o')
})

test('element with elements children', async () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,7 @@ export function createHydrationFunctions(
// JSX-compiled fns, but on the client the browser parses only 1 text
// node.
// look ahead for next possible text vnode
let next = children[i + 1]
if (next && (next = normalizeVNode(next)).type === Text) {
if (i + 1 < l && normalizeVNode(children[i + 1]).type === Text) {
// create an extra TextNode on the client for the next vnode to
// adopt
insert(
Expand Down