React 19.2's <Activity>: 6 Silent Keep-Alive Traps and Their Fixes
Multi-tab keep-alive is a core requirement for admin dashboards, and React 19.2 finally makes it native. But these six silent failures cause state loss, broken reloads, and invisible overlays that block clicks unless you apply the documented fixes.
React 19.2 finally brings a built-in keep-alive mechanism: <Activity> keeps a subtree's DOM and state alive when hidden, with effects cleaned up and re-run on visibility toggles. That capability unlocks multi-tab UIs without third-party libraries, but only if the tab outlet completely replaces <Outlet /> and page components stop reading route hooks. A production implementation passes search and params as props, injects navigation callbacks, and persists view state to the URL so refreshes don't lose anything.
Three traps come from effect and cache semantics. Dependency arrays trigger on re-show, so a ref comparison is required to avoid resetting user data. A global staleTime of 30 seconds makes a reload button a no-op unless the cache is invalidated on remount. And URL-driven overlays portaled to <body> float above hidden tabs, blocking clicks; mounting them into the tab's root container fixes that. Two more traps involve global DOM queries and the non-instantaneous uniqueness of data-visible attributes during switching.
A final trap requires replacing the router outlet entirely: mixing <Outlet /> with <Activity> unmounts the current page on switch. The full solution, including E2E tests, lives in the open-source fastapi-react-admin project. A checklist at the end summarizes every rule, making it easy to apply to your own multi-tab admin.
The silent nature of these failures is the most dangerous: dependency arrays and query caches assume a component's lifecycle matches its visibility, so they misbehave without errors.
The effect re-run on visibility toggles is a fundamental semantic change; developers must now think of effects as per-visible-cycle, not per-mount.
Display:none is not DOM removal; libraries that query the document globally will still hit hidden nodes, so scoping selectors is a mandatory part of keep-alive.
The 18ms and 300ms windows of dual data-visible values show that keep-alive changes DOM visibility asynchronously, which breaks strict E2E selectors unless routed by tab ID.
The point that it's visibility that decides, not unmounting, hits the root. This is how keep-alive should be thought of. After stepping through all six traps one by one and writing it out, this article is worth it.