AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Client-Side Memory Leak In Pages Router: GetStaticProps Data Retained Indefinitely

Next.js Pages Router retains getStaticProps data for every visited page on the client without any eviction mechanism, causing unbounded memory growth in long-lived sessions.

highConfidence 85%Next.jsTurbopackPages RouterAffected V16.1.7

Origin Analysis

The client-side route loader in Next.js caches the JSON data fetched for each route (from /_next/data requests) in a plain object or map without a size limit or LRU policy. This cache is never cleared during client-side navigation, so all page props remain referenced and cannot be garbage collected.
1. Clone the minimal repro repository or create a Next.js app with Pages Router and multiple pages using getStaticProps.\n2. Run `npm install && npx next build && npx next start`.\n3. Open the app and navigate between pages multiple times.\n4. Monitor JS heap usage via performance.memory or Chrome DevTools; observe steady heap growth after each navigation.\n5. Take a heap snapshot and inspect retained objects; note large amounts of data from previously visited pages.

Fixing Code Block

Edge Case Audit

This fix changes cache behavior and may increase network requests for pages evicted from the cache, impacting performance on low-memory devices or with many unique pages. The hardcoded entry count may not suit all applications; it should ideally be configurable or based on total data size. Concurrency: if multiple navigations occur rapidly, the eviction logic is safe but may evict a route currently being fetched. Rollback: to revert to the previous unlimited cache, remove the MAX_CACHE_ENTRIES check and eviction block. Test thoroughly with dynamic routes and client-side transitions.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state