Skip to content

fix(pages-router): add bounded eviction to client-side data cache (sdc/sbc)#95355

Draft
sleitor wants to merge 1 commit into
vercel:canaryfrom
sleitor:fix-91484
Draft

fix(pages-router): add bounded eviction to client-side data cache (sdc/sbc)#95355
sleitor wants to merge 1 commit into
vercel:canaryfrom
sleitor:fix-91484

Conversation

@sleitor

@sleitor sleitor commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

The sdc/sbc (Server Data Cache / Server Background Cache) objects in the Pages Router grew without bound: every route visited added a Promise to the plain-object cache and nothing ever removed them, causing a memory leak that grows with the number of unique pages visited in a long-lived session (reported in #91484 by @iamakulov).

What

Wraps the cache initializer in a Proxy-based factory (createDataCache) that enforces a maximum of 50 cache entries using a FIFO eviction policy. When the 51st unique key is written, the oldest entry is deleted before the new one is stored. All existing call sites that read, write, or delete cache keys via bracket notation continue to work without modification.

The constant SDC_MAX_ENTRIES (50 routes) matches common LRU sizes used in other parts of the codebase and is conservative enough to avoid observable regressions while still bounding memory use for production sessions.

Why

Previously there was no eviction at all — the cache was a plain object with no size limit. This is a low-risk, zero-call-site-change fix.

Fixes #91484

…c/sbc)

The sdc/sbc (Server Data Cache / Server Background Cache) objects in the
Pages Router grew without bound: every route visited added a Promise to
the plain-object cache and nothing ever removed them, causing a memory
leak that grows with the number of unique pages visited in a long-lived
session (issue vercel#91484, reported by iamakulov).

This change wraps the cache initializer in a Proxy-based factory
(createDataCache) that enforces a maximum of 50 cache entries using a
FIFO eviction policy.  When the 51st unique key is written, the oldest
entry is deleted before the new one is stored.  All existing call sites
that read, write, or delete cache keys via bracket notation continue to
work without modification.

The constant SDC_MAX_ENTRIES (50 routes) matches common LRU sizes used
in other parts of the codebase and is conservative enough to avoid any
observable regressions while still bounding memory use to a reasonable
level for production sessions.

Fixes vercel#91484
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client-side memory leak with pages router: Next.js retains getStaticProps data indefinitely

1 participant