From: daiwei Date: Tue, 22 Apr 2025 09:40:31 +0000 (+0800) Subject: wip: save X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c30fd4db94911cd33fcc9247ad34334503c59a2;p=thirdparty%2Fvuejs%2Fcore.git wip: save --- diff --git a/packages/compiler-ssr/__tests__/ssrElement.spec.ts b/packages/compiler-ssr/__tests__/ssrElement.spec.ts index 97601ae9ab..59f6b0ffbc 100644 --- a/packages/compiler-ssr/__tests__/ssrElement.spec.ts +++ b/packages/compiler-ssr/__tests__/ssrElement.spec.ts @@ -398,24 +398,6 @@ describe('ssr: element', () => { }) describe('dynamic child anchor', () => { - test('component with element siblings', () => { - expect( - getCompiledString(` -
-
- -
-
- `), - ).toMatchInlineSnapshot(` - "\`
\`) - _push("") - _push(_ssrRenderComponent(_component_Comp1, null, null, _parent)) - _push("") - _push(\`
\`" - `) - }) - test('with consecutive components', () => { expect( getCompiledString(` diff --git a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts index a130dc427f..48df321337 100644 --- a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts +++ b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts @@ -428,5 +428,24 @@ function shouldAddDynamicAnchor( } } - return hasStaticPreviousSibling && hasStaticNextSibling + let hasConsecutiveDynamicNodes = false + if (index > 0 && index < len - 1) { + if (index > 0 && !isStaticElement(children[index - 1])) { + hasConsecutiveDynamicNodes = true + } + + if ( + !hasConsecutiveDynamicNodes && + index < len - 1 && + !isStaticElement(children[index + 1]) + ) { + hasConsecutiveDynamicNodes = true + } + } + + return ( + hasStaticPreviousSibling && + hasStaticNextSibling && + hasConsecutiveDynamicNodes + ) } diff --git a/packages/runtime-core/__tests__/hydration.spec.ts b/packages/runtime-core/__tests__/hydration.spec.ts index 07a6504b50..a6a8960fb1 100644 --- a/packages/runtime-core/__tests__/hydration.spec.ts +++ b/packages/runtime-core/__tests__/hydration.spec.ts @@ -1844,20 +1844,6 @@ describe('SSR hydration', () => { }) describe('dynamic child anchor', () => { - test('component with element siblings', () => { - const Comp = { - render() { - return createTextVNode('foo') - }, - } - const { vnode, container } = mountWithHydration( - `
foo
`, - () => h('div', null, [h('span'), h(Comp), h('span')]), - ) - expect(vnode.el).toBe(container.firstChild) - expect(`Hydration children mismatch`).not.toHaveBeenWarned() - }) - test('with consecutive components', () => { const Comp = { render() { diff --git a/packages/runtime-vapor/__tests__/hydration.spec.ts b/packages/runtime-vapor/__tests__/hydration.spec.ts index def3c9d924..27ef427a11 100644 --- a/packages/runtime-vapor/__tests__/hydration.spec.ts +++ b/packages/runtime-vapor/__tests__/hydration.spec.ts @@ -241,8 +241,7 @@ describe('Vapor Mode hydration', () => { test('component with anchor insertion', async () => { const { container, data } = await testHydration( - ` -