Skip to content

Page on_unload lifecycle hook #6233

Closed as not planned
Closed as not planned

Description

@masenf

Summary

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.

Part of the Reflex Framework Roadmap — Section 1m.

Activity

  1. linear commented on Mar 25, 2026

    @linear
  2. masenf commented on Mar 25, 2026

    @masenf
    CollaboratorAuthor

    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.

    Recommending closure as not planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAnything you want improved

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions