From: daiwei Date: Tue, 14 Oct 2025 08:28:08 +0000 (+0800) Subject: fix: handling v-for with non-hydration nodes X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7044f6ff529cbc721a83ef65a2b3a365d2478805;p=thirdparty%2Fvuejs%2Fcore.git fix: handling v-for with non-hydration nodes --- diff --git a/packages/runtime-vapor/__tests__/hydration.spec.ts b/packages/runtime-vapor/__tests__/hydration.spec.ts index a20c6f3f55..7de42143f4 100644 --- a/packages/runtime-vapor/__tests__/hydration.spec.ts +++ b/packages/runtime-vapor/__tests__/hydration.spec.ts @@ -1940,6 +1940,57 @@ describe('Vapor Mode hydration', () => { " `) }) + + test('with non-hydration node', async () => { + const data = ref({ show: true, msg: 'foo' }) + const { container } = await testHydration( + ``, + {}, + data, + ) + expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot( + ` + "
+
foo
non-hydration node
foo
non-hydration node
+
" + `, + ) + + data.value.msg = 'bar' + await nextTick() + expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot( + ` + "
+
bar
non-hydration node
bar
non-hydration node
+
" + `, + ) + + data.value.show = false + await nextTick() + expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(` + "
+
non-hydration node
non-hydration node
+
" + `) + + data.value.show = true + await nextTick() + expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(` + "
+
bar
non-hydration node
bar
non-hydration node
+
" + `) + }) }) describe('slots', () => { diff --git a/packages/runtime-vapor/src/apiCreateFor.ts b/packages/runtime-vapor/src/apiCreateFor.ts index 6f7bd2dca5..bdeccce2a5 100644 --- a/packages/runtime-vapor/src/apiCreateFor.ts +++ b/packages/runtime-vapor/src/apiCreateFor.ts @@ -132,18 +132,14 @@ export const createFor = ( if (!isMounted) { isMounted = true - let prevNodes: Block for (let i = 0; i < newLength; i++) { - if (isHydrating && isComponent && i > 0) { - setCurrentHydrationNode(findLastChild(prevNodes!)!.nextSibling) + const nodes = mount(source, i).nodes + if (isHydrating) { + setCurrentHydrationNode(findLastChild(nodes!)!.nextSibling) } - prevNodes = mount(source, i).nodes } if (isHydrating) { - if (isComponent) { - setCurrentHydrationNode(findLastChild(prevNodes!)!.nextSibling) - } parentAnchor = newLength === 0 ? currentHydrationNode!.nextSibling!