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

Dev Server Memory Leak Via Unbounded Source Map And Fake Function Caches

Next.js dev server retains ~90 MB per edit of a Server Component due to unbounded growth of Node's generatedSourceMapCache and React's fakeFunctionCache. Inline data URL source maps and line/column-dependent keys cause permanent cache entries, leading to OOM crashes.

highConfidence 85%Next.jsAffected V16.4.0-Canary.14Affected V16.4.0-Canary.15

Origin Analysis

Next.js starts dev with --enable-source-maps, causing Node to parse and cache inline source maps embedded in eval'd HMR modules. React's flight client also caches fake function scripts keyed by line/column, which change with every edit. Both caches grow monotonically and are never cleared, resulting in unbounded memory consumption.
1. Clone the repro repo. 2. Run pnpm install. 3. Run NODE_OPTIONS="--max-old-space-size=3072" pnpm dev. 4. Open http://localhost:3000/ once. 5. Insert a line near the top of app/page.tsx, save, wait, reload. 6. Repeat and observe RSS of next-server process increasing indefinitely.

Fixing Code Block

Edge Case Audit

Disabling source maps degrades stack trace quality during development, making debugging more difficult. The LRU cache may cause slight CPU overhead on cache misses and could evict entries that are still needed, but this does not affect correctness. The patch modifies node_modules directly, so it must be reapplied after every package installation or update. Rollback: reinstall the affected packages (pnpm install --force) to restore original files. Test thoroughly with your real application before relying on this hotfix.

Ecosystem Topology