From e70f4c47c553b6e16d8fad70743271ca23802fe7 Mon Sep 17 00:00:00 2001 From: edison Date: Sat, 16 Dec 2023 11:55:40 +0800 Subject: [PATCH 1/7] fix(hydration): handle appear transition before patch props (#9837) close #9832 --- .../runtime-core/__tests__/hydration.spec.ts | 35 +++++++++++++++ packages/runtime-core/src/hydration.ts | 43 ++++++++++--------- 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/packages/runtime-core/__tests__/hydration.spec.ts b/packages/runtime-core/__tests__/hydration.spec.ts index 2b85cc974a4..39cb921bf60 100644 --- a/packages/runtime-core/__tests__/hydration.spec.ts +++ b/packages/runtime-core/__tests__/hydration.spec.ts @@ -1114,6 +1114,41 @@ describe('SSR hydration', () => { expect(`mismatch`).not.toHaveBeenWarned() }) + test('transition appear w/ event listener', async () => { + const container = document.createElement('div') + container.innerHTML = `` + createSSRApp({ + data() { + return { + count: 0 + } + }, + template: ` + + + + ` + }).mount(container) + + expect(container.firstChild).toMatchInlineSnapshot(` + + `) + + triggerEvent('click', container.querySelector('button')!) + await nextTick() + expect(container.firstChild).toMatchInlineSnapshot(` + + `) + }) + describe('mismatch handling', () => { test('text node', () => { const { container } = mountWithHydration(`foo`, () => 'bar') diff --git a/packages/runtime-core/src/hydration.ts b/packages/runtime-core/src/hydration.ts index 94d6e8f6277..1107bd6566d 100644 --- a/packages/runtime-core/src/hydration.ts +++ b/packages/runtime-core/src/hydration.ts @@ -344,6 +344,28 @@ export function createHydrationFunctions( if (dirs) { invokeDirectiveHook(vnode, null, parentComponent, 'created') } + + // handle appear transition + let needCallTransitionHooks = false + if (isTemplateNode(el)) { + needCallTransitionHooks = + needTransition(parentSuspense, transition) && + parentComponent && + parentComponent.vnode.props && + parentComponent.vnode.props.appear + + const content = (el as HTMLTemplateElement).content + .firstChild as Element + + if (needCallTransitionHooks) { + transition!.beforeEnter(content) + } + + // replace