<Activity mode={isOpen ? 'visible' : 'hidden'}> is an alternative to {isOpen && <Sidebar />}. Stable since React 19.2, it has two modes:
hidden: React keeps the subtree's fibers, so state is preserved, and keeps the DOM nodes, so typed text, scroll position and a<video>'s timecode survive. It hides the top-level DOM nodes withdisplay: none(React 19.3.1 sets it as!importantinline) and cleans up the children's effects, layout effects included, as if they had unmounted. Hidden children still re-render when their props change, but at a lower priority, after the visible content has committed.visible(the default): the nodes are shown again, with their previous state, and the effects are re-created.
Compare the alternatives:
- Conditional rendering unmounts: state and DOM are gone and come back from scratch.
- CSS-only hiding (
hidden,display: noneon a wrapper) keeps everything mounted, including effects, so subscriptions, timers and connections keep running in invisible UI, and every update renders it at full priority.
Activity sits between them: preserved like CSS hiding, quiet like unmounting.
Pre-rendering. A boundary that's hidden on its first render still renders its children, after the visible content and without running their effects. That lets a likely-next tab load its code and Suspense-based data in advance; data fetched in an effect isn't, since the effect doesn't run.
Because hidden DOM isn't destroyed, its side effects can continue. A hidden <video> keeps playing; pause it in an effect cleanup, preferably useLayoutEffect since the cleanup is tied to the UI being hidden. Effects with proper cleanup, the same ones that survive Strict Mode, already work under Activity.