]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(transition/ssr): make transition appear work with Suspense in SSR (#12047)
authoredison <daiwei521@126.com>
Fri, 11 Oct 2024 02:34:28 +0000 (10:34 +0800)
committerGitHub <noreply@github.com>
Fri, 11 Oct 2024 02:34:28 +0000 (10:34 +0800)
close #12046

packages/runtime-core/__tests__/hydration.spec.ts
packages/runtime-core/src/hydration.ts

index c98f1f473bd9bd9bb0120c6892fa22649930e6d8..a1fb8cde33f32aba5dee62934d9a5bc2725c4939 100644 (file)
@@ -1613,6 +1613,36 @@ describe('SSR hydration', () => {
     `)
   })
 
+  test('Suspense + transition appear', async () => {
+    const { vnode, container } = mountWithHydration(
+      `<template><div>foo</div></template>`,
+      () =>
+        h(Suspense, {}, () =>
+          h(
+            Transition,
+            { appear: true },
+            {
+              default: () => h('div', 'foo'),
+            },
+          ),
+        ),
+    )
+
+    expect(vnode.el).toBe(container.firstChild)
+    // wait for hydration to finish
+    await new Promise(r => setTimeout(r))
+
+    expect(container.firstChild).toMatchInlineSnapshot(`
+      <div
+        class="v-enter-from v-enter-active"
+      >
+        foo
+      </div>
+    `)
+    await nextTick()
+    expect(vnode.el).toBe(container.firstChild)
+  })
+
   // #10607
   test('update component stable slot (prod + optimized mode)', async () => {
     __DEV__ = false
index 82972e17174b15466a6f23051a60bf8172a4c256..c49db529c38a486e470b64f9df88ea0a358d767c 100644 (file)
@@ -385,7 +385,10 @@ export function createHydrationFunctions(
       let needCallTransitionHooks = false
       if (isTemplateNode(el)) {
         needCallTransitionHooks =
-          needTransition(parentSuspense, transition) &&
+          needTransition(
+            null, // no need check parentSuspense in hydration
+            transition,
+          ) &&
           parentComponent &&
           parentComponent.vnode.props &&
           parentComponent.vnode.props.appear