From: daiwei Date: Fri, 7 Nov 2025 07:58:40 +0000 (+0800) Subject: wip: handling hydration X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F14064%2Fhead;p=thirdparty%2Fvuejs%2Fcore.git wip: handling hydration --- diff --git a/packages/runtime-vapor/__tests__/hydration.spec.ts b/packages/runtime-vapor/__tests__/hydration.spec.ts index 17174408e..7094a0f60 100644 --- a/packages/runtime-vapor/__tests__/hydration.spec.ts +++ b/packages/runtime-vapor/__tests__/hydration.spec.ts @@ -1065,6 +1065,34 @@ describe('Vapor Mode hydration', () => { `, ) }) + + test('dynamic component fallback with dynamic slots', async () => { + const data = ref({ + name: 'default', + msg: 'foo', + }) + const { container } = await testHydration( + ``, + {}, + data, + ) + + expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot( + `"
foo
"`, + ) + + data.value.msg = 'bar' + await nextTick() + expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot( + `"
bar
"`, + ) + }) }) describe('if', () => { diff --git a/packages/runtime-vapor/src/component.ts b/packages/runtime-vapor/src/component.ts index 10bd727d0..d083d7404 100644 --- a/packages/runtime-vapor/src/component.ts +++ b/packages/runtime-vapor/src/component.ts @@ -665,22 +665,16 @@ export function createComponentWithFallback( setCurrentHydrationNode(el.firstChild) } if (rawSlots.$) { - const frag = - isHydrating || __DEV__ - ? new DynamicFragment('slot') - : new DynamicFragment() - + // ssr output does not contain the slot anchor, use an empty string + // as the anchor label to avoid slot anchor search errors + const frag = new DynamicFragment( + isHydrating ? '' : __DEV__ ? 'slot' : undefined, + ) renderEffect(() => frag.update(getSlot(rawSlots as RawSlots, 'default'))) - - if (!isHydrating) { - const scopeId = currentInstance!.type.__scopeId - if (scopeId) setScopeId(frag, [`${scopeId}-s`]) - insert(frag, el) - } else { - frag.hydrate() - } + if (!isHydrating) insert(frag, el) } else { - insert(getSlot(rawSlots as RawSlots, 'default')!(), el) + const block = getSlot(rawSlots as RawSlots, 'default')!() + if (!isHydrating) insert(block, el) } if (isHydrating) { setCurrentHydrationNode(nextNode)