SPA auto-update on new build, preserving player + queue state (#196) - #265
Merged
Conversation
Lightweight version signal for SPA auto-update polling. Unlike
/api/health (1s Navidrome ping budget per call), this endpoint is cheap
enough to poll per open tab. buildId is a short SHA-256 of the on-disk
${PUBLIC_DIR}/index.html behind an mtime+size cache, so any rebuild
dropped on disk is detected without an APP_VERSION bump and without a
hub restart. Sentinels: 'dev' (no staticDir), 'unknown' (unreadable).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UkCqNJ2T4qMyBYStie6hhS
…loses #196) UpdateNotifier polls /api/version (60s + window focus) and treats any buildId different from the boot-time baseline as an update. Auto-reload fires when it can't interrupt anything: playback paused, or sink is Sonos (the device keeps playing — the tab is just a remote), and no text input focused. While playing locally it defers behind a subtle 'Update available' banner with a manual Reload button, retrying every 5s so the reload lands when playback pauses or ends. Player state (queue, index, position, shuffle/repeat, isPlaying, sink) is snapshotted to sessionStorage before reload and restored at boot within a 30s freshness window. The sink restore is a documented scoped exception to the store's never-persist rule; a restored Sonos sink seeds PlayerBar's skip-play ref so the mount-time track-change effect doesn't re-issue SetAVTransportURI at the still-playing device. Local resume goes through the existing audio.play() path — an autoplay-policy rejection lands the player paused at the right position. Reload-loop guard: sessionStorage remembers the buildId already reloaded for; a persistent mismatch (cached index.html) degrades to the manual banner instead of reload-looping the tab. 'dev'/'unknown' buildIds never trigger anything. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UkCqNJ2T4qMyBYStie6hhS
…#196) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UkCqNJ2T4qMyBYStie6hhS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #196.
What
The SPA now detects a new deployed build and reloads itself without losing the play queue — and without ever interrupting audio the user can hear.
Hub:
GET /api/version{ appVersion, buildId }— no Navidrome ping (unlike/api/health, whose 1s timeout budget makes it unsuitable for per-tab polling).buildId= short SHA-256 of the on-disk${PUBLIC_DIR}/index.html(mtime+size cached, ~one stat per request). Vite content-hashes every chunk name into index.html, so any rebuild changes the id — no APP_VERSION bump, no hub restart (owner requirement: most changes don't increment the version)."dev"(no staticDir — Vite HMR owns dev updates),"unknown"(index.html unreadable, e.g. mid-deploy). Neither ever triggers a reload.SPA:
UpdateNotifier(mounted in AppLayout, post-login only)State preservation across the reload
lib/player-snapshot.ts: queue/index/position/shuffle/repeat/isPlaying/sink → sessionStorage, restored at boot if < 30s old (volume already persists via localStorage).SetAVTransportURIat the still-playing device.audio.play()path; an autoplay-policy rejection lands the player paused at the correct position.sinkrestore is a documented, freshness-bounded exception to the player store's never-persist rule.Skipped the
configVersionidea from the issue thread —/api/capabilitiesis already re-polled via react-query, so admin toggles propagate without a reload.Testing
hub/test/version-route.test.ts(7): buildId hashing, mtime-cache invalidation on rewrite, dev/unknown sentinels, endpoint shape.frontend/src/lib/player-snapshot.test.ts(7): round-trip, freshness expiry, corrupt/malformed payloads, one-shot Sonos flag, unknown-sink fallback.frontend/src/components/UpdateNotifier.test.tsx(7): stable = silent, auto-reload when paused / when casting, defer + manual reload while playing locally, deferred reload fires on pause, loop guard, dev/unknown ignored.pnpm verifygreen (826 hub + 166 frontend),pnpm lintzero output.🤖 Generated with Claude Code
https://claude.ai/code/session_01UkCqNJ2T4qMyBYStie6hhS