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
Add an on_unload lifecycle hook for page unload events — the inverse of on_connect (1j).
Details
Fires when a user navigates away from a page or closes the tab, enabling cleanup logic and resource release. This completes the connection lifecycle: on_connect for setup, on_unload for teardown.
Closing this as not planned — the semantics of on_unload are too vague to implement well.
Key questions that don't have clear answers:
HTTP REST context: When should on_unload fire? When the state expires? When the request completes?
WebSocket context: Is "unload" when the client disconnects? When the tab is closed?
General ambiguity: The concept of "unload" doesn't map cleanly to Reflex's state lifecycle.
An alternative like on_expire (firing when the state is evicted from the backing store) was considered, but that also has problems — for Redis-backed state, we don't know the state expired until after it's already gone, so there's no opportunity to run a handler.
Activity
linear commentedon Mar 25, 2026
ENG-9172
masenf commentedon Mar 25, 2026
Closing this as not planned — the semantics of
on_unloadare too vague to implement well.Key questions that don't have clear answers:
on_unloadfire? When the state expires? When the request completes?An alternative like
on_expire(firing when the state is evicted from the backing store) was considered, but that also has problems — for Redis-backed state, we don't know the state expired until after it's already gone, so there's no opportunity to run a handler.Recommending closure as not planned.