Backtestsvuerun-20261013-093701#15288
KeepAlive caches a never-mounted vnode when a switch lands while an ancestor Suspense is pending
Our patch was judged better than the merged fix.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Both patches apply the same core fix suggested in the issue: inside the Suspense branch of `cacheSubtree`'s post-render effect, skip `cache.set` when the inner child has no `component`. Either one stops the poisoned cache entry, so the `suspenseId`/`unmountComponent(null)` crashes go away.
Patch B also calls `keys.delete(pendingCacheKey)` when it skips caching. This matters because KeepAlive's render has already added the key to `keys`. Without the delete, `keys` and `cache` drift apart. With `max` set, the stale key can then be chosen by `pruneCacheEntry`, which does `cache.get(key)` on a missing entry. Depending on the guard, that either throws in `isSameVNodeType(undefined, current)` or counts a phantom entry toward `max`. That in turn can evict a real cached instance too early, unmounting it instead of deactivating it. The issue's real-world context is `<NuxtPage :keepalive="{ max: 5 }" />`, so this edge case is directly relevant. Patch B's handling makes the fix more complete and correct, not just extra hardening.
On tests, Patch B adds two scenarios. The first is the issue's exact switch sequence. The second uses `max: 3` and checks that the never-mounted page does not count toward `max` and that no instance is unmounted. Both would fail before the fix. Patch A's single test also reproduces the issue, but it relies on async pages and `setTimeout` timing and does not cover `max`.
Patch B's comments are clear and fit the surrounding code. Overall, B is the more correct and better-tested fix.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
7m 41s
Wall-clock time in the container
Full test suite
No new failures
1,778 passed · 1 skipped · 1,779 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
146vs 76 merged
Changed lines, ours vs merged
The issue
View on GitHubVue version
3.5.41 (also reproduces on 3.5.40 and 3.6.0-rc.3)
Link to minimal reproduction
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>
- While
RootDepis still pending (soparentSuspense.deps > 0), switch the inner page fromPageAtoPageB. - Let the root boundary resolve.
- Switch back to
PageA, then toPageBagain.
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 familiarUncaught (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:
- The route change re-renders
KeepAlive, so the inner<Suspense>is patched withn1 != null. Because an ancestor boundary is still pending,SuspenseImpl.processtakes 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.
KeepAlive'sonUpdated→cacheSubtreestill caches it, unconditionally:
if (isSuspense(instance.subTree.type)) {
queuePostRenderEffect(() => {
cache.set(pendingCacheKey, getInnerChild(instance.subTree))
}, instance.subTree.suspense)
}
- The next render for that key hits the poisoned entry:
KeepAlivecopiescachedVNode.component(null) onto the new vnode and setsCOMPONENT_KEPT_ALIVE, sopatchSuspensereadsnewBranch.component.suspenseIdonnull, and the teardown that follows callsunmountComponent(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
packages/runtime-core/__tests__/components/Suspense.spec.tsindex d40f85b86..3ac0c6490 100644@@ -2111,6 +2111,140 @@ describe('Suspense', () => { expect(serializeInner(root)).toBe(`<div>async2</div>`) }) + // #15288+ test('KeepAlive + Suspense switch under pending ancestor', async () => {+ const RootDep = defineAsyncComponent({+ render() {+ return h('div', 'root')+ },+ })+ const PageA = {+ render() {+ return h('div', 'pageA')+ },+ }+ const 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('div', [+ 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 root 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><div>root</div><div>pageA</div></div>`,+ )++ viewRef.value = 0+ await nextTick()+ expect(serializeInner(root)).toBe(+ `<div><div>root</div><div>pageA</div></div>`,+ )++ viewRef.value = 1+ await nextTick()+ expect(serializeInner(root)).toBe(+ `<div><div>root</div><div>pageB</div></div>`,+ )++ viewRef.value = 0+ await nextTick()+ expect(serializeInner(root)).toBe(+ `<div><div>root</div><div>pageA</div></div>`,+ )+ })++ // #15288+ test('KeepAlive(max) + Suspense switch under pending ancestor', async () => {+ const RootDep = defineAsyncComponent({+ render() {+ return h('div', 'root')+ },+ })+ const unmounted: string[] = []+ const pages = ['pageA', 'pageB', 'pageC', 'pageD'].map(text => ({+ setup() {+ onUnmounted(() => unmounted.push(text))+ return () => h('div', text)+ },+ }))+ const viewRef = ref(0)+ const root = nodeOps.createElement('div')+ const App = {+ render() {+ return h(Suspense, null, {+ default: h('div', [+ h(RootDep),+ h(+ KeepAlive,+ { max: 3 },+ {+ 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 root Suspense is still pending+ viewRef.value = 1+ await nextTick()++ await Promise.all(deps)+ await nextTick()++ const go = async (index: number, text: string) => {+ viewRef.value = index+ await nextTick()+ expect(serializeInner(root)).toBe(+ `<div><div>root</div><div>${text}</div></div>`,+ )+ }+ await go(0, 'pageA')+ await go(2, 'pageC')+ await go(3, 'pageD')+ // the never-mounted pageB must not count towards `max`+ await go(0, 'pageA')+ expect(unmounted).toEqual([])+ // pageD is still cached and must be deactivated, not unmounted+ await go(3, 'pageD')+ expect(unmounted).toEqual([])+ await go(1, 'pageB')+ })+ test('KeepAlive + Suspense + comment slot', async () => { const toggle = ref(false) const Async = defineAsyncComponent({packages/runtime-core/src/components/KeepAlive.tsindex 55eaf8624..845c3ea9c 100644@@ -248,7 +248,17 @@ const KeepAliveImpl: ComponentOptions = { // avoid caching vnode that not been mounted if (isSuspense(instance.subTree.type)) { queuePostRenderEffect(() => {- cache.set(pendingCacheKey!, getInnerChild(instance.subTree))+ const innerChild = getInnerChild(instance.subTree)+ // #15288 the inner Suspense may have skipped patching its new+ // branch because an ancestor Suspense is still pending, leaving+ // the vnode without a component instance.+ if (innerChild.component) {+ cache.set(pendingCacheKey!, innerChild)+ } else {+ // keep `keys` in sync with `cache` so pruning by `max` does not+ // pick a key that has no cached entry+ keys.delete(pendingCacheKey!)+ } }, instance.subTree.suspense) } else { cache.set(pendingCacheKey, getInnerChild(instance.subTree))
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))