nextjs - ✅(Solved) Fix Client-side memory leak with pages router: Next.js retains getStaticProps data indefinitely [1 pull requests, 7 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#91484Fetched 2026-04-08 00:46:58
View on GitHub
Comments
7
Participants
4
Timeline
16
Reactions
0
Author
Timeline (top)
subscribed ×7commented ×4mentioned ×2cross-referenced ×1

Fix Action

Fixed

PR fix notes

PR #91581: fix : pages router client data cache leak with LRU eviction

Description (problem / solution / changelog)

What?

  • Evict old Pages Router SSG data on the client.

Why?

  • Prevent unbounded memory growth in long sessions.

How?

  • Use an LRU cache with size/entry limits for sdc.

Fixes #91484

Changed files

  • packages/next/src/shared/lib/router/router.ts (modified, +63/-2)

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:55:08 PST 2026; root:xnu-12377.91.3~2/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 24.13.0
  npm: 9.4.0
  Yarn: 1.22.22
  pnpm: 10.23.0
Relevant Packages:
  next: 16.1.7 // Latest available version is detected (16.1.7).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: N/A
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/iamakulov/nextjs-memory-leak-repro

To Reproduce

  1. npm install && npx next build && npx next start
  2. Open http://localhost:3000. Click “Go to page N” a bunch of times. Observe the JS heap grow, both as reported by performance.memory, and in DevTools
  3. After a few clicks, take the heap snapshot in DevTools. Observe that the majority of the heap is data by Next.js.
<img width="3278" height="2278" alt="Image" src="https://github.com/user-attachments/assets/2c46f81f-61cf-4667-9394-ff8431945fb2" />

The repro is minimal, but the issue is real (caught it on a production Next.js site with many long-lived sessions and semi-large page data).

Current vs. Expected behavior

Expected: Next.js implements an LRU cache for the visited pages. Data promises from pages you navigated away from a while ago get evicted and GC-collected.

Ideally, the eviction is based on the total size of the data and not the number of pages. (E.g.: evict the oldest page when the total stringified size of data reaches 100 MB.)

Actual: Next.js retains all data from all visited pages. The cache size grows indefinitely.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:55:08 PST 2026; root:xnu-12377.91.3~2/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 24.13.0
  npm: 9.4.0
  Yarn: 1.22.22
  pnpm: 10.23.0
Relevant Packages:
  next: 16.1.7 // Latest available version is detected (16.1.7).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: N/A
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Pages Router

Which stage(s) are affected? (Select all that apply)

Other (Deployed)

Additional context

No response

extent analysis

Fix Plan

To address the memory leak issue in Next.js, we can implement a custom LRU cache with a size limit. Here are the steps:

  • Install the lru-cache package: npm install lru-cache
  • Create a custom cache wrapper around Next.js' getStaticProps and getServerSideProps methods
  • Set a maximum cache size (e.g., 100 MB) and implement eviction based on the total size of the data

Example Code

// Import the lru-cache package
import LRU from 'lru-cache';

// Create an LRU cache instance with a maximum size of 100 MB
const cache = new LRU({
  max: 100 *

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING