From c03a3c5019a3c9088e2a7015e8a0c6842bfb65d6 Mon Sep 17 00:00:00 2001 From: daiwei Date: Fri, 7 Nov 2025 15:58:40 +0800 Subject: [PATCH] wip: handling hydration --- .../runtime-vapor/__tests__/hydration.spec.ts | 28 +++++++++++++++++++ packages/runtime-vapor/src/component.ts | 22 ++++++--------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/packages/runtime-vapor/__tests__/hydration.spec.ts b/packages/runtime-vapor/__tests__/hydration.spec.ts index 17174408ee..7094a0f60a 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 10bd727d0d..d083d7404c 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) -- 2.47.3