Skip to content

fix(station-boards): push last snapshot on subscribe when one exists - #482

Merged
ciotlosm merged 1 commit into
mainfrom
fix/station-boards-late-subscribe-catchup
Aug 7, 2026
Merged

fix(station-boards): push last snapshot on subscribe when one exists#482
ciotlosm merged 1 commit into
mainfrom
fix/station-boards-late-subscribe-catchup

Conversation

@ciotlosm

@ciotlosm ciotlosm commented Aug 7, 2026

Copy link
Copy Markdown
Member

Symptom

Switching between views (e.g. station view -> home, or any pair of views that use createStationBoardsController) showed scheduled-only vehicles for up to one poll cycle (15 s today) before live GPS buses reappeared, even when data was already flowing on the previous view.

Root cause

subscribeStationBoards in src/lib/workers/gtfs/stationSubscribers.ts explicitly skipped the late-subscribe catch-up. PR #454 removed it on 2026-07-22 to fix an incoming-first flicker in StationCard groups on cold start, but the regression is that the new view's subscriber now waits for the next tickLive to receive its first push.

PR #454 was correct for the first-ever subscription (before the first tickLive has run, getReconciledSnapshot() returns null, and pushing the empty scheduled-only board does cause flicker). It was wrong for every subsequent subscription, where a non-null snapshot already exists and is what the stream is currently broadcasting.

Fix

In subscribeStationBoards, push the last good snapshot on subscribe but only when getReconciledSnapshot() is non-null. The cold-start path is unchanged (the null check skips the push), so the PR #454 flicker fix is preserved. Every subsequent subscription paints within a microtask with the same merged-with-GPS data the stream is currently showing.

const snap = getReconciledSnapshot();
if (snap) void pushOne(sub, snap);

The new view now reads the most recent merged snapshot the moment its controller mounts. The next tickLive (within livePollMs = 15 s) replaces it with a fresher one.

Verification

  • 386 tests pass (npx vitest run)
  • svelte-check 0 errors
  • Diff is 16 insertions / 6 deletions in one file (focused; no whole-file reformat)

Related

PR #454 (fix: eliminate incoming-first flicker in StationCard groups) is the fix this restores the missing half of. The two together are the complete solution: no flicker on cold start, no 15 s wait on view switch.

Symptom: switching views (station -> home, or any other view that
uses createStationBoardsController) showed scheduled-only vehicles
for up to one poll cycle (15 s today) before live GPS buses
reappeared, even when data was already flowing on the previous view.

Root cause: subscribeStationBoards explicitly skipped the
late-subscribe catch-up that the previous implementation had
(`void pushOne(sub, getReconciledSnapshot())`). PR #454 removed
it in 2026-07 to fix an incoming-first flicker in StationCard
groups on cold start.

That reasoning was correct for the FIRST-EVER subscription
(before tickLive has run, getReconciledSnapshot returns null, and
pushing scheduled-only vehicles does cause a flicker). It was
wrong for every subsequent subscription, where the snapshot
exists, has merged GPS data, and is what the stream is currently
broadcasting.

Fix: push the last good snapshot on subscribe, but only when
getReconciledSnapshot() returns non-null. The cold-start path
(snapshot === null) is unchanged, so the PR #454 flicker fix
is preserved.

The new view now paints the same merged-with-GPS data the
previous view was showing, within a microtask of subscribing.
The next tickLive (within livePollMs) replaces it with a
fresher snapshot.
@ciotlosm
ciotlosm merged commit af80402 into main Aug 7, 2026
3 checks passed
@ciotlosm
ciotlosm deleted the fix/station-boards-late-subscribe-catchup branch August 7, 2026 15:47
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.

2 participants