Skip to content

[ENG-36794] feat: add real-time server-sent events infrastructure#3349

Open
gdsantana wants to merge 4 commits intodevfrom
ENG-36794
Open

[ENG-36794] feat: add real-time server-sent events infrastructure#3349
gdsantana wants to merge 4 commits intodevfrom
ENG-36794

Conversation

@gdsantana
Copy link
Contributor

Feature

Description

Adds a complete Server-Sent Events (SSE) infrastructure for handling real-time updates and activity notifications.

Components added:

  • SSEClient (src/services/v2/base/sse/sse-client.js): Wrapper with automatic reconnection and event parsing
  • SSEService (src/services/v2/base/sse/sse-service.js): Singleton managing global state, cross-tab coordination, and cache invalidation
  • useSSE composable (src/composables/useSSE.js): Vue composable for easy component integration
  • Session integration (src/services/v2/base/auth/sessionManager.js): Starts/stops SSE based on auth state
  • Unit tests (src/tests/services/v2/base/sse/sse-client.test.js): Comprehensive test coverage for the client
  • Vite proxy config (vite.config.js): Proxy configuration for /events/stream endpoint

How to test

  1. Start the dev server: yarn dev
  2. Login to the application
  3. Open browser DevTools → Network tab
  4. Filter for "EventStream" type requests
  5. Verify that a connection to /events/stream is established
  6. Test reconnection by temporarily disconnecting network
  7. Verify SSE automatically reconnects when network returns
  8. Run tests: yarn test:unit:headless --run src/tests/services/v2/base/sse/sse-client.test.js

Technical Details

  • Automatic reconnection: Exponential backoff with configurable max delay
  • Cross-tab coordination: Uses BroadcastChannel for multi-tab sync
  • Cache invalidation: Triggers Vue Query cache updates on relevant events
  • Session lifecycle: SSE starts on login, stops on logout

Adds a complete Server-Sent Events (SSE) infrastructure for handling real-time updates and activity notifications.

Includes:
- SSEClient wrapper with automatic reconnection and event parsing
- Singleton SSEService managing global state, cross-tab coordination, and cache invalidation
- Vue composable useSSE for easy component integration
- Session lifecycle integration to start/stop SSE based on auth state
- Comprehensive unit tests for the client
- Proxy configuration for the /events/stream endpoint
HerbertJulio and others added 3 commits March 5, 2026 16:04
Remove duplicated BroadcastManager/TabCoordinator instances by
merging SSEService into CacheSyncService. Extract CacheInvalidator
for SRP. Fix proxy rewrite, duplicate listener, and sort bugs.
- only start SSE for client accounts (account.kind === 'client')
- wire afterLogin into accountGuard to trigger SSE after session load
- close existing EventSource before creating new connection
- add 60s inactivity watchdog to detect silent connection deaths
- add console.log for cache invalidation debugging
Remove client-side inactivity timeout mechanism from SSE client and
implement reconnection logic in cache-sync-service when server closes
the connection. This provides more reliable handling of server-initiated
disconnects by responding to explicit close events rather than relying
on inactivity detection.

- Add scheduleReconnect and clearClosedReconnectTimeout methods
- Remove inactivityTimeout option and related methods from SSE client
- Add tests for ping and closed event handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

2 participants