]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(keep-alive): fix render error in cached is undefined (#11496)
authorかっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>
Wed, 7 Aug 2024 03:58:44 +0000 (12:58 +0900)
committerGitHub <noreply@github.com>
Wed, 7 Aug 2024 03:58:44 +0000 (11:58 +0800)
fix #11427
close #11431

packages/runtime-core/__tests__/components/Suspense.spec.ts
packages/runtime-core/src/components/KeepAlive.ts

index 62765dad987bd7e5b76620b3099a69c83df38403..65e801de277f767d4784ced162b1c3f1cfd6e0ef 100644 (file)
@@ -2036,7 +2036,7 @@ describe('Suspense', () => {
     expect(serializeInner(root)).toBe(`<div>sync</div>`)
   })
 
-  // #10899
+  // #10899 / #11427
   test('KeepAlive + Suspense switch before branch resolves', async () => {
     const Async1 = defineAsyncComponent({
       render() {
@@ -2053,14 +2053,20 @@ describe('Suspense', () => {
     const root = nodeOps.createElement('div')
     const App = {
       render() {
-        return h(KeepAlive, null, {
-          default: () => {
-            return h(Suspense, null, {
-              default: h(components[viewRef.value]),
-              fallback: h('div', 'loading'),
-            })
+        return h(
+          KeepAlive,
+          {
+            max: 1,
           },
-        })
+          {
+            default: () => {
+              return h(Suspense, null, {
+                default: h(components[viewRef.value]),
+                fallback: h('div', 'loading'),
+              })
+            },
+          },
+        )
       },
     }
     render(h(App), root)
index 74cb1b1c12d20181f335d3d92e83a5c87176a5f2..8fe1088b26b78cfb3286a87d94508ba999a3e96b 100644 (file)
@@ -206,7 +206,7 @@ const KeepAliveImpl: ComponentOptions = {
 
     function pruneCacheEntry(key: CacheKey) {
       const cached = cache.get(key) as VNode
-      if (!current || !isSameVNodeType(cached, current)) {
+      if (cached && (!current || !isSameVNodeType(cached, current))) {
         unmount(cached)
       } else if (current) {
         // current active instance should no longer be kept-alive.