Skip to content

UI: one EventSource module with one retry policy - #159

Merged
RikusVanRensburg merged 1 commit into
mainfrom
refactor/RVR/ui-live-module
Nov 12, 2026
Merged

RikusVanRensburg merged 1 commit into
mainfrom
refactor/RVR/ui-live-module

Conversation

@RikusVanRensburg

Copy link
Copy Markdown
Contributor

Closes #146

What changed and why

  • hub/ is now live/. LiveProvider owns the one EventSource and applies every push itself. live/push-table.ts is the single eventName -> apply table and also gives the names to listen for. Removed: Dispatcher, useHubEvent, PushSource, HubPushes, FakeHub, the duplicated event-name list.
  • One retry policy (0, 2, 5, 10, then 30 s) that now also covers a first connect that failed. Before, it went down and waited for the Retry button. down now means "away through every step"; it keeps retrying and Retry only skips the wait.
  • Everything is refetched only when a stream opens after a failure, not on the first open. Start-up makes one /api/auth/state request instead of two.
  • A push that is not JSON, or that its cache entry cannot take, is logged (console.error) and the keys it belongs to are invalidated.
  • Cancel and set are synchronous (cancelQueries reverts the query synchronously, read from query-core 5.105.1), so two pushes for one key land in order.
  • Tests drive a fake EventSource (test/fake-event-source.ts, installed in vitest.setup.ts); the hub the harness returned is now live. New test/live.test.tsx covers first-connect retry, down, no refetch on first open, one listener per event, back-to-back pushes and the two malformed cases.
  • Decision recorded in docs/decisions.md: no SSE id: and Last-Event-ID replay. A reconnect refetch is a few small GETs on a LAN and replay would still need the refetch for a gap.

Testing

  • Native: pnpm --filter koppel.ui typecheck, pnpm --filter koppel.ui lint: clean.
  • node:24.22.2-bookworm-slim, pnpm 9.15.0: pnpm --filter koppel.ui test: 6 files, 84 tests passed.
  • Not run: the react-ui tests (not touched), Rust tests (no Rust change), the contract tests, a manual run against a real server.
  • Bundle (built to a scratch folder): JS 522,640 to 522,219 bytes (gzip 154,105 to 154,039).

Docs

docs/ui.md, CLAUDE.md and docs/decisions.md updated.

Changelog notes: no wire, on-disk or settings change. User-visible: fewer requests at start-up, and the UI recovers by itself after a first connect that failed.

🤖 Generated with Claude Code

LiveProvider owns the EventSource and applies every push through one
table of event names. A first connect that fails now retries on the same
steps as any other, the first open no longer refetches everything, and a
push that cannot be applied is logged and its data fetched. The cancel
and the set of a push are synchronous. hub/ becomes live/ and the tests
drive a fake EventSource instead of FakeHub.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The UI's live layer is one EventSource module, with one retry policy

1 participant