Skip to content

[Frontend] useStreamEvents tears down and recreates the EventSource on every render - SSE reconnect storm/leak #850

Description

@grantfox-oss

Telegram (ask questions / claim the issue here first): https://t.me/+DOylgFv1jyJlNzM0

Why this matters

frontend/src/hooks/useStreamEvents.ts:47-64 - buildUrl's useCallback depends on streamIds, whose default streamIds = [] is a fresh array each render, and every call site passes an inline array. New identity -> buildUrl -> connect change -> the mount effect with deps [connect] closes and reopens the EventSource on every render. Each received event calls setEvents, re-rendering the consumer, so the stream reconnects on every event - a self-sustaining reconnect loop and resource leak.

Acceptance criteria

  • Memoize subscription identity (derive a stable string key from streamIds/subscribeToAll/jwtToken) so connect/buildUrl only change when the subscription changes
  • EventSource is created once per distinct subscription, not per render or per received event
  • Clear any pending reconnect timer before scheduling a new one and cap reconnect attempts
  • Add a regression test asserting only one EventSource instance is created across multiple re-renders and incoming events

Files to touch

  • frontend/src/hooks/useStreamEvents.ts
  • frontend/src/components/NotificationDropdown.tsx
  • frontend/src/components/dashboard/dashboard-view.tsx
  • frontend/src/app/streams/[id]/page.tsx

Out of scope

  • Backend SSE controller changes

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workingfrontendFrontend related tasks

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions