Backtestsvuerun-20261005-155915#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 add the guard the issue proposes. In the Suspense branch of KeepAlive's cacheSubtree, they skip `cache.set` when the inner child has no `component`. That removes the poisoned cache entry behind the `suspenseId`/`unmountComponent(null)` crashes. So on the reported crash, the two are equivalent. The difference is what happens to the branch that actually stayed mounted. The queued effect reads `instance.subTree` and `pendingCacheKey` when it runs, not when it was queued. Once the pending ancestor resolves, the effects from both the initial mount and the update see the new, never-patched subtree under the new key. The mounted page (PageA) therefore never enters the cache. KeepAlive's render still marked its vnode COMPONENT_SHOULD_KEEP_ALIVE, though. With Patch A alone, navigating away from PageA deactivates it instead of unmounting it. Nothing in the cache tracks it, so it is never unmounted, even when the KeepAlive is destroyed. That is a leaked component instance and a lingering hidden DOM subtree. Patch B handles this. When the inner child was never patched, it resets the shape flag on the Suspense's `activeBranch`, unless that component is already cached. The page then unmounts normally when switched away from or torn down. B's tests cover more ground: - Repeated switches after resolution. - Full teardown via `render(null)`. - A dedicated test asserting `onUnmounted` fires for PageA on a switch to a third page and on teardown. This test would fail under Patch A's fix. Patch A's single test checks only the visible output of the reported scenario. B's extra logic is a bit heavier (a linear scan of the cache values), but it is commented, tightly scoped to the failure path, and fixes a real consequence of the same root cause. B is the more complete and correct 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
11m 33s
Wall-clock time in the container
Full test suite
No new failures
3,680 passed · 6 skipped · 3,686 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..68335cdeb 100644@@ -2111,6 +2111,132 @@ describe('Suspense', () => { expect(serializeInner(root)).toBe(`<div>async2</div>`) }) + test('KeepAlive + Suspense switch while ancestor Suspense is pending', async () => {+ const RootDep = defineAsyncComponent({+ render() {+ return h('div', 'root')+ },+ })+ const PageA = { render: () => h('div', 'pageA') }+ const PageB = { render: () => 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>`)++ // tearing down the cache must not hit a never-mounted vnode+ render(null, root)+ expect(serializeInner(root)).toBe(``)+ })++ test('KeepAlive + Suspense switch while ancestor Suspense is pending should not leak the mounted page', async () => {+ const RootDep = defineAsyncComponent({+ render() {+ return h('div', 'root')+ },+ })+ const unmounted: string[] = []+ const createPage = (name: string) => ({+ setup() {+ onUnmounted(() => unmounted.push(name))+ return () => h('div', name)+ },+ })+ const pages = [+ createPage('pageA'),+ createPage('pageB'),+ createPage('pageC'),+ ]+ const viewRef = ref(0)+ 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'),+ })+ },+ }++ const mountAndSwitchWhilePending = async () => {+ const root = nodeOps.createElement('div')+ render(h(App), root)+ viewRef.value = 1+ await nextTick()+ await Promise.all(deps)+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>root</div><div>pageA</div>`)+ return root+ }++ // switching to a third page must unmount the page that stayed mounted+ let root = await mountAndSwitchWhilePending()+ viewRef.value = 2+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>root</div><div>pageC</div>`)+ expect(unmounted).toEqual(['pageA'])+ render(null, root)+ expect(unmounted).toEqual(['pageA', 'pageC'])++ // tearing down right after resolving must unmount it too+ unmounted.length = 0+ deps.length = 0+ viewRef.value = 0+ root = await mountAndSwitchWhilePending()+ render(null, root)+ expect(serializeInner(root)).toBe(``)+ expect(unmounted).toEqual(['pageA'])+ })+ test('KeepAlive + Suspense + comment slot', async () => { const toggle = ref(false) const Async = defineAsyncComponent({packages/runtime-core/src/components/KeepAlive.tsindex 55eaf8624..f11fb9c4f 100644@@ -248,7 +248,25 @@ 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)+ // the inner child may never have been patched if an ancestor+ // Suspense was pending when this update happened+ if (innerChild.component) {+ cache.set(pendingCacheKey!, innerChild)+ } else {+ // the branch that stayed mounted is not tracked by the cache,+ // so it must not be kept alive or it would never be unmounted+ const { activeBranch } = instance.subTree.suspense!+ if (+ activeBranch &&+ activeBranch.component &&+ !Array.from(cache.values()).some(+ cached => cached.component === activeBranch.component,+ )+ ) {+ resetShapeFlag(activeBranch)+ }+ } }, 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))