React 19.2: Hidden Subtree State Preservation

Drawers/tabs resetting your inputs? Most of the time it’s because we unmount them on close. That’s why text fields clear, toggles jump back, and even scroll position resets. React 19.2 adds <Activity />: you can switch a subtree to hidden without losing its state. And while it’s hidden, React cleans up Effects and runs hidden updates at a lower priority — less background work, less UI jank. The image shows the exact change. #React #JavaScript #TypeScript #WebDevelopment #Frontend #SoftwareEngineering #WebPerformance #DeveloperExperience #ReactDevelopment #Programming

  • graphical user interface, text

Real-world use cases: - filter drawers (draft inputs shouldn't reset) - settings tabs (textareas/toggles should stay) - multi-step flows (step state shouldn't die between sections) Small gotcha: `hidden` cleans up Effects. So "fetch on mount" inside the drawer won't run while it's hidden. If you need prefetching, move the fetch up a level and rely on caching (React Query / SWR).

Docs: https://react.dev/reference/react/Activity Release notes: https://react.dev/blog/2025/01/16/react-v19-2 The migration guide helped me avoid a few pitfalls when switching from conditional mounting. Worth reading if you're refactoring existing drawers/modals.

Or, try a framework that doesn't require any extra engineering just to render your state! Have a look at Inglorious Web: https://npmjs.com/package/@inglorious/web

Sometimes it’s nice to lose state. Sometimes it’s not 🤷

See more comments

To view or add a comment, sign in

Explore content categories