yceffort
◆ SERIES · 2 POSTS

Page Preservation in Next.js

How Next.js with cacheComponents hides and restores pages: Activity lifecycle conflicts, measured retention across route segments, and deciding which state to keep and which work to stop.

README

This blog enables cacheComponents in Next.js. When navigating to another page, some previous screens remain hidden inside React Activity. Keeping them allows their state to be restored, but it can also conflict with a library's lifecycle assumptions or retain the DOM of several screens at once.

Part 1 follows a three.js canvas that went blank on the about page. Source analysis and reproduction connect the point at which Next.js hides the screen, React cleans up its Effects, and react-three-fiber disposes of its WebGL context.

Part 2 explains why repeated navigation retained three posts in one case and nine in another, then considers what to change to manage memory. It separates work that should stop when hidden from state worth restoring, and examines DOM size, retained data, and caches outside the page. Measured results are kept distinct from proposed improvements whose memory savings have not yet been measured.

02 ITEMS

All posts

in order
01

Pages You Leave Don't Die, They Hide: Next.js cacheComponents and React Activity

#nextjs#react#debugging
Next.js 16's cacheComponents hides the pages you leave with React Activity instead of unmounting them. Following a three.js canvas that went blank after a back navigation, I read the router, React, and react-three-fiber source and reproduced it in a browser.
34 min · read
02

Why Did Next.js's Last Three Leave Nine Posts Behind?

#nextjs#memory#web-performance
Next.js is said to preserve the last three pages, yet nine posts remained on this blog. A sequential navigation experiment measures how far preservation reaches, then looks at managing memory by separating work to stop when hidden from state worth keeping.
16 min · read