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