zerobyte/app/client
Nico d5da6d4562
fix: sse connection (#623)
### TL;DR

Refactored `useServerEvents` hook to use a shared EventSource connection across all components instead of creating individual connections per hook instance.

### What changed?

- Introduced shared state management for EventSource connections with reference counting
- Added comprehensive test coverage with MockEventSource implementation
- Modified the hook to share a single EventSource connection across multiple consumers
- Implemented proper cleanup when the last subscriber unmounts
- Removed automatic query refetching on backup completion, keeping only cache invalidation

### How to test?

Run the new test suite with `bun test use-server-events.test.tsx` to verify:
- Single EventSource instance is shared across multiple hook consumers
- Event listeners work correctly with the shared connection
- Cache invalidation occurs once per event
- Proper cleanup happens when all subscribers unmount

### Why make this change?

This optimization reduces resource usage by preventing multiple EventSource connections when the hook is used in different components. The shared connection approach is more efficient while maintaining the same functionality, and the added tests ensure reliability of the server events system.
2026-03-05 22:32:44 +01:00
..
api-client fix: run repo stats in background (#620) 2026-03-05 20:18:34 +01:00
components chore: web-haptics 2026-03-04 18:48:47 +01:00
functions chore: improve ssr data loading 2026-03-04 18:48:47 +01:00
hooks fix: sse connection (#623) 2026-03-05 22:32:44 +01:00
lib refactor(sso): extract sso code into it's own module (#617) 2026-03-04 18:48:47 +01:00
modules refactor: correctly delete orphan sessions after idp deletion 2026-03-05 21:02:56 +01:00