Backtestsvuerun-20261021-133314#15288

Issue #15288 Merged fix PR #15291 Run 21 Oct 2026 · run-20261021-133314 vuejs/core

KeepAlive caches a never-mounted vnode when a switch lands while an ancestor Suspense is pending

Better

Our patch was judged better than the merged fix.

In this judgment, Patch A = our agent, Patch B = the merged fix.

Both patches stop the crash by refusing to cache the never-mounted vnode, and the independent tests confirm both clear the reported errors. Patch B is exactly the issue's suggested one-line guard, but it leaves the rest of KeepAlive's bookkeeping inconsistent with what actually mounted: the render pass has already added the unmounted PageB's key to `keys` and set `current` to the unmounted vnode. With `max` set (the issue's real-world Nuxt `keepalive: { max: 5 }` case) that orphan key consumes a slot and causes an early prune of a live entry; pruneCacheEntry then finds no cached vnode and falls into the `resetShapeFlag(current)` branch against a vnode that was never mounted, and the still-active PageA branch can be evicted/unmounted out from under the inner Suspense. onBeforeUnmount likewise compares cache entries against the unmounted PageB child instead of the mounted PageA active branch, so PageA is unmounted via the cache loop while also being the Suspense's active branch. Patch A addresses these: getMountedInnerChild resolves to the Suspense branch that is actually mounted, setCache drops the orphan key, repoints `current`, and caches the mounted vnode under its own key (skipping if pruned), and onBeforeUnmount uses the mounted child. Its tests cover the plain switch, switch-then-unmount (asserting onUnmounted fires exactly once), and the `max` scenario (asserting PageA is neither evicted nor unmounted and PageC renders), which would fail on base and would expose B's max-eviction behavior. Patch A is more code and carries some complexity risk, but it is confined to the KeepAlive cache path and matches surrounding conventions (reuses keys/cache/current, comment style). Patch B's single test is adequate but narrower. On correctness under the issue's own scenarios, A is the better fix.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

10m 24s

Wall-clock time in the container

Full test suite

No new failures

1,779 passed · 1 skipped · 1,780 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

247vs 76 merged

Changed lines, ours vs merged

Vue version

3.5.41 (also reproduces on 3.5.40 and 3.6.0-rc.3)

Link to minimal reproduction

https://play.vuejs.org/#eNqNVs1u4zYQfpWBL6RQ2c42uz0YtoFsemhRtLtIc1vtgZHGFhtqSJCUEiMQ0IfoE/ZJCpKyJTsbbC8SNDOc75tf6mV2Y8yia3G2mq1daaXx4NC3ZluQbIy2Hl6gwp0kvNWN0YTkc6hzcLVQSj/d4S4HGx6aftcteaxy2KO/ba1F8r+S84JKzOHP1hkkhzn8hmhulOwQethZ3QDrWmQFFVRqch4qVOIAG+CNy2CzBcIn+Gx1Ix1ybqPIob+XDerWc5tD47JsPK70HjaBEv/yNTsK0Vpt3Wu5qKqIFL0qvV90QrW4MK2reROdLpeRsANfI9x9+nQP62MoWzBIlaQ97LSF66urxsG/f/8DkuCP9tmDr6UD6UAYM1fYoYrehDtQmXIMy+jVeanU3LZEwVd9qKzwUhPoXVRLkl4KBUbscXEkfqe1/xkNbC6Lw18KAiDR4ArYYMXyIJsA8wyiGYB4EnJIOb++usqS1KJvLQGPaak5q2THcmBW62BrwKKoDiwa93lB/ST9jXjEz2KPIa2BRXAR7L5JMxHNByrf4nfO8N2R4NsUkSq0WMVsrYDBDxFiONZHqCndQPUGNifanEUJy6YGH18ZfGQTHyaFO04Ejz5OLh7xcK5mgh176z7W37alby2mtkkhuFXUw7TdeChABltYn2ZoG74mFgZt5BOsIq/ymPFT57REaL/XONEo9c1FRaaJPxaj5uN4U6tUPpYvVl60yq/Oj6RjQ9m+TKVBPjRull8qToHn8AKNeF7BB+jP4L4H+ibjizNQ8zhxcSME9SMeVuGRJNBn0F/yuxB8HT/7i2F5vSJ5thDG3Gry+OwXpaad3C/i3vpFUKViyTjatADTPptuK7R20aBzofZja5LoYDNMFlfiAVUeOyKHx+gn5m0MEzZRG4RjoBt4jOtjMoc/pTkUVZWcZgX1AfR0B/ABcgQ5XzTZKCLRcfZuEd5yLzyCgPkWHuCplgrjAoxrZ9Lk0qWVeVy/LE9TmgN7YNkl2PurkSz7cfHKm0WnVYdVXN3j3VSKssYq4hN2aOdNigw60hWyywCuJwE8hADEwOomhzTuZ+bvX8cb4Gvp00VjtHSasEo0AMnbw1thRocf/g9+yEClKbIPbbhepht/G2q39tgYJTzGaVkPa2KZvmqb3sbi9uUl3pR/aUmcFQWxDPp+vQyqow10c7nbFLOhTRXS3tfFDJw/KNwUs1IrbVdQWtk4TcUs+Dyzhb4f9mCSc5etChqt3gaHbo7KYcIPPCWVqq3QnUKfbUmfOXfrZfjdWS8nGZj1/wEDZfRV

Steps to reproduce

The reproduction drives itself from onMounted — just open it and read the log. The tree is the one Nuxt renders for a page with <NuxtPage keepalive>:

<Suspense>            <!-- root boundary, still pending -->
  <RootDep />         <!-- async setup, resolves after 300ms -->
  <KeepAlive>
    <Suspense>        <!-- per-page boundary -->
      <component :is="page" :key="key" />
    </Suspense>
  </KeepAlive>
</Suspense>
  1. While RootDep is still pending (so parentSuspense.deps > 0), switch the inner page from PageA to PageB.
  2. Let the root boundary resolve.
  3. Switch back to PageA, then to PageB again.

What is expected?

The inner page follows the switches, and no errors are raised.

What is actually happening?

The rendered page is stuck on PageA forever — every later switch is a no-op — and the renderer throws:

Cannot read properties of null (reading 'suspenseId')   // patchSuspense
Cannot read properties of null (reading 'm')            // unmountComponent

In a production build the second one is the more familiar
Uncaught (in promise) TypeError: Cannot destructure property 'bum' of 'instance' as it is null.

Removing the <KeepAlive> and changing nothing else makes both errors go away and navigation work.

System Info

  System:
    OS: Linux 7.0 Ubuntu 26.04 LTS
    CPU: (4) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
    Memory: 5.86 GB / 11.67 GB
  Binaries:
    Node: 24.19.0
    npm: 11.19.0
  npmPackages:
    vue: 3.5.41
  Browsers:
    Chromium (Playwright 1.5x, headless)

Any additional comments?

The chain, as far as I could trace it:

  1. The route change re-renders KeepAlive, so the inner <Suspense> is patched with n1 != null. Because an ancestor boundary is still pending, SuspenseImpl.process takes its early return:
   if (parentSuspense && parentSuspense.deps > 0 && !n1.suspense.isInFallback) {
     n2.suspense = n1.suspense
     n2.suspense.vnode = n2
     n2.el = n1.el
     return
   }

The incoming page vnode is therefore never patched: vnode.component === null, vnode.el === null.

  1. KeepAlive's onUpdated → cacheSubtree still caches it, unconditionally:
   if (isSuspense(instance.subTree.type)) {
     queuePostRenderEffect(() => {
       cache.set(pendingCacheKey, getInnerChild(instance.subTree))
     }, instance.subTree.suspense)
   }
  1. The next render for that key hits the poisoned entry: KeepAlive copies cachedVNode.component (null) onto the new vnode and sets COMPONENT_KEPT_ALIVE, so patchSuspense reads newBranch.component.suspenseId on null, and the teardown that follows calls unmountComponent(null).

