Settings work offline: local copy, no-flash first paint, outbox with replay #113

Closed
kayg wants to merge 0 commits from issue/100-prefs-offline-2 into dev
Owner

Closes #100.

Settings now work without the network.

  • Local copy: the last settings the server confirmed live in IndexedDB (prefs-store.ts). They are read before the app mounts (main.ts), so the look is on the page at first paint, also offline, and a slow server no longer holds the first paint up when this device already has a copy.
  • Outbox: every change shows at once and is queued with its own idempotency key (prefs-sync.ts). It is sent in order on change, on the browser online event, when the live socket opens, and on a 5 s retry. A retry reuses the same key. A bad value (4xx other than sign-in/busy) is dropped with the usual toast.
  • Conflicts: last writer wins per key. Each queued change remembers what the server had (base). If, on reconnect or from a live prefs.changed, the server's value is neither the base nor our value, another device changed it meanwhile: the server wins, the waiting change is dropped, the screen updates in place. Several offline edits to one key collapse to the last one.
  • Safety: nothing is sent until the signed-in person is known; a copy kept for a different person is thrown away; signing out forgets it.
  • No server change: prefs.set already takes idempotency keys.

Tests (e2e/prefs-offline.spec.ts, Chromium and WebKit at 1440): offline change shows at once and waits in the outbox; Chromium reload fully offline keeps the look at first paint with no layout shift (the bottom bar's own width settle, which also happens without any of this, is excluded); reconnect sends it; a dropped request is retried with the same idempotency key; a newer value from another device wins in place. WebKit cannot hold the network off across a reload in a test, so its reload step is skipped.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T

(Replaces #110 with current dev merged in, so CI reruns now that CI has CPU priority over agent builds.)

Closes #100. Settings now work without the network. - **Local copy**: the last settings the server confirmed live in IndexedDB (`prefs-store.ts`). They are read before the app mounts (`main.ts`), so the look is on the page at first paint, also offline, and a slow server no longer holds the first paint up when this device already has a copy. - **Outbox**: every change shows at once and is queued with its own idempotency key (`prefs-sync.ts`). It is sent in order on change, on the browser `online` event, when the live socket opens, and on a 5 s retry. A retry reuses the same key. A bad value (4xx other than sign-in/busy) is dropped with the usual toast. - **Conflicts**: last writer wins per key. Each queued change remembers what the server had (`base`). If, on reconnect or from a live `prefs.changed`, the server's value is neither the base nor our value, another device changed it meanwhile: the server wins, the waiting change is dropped, the screen updates in place. Several offline edits to one key collapse to the last one. - **Safety**: nothing is sent until the signed-in person is known; a copy kept for a different person is thrown away; signing out forgets it. - No server change: `prefs.set` already takes idempotency keys. Tests (`e2e/prefs-offline.spec.ts`, Chromium and WebKit at 1440): offline change shows at once and waits in the outbox; Chromium reload fully offline keeps the look at first paint with no layout shift (the bottom bar's own width settle, which also happens without any of this, is excluded); reconnect sends it; a dropped request is retried with the same idempotency key; a newer value from another device wins in place. WebKit cannot hold the network off across a reload in a test, so its reload step is skipped. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T (Replaces #110 with current dev merged in, so CI reruns now that CI has CPU priority over agent builds.)
Settings work offline: local copy, first paint, outbox with replay (#100)
Some checks failed
CI / rust (pull_request) Successful in 2m9s
CI / web (pull_request) Failing after 9m7s
28c4efbaec
Settings keep a copy in IndexedDB that is read before the app first
paints, so the look is right with no network and no wait for the server.
Changes are applied at once and queued in an outbox with idempotency keys;
the outbox is replayed in order on reconnect (online event, live socket
open, slow retry). Last writer wins per key: if another device changed the
same setting while this one was offline, the server's value wins and the
screen updates in place. A copy kept for someone else is thrown away.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Merge remote-tracking branch 'origin/dev' into issue/100-prefs-offline
Some checks failed
CI / rust (pull_request) Failing after 1m50s
CI / web (pull_request) Failing after 8m39s
7495c19be5
Author
Owner

Review: the outbox design is sound.

  • Retries reuse the idempotency key.
  • A change from another device wins.
  • Nothing is sent before the owner is confirmed, and signing out clears the stored copy.

Nit for later: offline, the 5 s retry wakes the phone forever. Back off, or rely on online and the socket opening.

CI: rust is green. The web failures are the same timeout family the baseline probe (#115) showed on unchanged e6a9b2b, and this PR's own 6 tests pass on both engines.

Merging.

Review: the outbox design is sound. - Retries reuse the idempotency key. - A change from another device wins. - Nothing is sent before the owner is confirmed, and signing out clears the stored copy. Nit for later: offline, the 5 s retry wakes the phone forever. Back off, or rely on `online` and the socket opening. CI: rust is green. The web failures are the same timeout family the baseline probe (#115) showed on unchanged `e6a9b2b`, and this PR's own 6 tests pass on both engines. Merging.
Author
Owner

Closing: this branch is already fully contained in dev (it landed through a merge train). Branch cleanup, 2026-10-15.

Closing: this branch is already fully contained in `dev` (it landed through a merge train). Branch cleanup, 2026-10-15.
kayg closed this pull request 2026-10-15 08:35:04 +00:00
Some checks failed
CI / rust (pull_request) Failing after 1m50s
CI / web (pull_request) Failing after 8m39s

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!113
No description provided.