You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: effect cleanup cannot distinguish hidden Activity from unmount #38403
OverlayScrollbarsComponent initializes in an effect and destroys osInstance() in its cleanup.
The current behavior
Activity hiding currently runs the effect cleanup for the subtree. Cleanup cannot distinguish temporary hiding from a true unmount, so libraries that destroy external instances in effect cleanup destroy stateful resources even though the Activity DOM and component state are preserved.
When the Activity becomes visible again, React reruns the effect and creates a new external instance. The previous scroll position and other instance state are lost.
The expected behavior
React should provide a supported way to distinguish temporary hiding of an Activity subtree from a real unmount, or otherwise provide a lifecycle mechanism that lets integrations preserve state and external resources during hiding.
Libraries should be able to keep or suspend external resources while hidden and perform final destruction only when the component is truly unmounted.
If React intentionally does not expose this distinction, guidance for the recommended cleanup and restoration pattern would be helpful.
Feasibility note from looking into this: the behavior is intentional. <Activity mode="hidden"> unmounts effects (runs cleanup) while preserving state and DOM, so that hidden trees behave like unmounted ones for side effects. Exposing a way to tell hide from unmount would be a new public API or lifecycle (and would partly undermine that model), so it's a React-team design decision, not something an external PR can settle.
In the meantime, the supported pattern is to make the effect setup/cleanup symmetric and idempotent: keep the external instance (and its state, such as scroll position) in a ref or in the library's own store, have cleanup only suspend or detach, and have setup restore it. Final destruction can be deferred, e.g. by scheduling it and cancelling it if the effect re-runs, or by tying it to the owning component's real lifetime through a stable cleanup. The guidance in the Activity docs about effects in hidden trees is also the place to document this if the team wants it. Not planning a PR here, to avoid a competing API proposal.
Activity
sleitor commentedon Nov 29, 2026
Feasibility note from looking into this: the behavior is intentional.
<Activity mode="hidden">unmounts effects (runs cleanup) while preserving state and DOM, so that hidden trees behave like unmounted ones for side effects. Exposing a way to tell hide from unmount would be a new public API or lifecycle (and would partly undermine that model), so it's a React-team design decision, not something an external PR can settle.In the meantime, the supported pattern is to make the effect setup/cleanup symmetric and idempotent: keep the external instance (and its state, such as scroll position) in a ref or in the library's own store, have cleanup only suspend or detach, and have setup restore it. Final destruction can be deferred, e.g. by scheduling it and cancelling it if the effect re-runs, or by tying it to the owning component's real lifetime through a stable cleanup. The guidance in the Activity docs about effects in hidden trees is also the place to document this if the team wants it. Not planning a PR here, to avoid a competing API proposal.