Suggested fix — the same shape as the two guards already at that site, i.e. do not cache a vnode that never finished mounting:

const innerChild = getInnerChild(instance.subTree)
if (innerChild.component) {
  cache.set(pendingCacheKey, innerChild)
}

With that guard the page is simply not cached that one time, and the reproduction runs clean.

This looks like a third path into the defect class fixed by #10912 (avoid caching vnode that not been mounted, for #10899) and #11479 (for #6028) — both guard KeepAlive's own subtree, while here it is an ancestor Suspense that is pending.

Real-world context: this is how it surfaced for us — a Nuxt 4 app rendering <NuxtPage :keepalive="{ max: 5 }" />, where a link clicked before hydration finished intermittently left the user on a blank page with Cannot destructure property 'bum' of 'e' as it is null in the console. The window widens with slower hydration, so it shows up under load / on slow clients.

<sub>Investigation and reproduction prepared with Claude Code, on behalf of drunomics.</sub>

The two patches

Our patch+243 −4
packages/runtime-core/__tests__/components/Suspense.spec.tsindex d40f85b86..352fb515f 100644@@ -2111,6 +2111,213 @@ describe('Suspense', () => {     expect(serializeInner(root)).toBe(`<div>async2</div>`)   }) +  test('KeepAlive + Suspense switch while an ancestor Suspense is pending', async () => {+    const RootDep = defineAsyncComponent({+      render() {+        return h('div', 'root')+      },+    })+    const PageA = {+      name: 'PageA',+      render() {+        return h('div', 'pageA')+      },+    }+    const PageB = {+      name: 'PageB',+      render() {+        return h('div', 'pageB')+      },+    }+    const pages = [PageA, PageB]+    const viewRef = ref(0)+    const root = nodeOps.createElement('div')+    const App = {+      render() {+        return h(Suspense, null, {+          default: h(Fragment, null, [+            h(RootDep),+            h(KeepAlive, null, {+              default: () =>+                h(Suspense, null, {+                  default: h(pages[viewRef.value], {+                    key: viewRef.value,+                  }),+                }),+            }),+          ]),+          fallback: h('div', 'loading'),+        })+      },+    }+    render(h(App), root)+    expect(serializeInner(root)).toBe(`<div>loading</div>`)++    // switch the inner page while the ancestor Suspense is still pending+    viewRef.value = 1+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>loading</div>`)++    await Promise.all(deps)+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>root</div><div>pageA</div>`)++    viewRef.value = 0+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>root</div><div>pageA</div>`)++    viewRef.value = 1+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>root</div><div>pageB</div>`)++    viewRef.value = 0+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>root</div><div>pageA</div>`)++    viewRef.value = 1+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>root</div><div>pageB</div>`)++    // unmounting must not touch a never-mounted cached vnode+    render(null, root)+    expect(serializeInner(root)).toBe(``)+  })++  test('KeepAlive + Suspense switch then unmount while an ancestor Suspense is pending', async () => {+    const RootDep = defineAsyncComponent({+      render() {+        return h('div', 'root')+      },+    })+    const unmountedA = vi.fn()+    const PageA = {+      name: 'PageA',+      setup() {+        onUnmounted(unmountedA)+        return () => h('div', 'pageA')+      },+    }+    const PageB = {+      name: 'PageB',+      render() {+        return h('div', 'pageB')+      },+    }+    const pages = [PageA, PageB]+    const viewRef = ref(0)+    const root = nodeOps.createElement('div')+    const App = {+      render() {+        return h(Suspense, null, {+          default: h(Fragment, null, [+            h(RootDep),+            h(KeepAlive, null, {+              default: () =>+                h(Suspense, null, {+                  default: h(pages[viewRef.value], {+                    key: viewRef.value,+                  }),+                }),+            }),+          ]),+          fallback: h('div', 'loading'),+        })+      },+    }+    render(h(App), root)+    expect(serializeInner(root)).toBe(`<div>loading</div>`)++    viewRef.value = 1+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>loading</div>`)++    await Promise.all(deps)+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>root</div><div>pageA</div>`)++    render(null, root)+    expect(serializeInner(root)).toBe(``)+    expect(unmountedA).toHaveBeenCalledTimes(1)+  })++  test('KeepAlive (max) + Suspense switch while an ancestor Suspense is pending', async () => {+    const RootDep = defineAsyncComponent({+      render() {+        return h('div', 'root')+      },+    })+    const unmountedA = vi.fn()+    const PageA = {+      name: 'PageA',+      setup() {+        onUnmounted(unmountedA)+        return () => h('div', 'pageA')+      },+    }+    const PageB = {+      name: 'PageB',+      render() {+        return h('div', 'pageB')+      },+    }+    const PageC = {+      name: 'PageC',+      render() {+        return h('div', 'pageC')+      },+    }+    const pages = [PageA, PageB, PageC]+    const viewRef = ref(0)+    const root = nodeOps.createElement('div')+    const App = {+      render() {+        return h(Suspense, null, {+          default: h(Fragment, null, [+            h(RootDep),+            h(+              KeepAlive,+              { max: 2 },+              {+                default: () =>+                  h(Suspense, null, {+                    default: h(pages[viewRef.value], {+                      key: viewRef.value,+                    }),+                  }),+              },+            ),+          ]),+          fallback: h('div', 'loading'),+        })+      },+    }+    render(h(App), root)+    expect(serializeInner(root)).toBe(`<div>loading</div>`)++    viewRef.value = 1+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>loading</div>`)++    await Promise.all(deps)+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>root</div><div>pageA</div>`)++    // the never-mounted PageB must not take a cache slot, so PageA is kept+    viewRef.value = 2+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>root</div><div>pageC</div>`)+    expect(unmountedA).toHaveBeenCalledTimes(0)++    viewRef.value = 0+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>root</div><div>pageA</div>`)+    expect(unmountedA).toHaveBeenCalledTimes(0)++    render(null, root)+    expect(serializeInner(root)).toBe(``)+    expect(unmountedA).toHaveBeenCalledTimes(1)+  })+   test('KeepAlive + Suspense + comment slot', async () => {     const toggle = ref(false)     const Async = defineAsyncComponent({packages/runtime-core/src/components/KeepAlive.tsindex 55eaf8624..fd5984c5e 100644@@ -241,6 +241,38 @@ const KeepAliveImpl: ComponentOptions = {      // cache sub tree after render     let pendingCacheKey: CacheKey | null = null+    // the inner child that is actually mounted. If the child Suspense was not+    // patched because an ancestor Suspense is still pending, its new content+    // vnode is never mounted and the previous branch is still the active one.+    const getMountedInnerChild = (): VNode => {+      const { subTree } = instance+      const vnode = getInnerChild(subTree)+      if (isSuspense(subTree.type)) {+        const { activeBranch, pendingBranch } = subTree.suspense!+        if (vnode !== activeBranch && vnode !== pendingBranch) {+          const mounted = pendingBranch || activeBranch+          if (mounted && mounted.component) {+            return mounted+          }+        }+      }+      return vnode+    }+    const setCache = (key: CacheKey) => {+      const vnode = getMountedInnerChild()+      if (vnode !== getInnerChild(instance.subTree)) {+        // the pending key belongs to the unmounted vnode, drop it unless it+        // is already cached, and track the mounted one under its own key+        if (!cache.has(key)) keys.delete(key)+        current = vnode+        key = vnode.key == null ? (vnode.type as ConcreteComponent) : vnode.key+        // it has been pruned in the meantime+        if (!keys.has(key)) return+      }+      // avoid caching vnode that has not been mounted+      if (!vnode.component) return+      cache.set(key, vnode)+    }     const cacheSubtree = () => {       // fix #1621, the pendingCacheKey could be 0       if (pendingCacheKey != null) {@@ -248,10 +280,10 @@ const KeepAliveImpl: ComponentOptions = {         // avoid caching vnode that not been mounted         if (isSuspense(instance.subTree.type)) {           queuePostRenderEffect(() => {-            cache.set(pendingCacheKey!, getInnerChild(instance.subTree))+            setCache(pendingCacheKey!)           }, instance.subTree.suspense)         } else {-          cache.set(pendingCacheKey, getInnerChild(instance.subTree))+          setCache(pendingCacheKey)         }       }     }@@ -260,8 +292,8 @@ const KeepAliveImpl: ComponentOptions = {      onBeforeUnmount(() => {       cache.forEach(cached => {-        const { subTree, suspense } = instance-        const vnode = getInnerChild(subTree)+        const { suspense } = instance+        const vnode = getMountedInnerChild()         if (cached.type === vnode.type && cached.key === vnode.key) {           // current instance will be unmounted as part of keep-alive's unmount           resetShapeFlag(vnode) 
Merged fix · PR #15291+75 −1
packages/runtime-core/__tests__/components/Suspense.spec.tsindex d40f85b86..6b6373fab 100644@@ -2111,6 +2111,77 @@ describe('Suspense', () => {     expect(serializeInner(root)).toBe(`<div>async2</div>`)   }) +  // #15288+  test('KeepAlive + Suspense switch while ancestor is pending', async () => {+    let resolveRootDep!: (comp: ComponentOptions) => void+    const rootDep = new Promise<ComponentOptions>(resolve => {+      resolveRootDep = resolve+    })+    const RootDep = defineAsyncComp(() => rootDep)+    const makePage = (name: string) =>+      defineAsyncComponent({+        render: () => h('div', `page ${name}`),+      })+    const PageA = makePage('A')+    const PageB = makePage('B')+    const page = shallowRef(PageA)+    const key = ref('a')+    const root = nodeOps.createElement('div')+    const App = {+      render() {+        return h(Suspense, null, {+          default: h('div', [+            h(RootDep),+            h(KeepAlive, null, {+              default: () =>+                h(Suspense, null, {+                  default: h(page.value, { key: key.value }),+                }),+            }),+          ]),+          fallback: h('div', 'loading'),+        })+      },+    }++    render(h(App), root)+    expect(serializeInner(root)).toBe('<div>loading</div>')++    await Promise.all(deps)+    await nextTick()++    page.value = PageB+    key.value = 'b'+    await nextTick()+    expect(serializeInner(root)).toBe('<div>loading</div>')++    resolveRootDep({+      render: () => h('div', 'root'),+    })+    await rootDep+    await new Promise(r => setTimeout(r))+    await nextTick()+    expect(serializeInner(root)).toBe(+      '<div><div>root</div><div>page A</div></div>',+    )++    page.value = PageA+    key.value = 'a'+    await nextTick()+    expect(serializeInner(root)).toBe(+      '<div><div>root</div><div>page A</div></div>',+    )++    page.value = PageB+    key.value = 'b'+    await nextTick()+    await Promise.all(deps)+    await nextTick()+    expect(serializeInner(root)).toBe(+      '<div><div>root</div><div>page B</div></div>',+    )+  })+   test('KeepAlive + Suspense + comment slot', async () => {     const toggle = ref(false)     const Async = defineAsyncComponent({packages/runtime-core/src/components/KeepAlive.tsindex 55eaf8624..b09152f72 100644@@ -248,7 +248,10 @@ const KeepAliveImpl: ComponentOptions = {         // avoid caching vnode that not been mounted         if (isSuspense(instance.subTree.type)) {           queuePostRenderEffect(() => {-            cache.set(pendingCacheKey!, getInnerChild(instance.subTree))+            const vnode = getInnerChild(instance.subTree)+            if (vnode.component) {+              cache.set(pendingCacheKey!, vnode)+            }           }, instance.subTree.suspense)         } else {           cache.set(pendingCacheKey, getInnerChild(instance.subTree))