Skip to content

Realtime Sync for Opened Accounts: per-account EventSource lifecycle scoped to open tabs only #24

Description

@saknarajapakshe

Goal

Keep an account's inbox live-updating only while it has a tab open — not for every authenticated account in the background

Background

Today, each tab opens one EventSource to /api/v1/events while isAuthenticated && inboxName is true. The backend (realtime.Hub, server/internal/realtime/hub.go) keeps one ref-counted IMAP IDLE connection per watched mailbox per session, torn down when the last subscriber disconnects — no backend changes are needed, this is entirely a frontend subscription-lifecycle change.

Scope (revised — significantly smaller than originally spec'd, and now effectively closed)

Because #23's window.open named-target change means each account maps to exactly one tab for its entire life (no in-place switching between already-linked accounts anymore), ref-counting and cross-tab liveness tracking are no longer required for correctness: a tab's own mount/unmount already is that account's "opened"/"closed" signal, and DataContext's existing per-tab EventSource effect (opens while isAuthenticated && inboxName, closes on unmount) already satisfies "only accounts with a tab open stay live" as-is, with no changes needed.

The one remaining in-place transition (#29addAccount reassigning an already-active tab from one account to another) also turned out not to need any new hook API: #29's fix resets inboxName back to "" the instant the active account changes, which already forces the existing realtime effect to close the old account's EventSource and reopen a fresh one (reading the new session's token) once the new account's inbox name resolves. So there is no onAccountOpened/onAccountClosed callback to wire into — the mechanism is automatic.

Acceptance criteria

Files likely touched

None expected beyond what #29 already covers — revisit only if #25's removal/invalidation flow surfaces a gap.

Dependencies

Depends on #22 (switch-flow hook points — resolved without new API, see #29) and #23 (tab-open/close is driven by the switcher's window.open behavior).

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions