PWA: a new version reaches a reloaded tab (#132) #163

Closed
kayg wants to merge 0 commits from issue/132-pwa-update-reload into dev
Owner

Closes #132.

A waiting service worker used to take over only when no tab of the old version was left, which a Safari reload never reaches. Now, keeping "never swap code under someone typing":

  • Startup, before mount (main.ts -> applyWaitingAtStartup): a waiting version is activated and the page reloads once. Loop guard: at most one automatic reload per 20 s (sessionStorage), and the takeover message is re-sent a few times if the browser is slow to hand over.
  • Nobody can be typing: signed out (sign-in/setup), or no note open and nothing unsaved, applies at once.
  • Note open: the quiet "Update ready" offer stays; it also applies when the app returns to the front (visibilitychange) with nothing unsaved.
  • The editor reports open/unsaved through watchNote() (same NoteSession.status that drives "Saved"; anything but saved counts as unsaved).

Tests: apps/web/e2e/pwa-update.spec.ts (Chromium, on the app as production serves it; a deploy is faked by rewriting dist-served/sw.js): reload after a deploy shows the new version; coming back to the front applies it; an open note with unsaved typing is never swapped (socket held back so typing stays unsaved), then applies once saved; signed out applies at once. Existing pwa.spec passes.

Note: the machine was at load ~100 during testing, so timeouts in the new spec are generous.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T

Closes #132. A waiting service worker used to take over only when no tab of the old version was left, which a Safari reload never reaches. Now, keeping "never swap code under someone typing": - **Startup, before mount** (`main.ts` -> `applyWaitingAtStartup`): a waiting version is activated and the page reloads once. Loop guard: at most one automatic reload per 20 s (sessionStorage), and the takeover message is re-sent a few times if the browser is slow to hand over. - **Nobody can be typing:** signed out (sign-in/setup), or no note open and nothing unsaved, applies at once. - **Note open:** the quiet "Update ready" offer stays; it also applies when the app returns to the front (`visibilitychange`) with nothing unsaved. - The editor reports open/unsaved through `watchNote()` (same `NoteSession.status` that drives "Saved"; anything but `saved` counts as unsaved). Tests: `apps/web/e2e/pwa-update.spec.ts` (Chromium, on the app as production serves it; a deploy is faked by rewriting `dist-served/sw.js`): reload after a deploy shows the new version; coming back to the front applies it; an open note with unsaved typing is never swapped (socket held back so typing stays unsaved), then applies once saved; signed out applies at once. Existing pwa.spec passes. Note: the machine was at load ~100 during testing, so timeouts in the new spec are generous. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
PWA: a new version reaches a reloaded tab (#132)
Some checks failed
CI / rust (pull_request) Failing after 28s
CI / web (pull_request) Failing after 7m59s
672a162fd4
A waiting version now takes over at startup, when signed out or no note is
open, and when the app returns to the front with nothing unsaved. An open
note with unsaved typing is never swapped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Author
Owner

Review: I read the diff.

  • When a new version applies: at startup, before anything shows. When nobody is typing: signed out, or no note open and nothing unsaved. When the app comes back to the front with nothing unsaved.
  • Guards: a 20 s reload guard prevents loops, and an open note with unsaved typing is never swapped.

Its 4 Chromium tests pass, and after merging dev svelte-check reports 0 errors. WebKit and the real iPhone are unverified; kayg checks on the phone.

Merging as #164.

Review: I read the diff. - **When a new version applies:** at startup, before anything shows. When nobody is typing: signed out, or no note open and nothing unsaved. When the app comes back to the front with nothing unsaved. - **Guards:** a 20 s reload guard prevents loops, and an open note with unsaved typing is never swapped. Its 4 Chromium tests pass, and after merging dev `svelte-check` reports 0 errors. WebKit and the real iPhone are unverified; kayg checks on the phone. Merging as #164.
kayg closed this pull request 2026-10-14 06:50:31 +00:00
Some checks failed
CI / rust (pull_request) Failing after 28s
CI / web (pull_request) Failing after 7m59s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!163
No description provided.