Backtestsvuerun-20261001-022054#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 A = our agent, Patch B = the merged fix.
Both patches add the guard the issue suggests: inside the post-render effect, only cache the inner child when `innerChild.component` is non-null. That stops the poisoned cache entry that caused the null `suspenseId` and `bum` crashes, and both tests reproduce the reported A→B (pending) → resolve → A → B sequence.
Patch A also handles a consequence the issue does not mention. KeepAlive's render calls `keys.add(key)` before the post-render effect runs. When the guard skips the cache write, the key for B stays in `keys` with no matching `cache` entry. With `max` set, a later prune can pick that orphan key as the oldest. `pruneCacheEntry` then finds `cached` undefined and takes the `else if (current) resetShapeFlag(current)` branch. That clears the keep-alive flags on the currently rendered vnode (A), so A is really unmounted on the next switch instead of being deactivated. This hits the issue's real-world setup, `<NuxtPage :keepalive="{ max: 5 }" />`.
Patch A deletes the key when no cache entry exists for it, and its second test covers this case with `max: 2`. It checks `unmountedA` / `mountedA` counts, which would fail under Patch B's guard alone. Patch B fixes the reported crash but leaves this cache-eviction bug in place.
Both patches are small and match the surrounding code. Patch A's tests are more thorough. A 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
5m 8s11 turns
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
179vs 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..7e26c518e 100644@@ -2111,6 +2111,174 @@ describe('Suspense', () => { expect(serializeInner(root)).toBe(`<div>async2</div>`) }) + test('KeepAlive + nested Suspense switch while ancestor Suspense is pending', async () => {+ let resolveRootDep!: () => void+ const RootDep = {+ async setup() {+ await new Promise<void>(r => (resolveRootDep = r))+ return () => h('div', 'root')+ },+ }+ const PageA = {+ name: 'PageA',+ render: () => h('div', 'A'),+ }+ const PageB = {+ name: 'PageB',+ render: () => h('div', 'B'),+ }+ const pages: Record<string, any> = { A: PageA, B: PageB }+ const page = ref('A')++ const App = {+ render() {+ return h(Suspense, null, {+ default: () =>+ h('div', [+ h(RootDep),+ h(KeepAlive, null, {+ default: () =>+ h(Suspense, null, {+ default: () => h(pages[page.value], { key: page.value }),+ }),+ }),+ ]),+ fallback: h('div', 'loading'),+ })+ },+ }++ const root = nodeOps.createElement('div')+ render(h(App), root)+ expect(serializeInner(root)).toBe(`<div>loading</div>`)++ // switch A -> B while the root Suspense (ancestor) is still pending+ page.value = 'B'+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>loading</div>`)++ // resolve the root dependency+ resolveRootDep()+ await new Promise(r => setTimeout(r))+ await nextTick()+ // the inner switch made while the ancestor was pending is not applied+ expect(serializeInner(root)).toBe(`<div><div>root</div><div>A</div></div>`)++ // switch back to A+ page.value = 'A'+ await nextTick()+ expect(serializeInner(root)).toBe(`<div><div>root</div><div>A</div></div>`)++ // switch to B again: the cached B vnode must not be a never-mounted one+ page.value = 'B'+ await nextTick()+ expect(serializeInner(root)).toBe(`<div><div>root</div><div>B</div></div>`)+ })++ test('KeepAlive (max) + nested Suspense switch while ancestor Suspense is pending', async () => {+ let resolveRootDep!: () => void+ const RootDep = {+ async setup() {+ await new Promise<void>(r => (resolveRootDep = r))+ return () => h('div', 'root')+ },+ }+ const mountedA = vi.fn()+ const unmountedA = vi.fn()+ const mountedC = vi.fn()+ const unmountedC = vi.fn()+ const PageA = {+ name: 'PageA',+ setup() {+ onMounted(mountedA)+ onUnmounted(unmountedA)+ return () => h('div', 'A')+ },+ }+ const PageB = {+ name: 'PageB',+ render: () => h('div', 'B'),+ }+ const PageC = {+ name: 'PageC',+ setup() {+ onMounted(mountedC)+ onUnmounted(unmountedC)+ return () => h('div', 'C')+ },+ }+ const pages: Record<string, any> = { A: PageA, B: PageB, C: PageC }+ const page = ref('A')++ const App = {+ render() {+ return h(Suspense, null, {+ default: () =>+ h('div', [+ h(RootDep),+ h(+ KeepAlive,+ { max: 2 },+ {+ default: () =>+ h(Suspense, null, {+ default: () => h(pages[page.value], { key: page.value }),+ }),+ },+ ),+ ]),+ fallback: h('div', 'loading'),+ })+ },+ }++ const root = nodeOps.createElement('div')+ render(h(App), root)+ expect(serializeInner(root)).toBe(`<div>loading</div>`)++ // switch A -> B while the root Suspense (ancestor) is still pending.+ // B is never mounted, so KeepAlive must not keep a key for it+ page.value = 'B'+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>loading</div>`)++ // resolve the root dependency+ resolveRootDep()+ await new Promise(r => setTimeout(r))+ await nextTick()+ // the inner switch made while the ancestor was pending is not applied+ expect(serializeInner(root)).toBe(`<div><div>root</div><div>A</div></div>`)+ expect(mountedA).toHaveBeenCalledTimes(1)++ page.value = 'A'+ await nextTick()+ expect(serializeInner(root)).toBe(`<div><div>root</div><div>A</div></div>`)++ // with max 2, adding C must not prune A (or C itself) because of an+ // orphan key left for B+ page.value = 'C'+ await nextTick()+ expect(serializeInner(root)).toBe(`<div><div>root</div><div>C</div></div>`)+ expect(mountedC).toHaveBeenCalledTimes(1)+ expect(unmountedA).not.toHaveBeenCalled()++ // switch back to A: the cached instance is reused+ page.value = 'A'+ await nextTick()+ expect(serializeInner(root)).toBe(`<div><div>root</div><div>A</div></div>`)+ expect(mountedA).toHaveBeenCalledTimes(1)+ expect(unmountedA).not.toHaveBeenCalled()+ expect(unmountedC).not.toHaveBeenCalled()++ // and C is still cached as well+ page.value = 'C'+ await nextTick()+ expect(serializeInner(root)).toBe(`<div><div>root</div><div>C</div></div>`)+ expect(mountedC).toHaveBeenCalledTimes(1)+ expect(unmountedC).not.toHaveBeenCalled()+ expect(unmountedA).not.toHaveBeenCalled()+ })+ test('KeepAlive + Suspense + comment slot', async () => { const toggle = ref(false) const Async = defineAsyncComponent({packages/runtime-core/src/components/KeepAlive.tsindex 55eaf8624..58725c7c4 100644@@ -248,7 +248,16 @@ 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)+ // skip vnodes that were not mounted, e.g. because an ancestor+ // Suspense is still pending+ if (innerChild.component) {+ cache.set(pendingCacheKey!, innerChild)+ } else if (!cache.has(pendingCacheKey!)) {+ // drop the key added during render so a later prune does not+ // act on a key without a cache 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))
What the agent reported
I fixed the bug. KeepAlive no longer caches a page that never mounted, so the switch sequence from the report runs without errors. All 44 runtime-core test files pass (1070 tests). The changes are uncommitted in the working tree.
What was wrong: your trace is correct. While the outer <Suspense> is still pending, SuspenseImpl.process skips patching the inner <Suspense>, so the new page vnode never gets a component. KeepAlive's cacheSubtree cached it anyway. The next switch to that key reused the empty cache entry, which caused the suspenseId error in patchSuspense and the unmountComponent(null) crash.
What I changed (packages/runtime-core/src/components/KeepAlive.ts, cacheSubtree, Suspense branch):
- Your suggested guard: the inner child is cached only if
innerChild.componentis set. - One extra step you didn't suggest: if caching is skipped and that key has no older valid entry, the key is also removed from
keys. The render function adds the key before caching runs. Left in place, it can make a latermaxprune remove the wrong page: withmax: 2, the left-over key made page A count as the oldest, so switching to page C wrongly unmounted A, as the second test shows.
Tests (both in packages/runtime-core/__tests__/components/Suspense.spec.ts):
KeepAlive + nested Suspense switch while ancestor Suspense is pending: follows the report: switch A→B while the outer boundary is pending, let it resolve, then A, then B. It checks the exact rendered output at every step. Before the fix it failed on the final switch withTypeError: Cannot read properties of null (reading 'suspenseId')inpatchSuspense; now it passes.KeepAlive (max) + nested Suspense switch while ancestor Suspense is pending: the same scenario withmax: 2and a third page, C. It checks that pages A and C are each mounted once and never unmounted. With the key-removal step taken out it fails (A gets unmounted); with it, it passes.- Gate:
./bt-test packages/runtime-core/__tests__gives 44 files and 1070 tests passed. Prettier is clean on both changed files.
Requirements:
- Inner page follows switches, no errors: done; the first test checks the rendered output after every switch.
- Both errors (
suspenseId, null instance inunmountComponent) gone: done; the first test reproduced thesuspenseIderror before the fix and passes after it. The second error happens in the teardown that follows the first one. - Suggested fix (don't cache a vnode that never mounted): done as suggested, plus the key removal above.
- Without
<KeepAlive>it works: no change needed, since the fix only touches KeepAlive's caching. - Same defect class as #10912 / #11479: those guards are unchanged and their existing tests still pass.
Still open: right after the outer boundary resolves, the screen shows A even though B was selected while it was pending. The switch made during the pending window is lost, because the inner <Suspense> skipped that patch. The first test records this exact current output, and the next switch works normally. Fixing it would mean changing that skip in Suspense.ts, which I left out to keep the change minimal.
The reviewer also flagged two existing weak spots that this change doesn't make worse, and I left them alone:
- The queued cache step reads
pendingCacheKeywhen it runs rather than when it was queued. - KeepAlive's record of the current page can still point at the never-mounted B after the outer boundary resolves.