Fix sync status and PWA recovery after inactivity #5

Merged
exler merged 4 commits from fix/pwa-sync-reconnect into main 2026-10-23 14:28:36 +02:00
Collaborator

Summary

  • Replace the hardcoded Synced indicator with actual connection/catch-up states on desktop and mobile (EN/PL).
  • Reconnect on foreground return, online and bfcache restore, including clean WebSocket closes; catch up missed shopping/planner/recipe updates without a page reload.
  • Never serve cached HTMX partials as fresh; reject expired-session HTMX requests and stop promising offline changes will be queued.

Root cause

The indicator was static. The vendored WS extension retries only selected close codes, lifecycle recovery was missing, and reconnecting did not replay missed broadcasts.

Verification

  • Real Chromium + real Django/HTMX + loopback TCP fault proxy: 15/15 browser regressions pass (parent rerun).
  • Covers silently stale sockets, missed updates, 1001 closes, offline state, failed catch-up, snapshot/broadcast races, drafts, expired sessions and service-worker fallback.
  • Django tests: 15/15 pass locally and inside the built Docker image. Browser tests: 15/15 pass after the Node 22 discovery fix.
  • Compiled .mo files removed from Git and excluded from Docker context; Docker installs gettext, runs Django compilemessages, then removes the compiler in the same layer. Verified generated Polish catalog in the built image and msgfmt absent. CI compiles before testing; README documents local compilation.
  • Forgejo PR CI passed on final head ef6da27 (Test / test, run 23). Initial run exposed Node 22 directory discovery incompatibility; fixed npm test to select *.test.mjs explicitly.

Limits

  • No heartbeat: a silently dead socket while the page remains continuously visible is recovered on a lifecycle event or a failed request, not proactively.
  • An already-open inline shopping edit can be replaced by a board update, as with existing broadcasts.
  • Desktop Chromium simulates lifecycle/network conditions; not an on-device iOS/Android suspension test.
  • No production deployment.

Visual verification

Captured in desktop Chromium against the real local application with synthetic fixture data, not production data. The mobile captures use a 360px-wide mobile emulator; they are not evidence from a physical device or an installed PWA. Network/lifecycle states are simulated.

Desktop live/connected state — Polish fixture

Desktop live/connected state — Polish fixture

Mobile reconnecting state — Polish fixture

Mobile reconnecting state — Polish fixture

Mobile offline state — Polish fixture

Mobile offline state — Polish fixture

## Summary - Replace the hardcoded Synced indicator with actual connection/catch-up states on desktop and mobile (EN/PL). - Reconnect on foreground return, online and bfcache restore, including clean WebSocket closes; catch up missed shopping/planner/recipe updates without a page reload. - Never serve cached HTMX partials as fresh; reject expired-session HTMX requests and stop promising offline changes will be queued. ## Root cause The indicator was static. The vendored WS extension retries only selected close codes, lifecycle recovery was missing, and reconnecting did not replay missed broadcasts. ## Verification - Real Chromium + real Django/HTMX + loopback TCP fault proxy: 15/15 browser regressions pass (parent rerun). - Covers silently stale sockets, missed updates, 1001 closes, offline state, failed catch-up, snapshot/broadcast races, drafts, expired sessions and service-worker fallback. - Django tests: 15/15 pass locally and inside the built Docker image. Browser tests: 15/15 pass after the Node 22 discovery fix. - Compiled .mo files removed from Git and excluded from Docker context; Docker installs gettext, runs Django compilemessages, then removes the compiler in the same layer. Verified generated Polish catalog in the built image and msgfmt absent. CI compiles before testing; README documents local compilation. - Forgejo PR CI passed on final head ef6da27 (Test / test, run 23). Initial run exposed Node 22 directory discovery incompatibility; fixed npm test to select *.test.mjs explicitly. ## Limits - No heartbeat: a silently dead socket while the page remains continuously visible is recovered on a lifecycle event or a failed request, not proactively. - An already-open inline shopping edit can be replaced by a board update, as with existing broadcasts. - Desktop Chromium simulates lifecycle/network conditions; not an on-device iOS/Android suspension test. - No production deployment. ## Visual verification Captured in desktop Chromium against the real local application with synthetic fixture data, not production data. The mobile captures use a 360px-wide mobile emulator; they are not evidence from a physical device or an installed PWA. Network/lifecycle states are simulated. ### Desktop live/connected state — Polish fixture ![Desktop live/connected state — Polish fixture](https://git.marut.network/attachments/2b025ed7-4695-43d2-998f-07b26c75bd20) ### Mobile reconnecting state — Polish fixture ![Mobile reconnecting state — Polish fixture](https://git.marut.network/attachments/f090bbc0-5d8e-4cab-b1c5-7cae54b318eb) ### Mobile offline state — Polish fixture ![Mobile offline state — Polish fixture](https://git.marut.network/attachments/81b7cfac-44fb-4e83-834c-4840f9c6aa20)
Make live sync status honest and recover after reconnect/resume
Some checks failed
Test / test (pull_request) Failing after 1m3s
292e92baaa
The sync indicator was hardcoded to "Synced"/"Live sync on", the ws
extension never reconnects after a clean server close (e.g. 1001 on
restart), nothing replaced a silently dead socket after the PWA resumed,
and broadcasts sent while a client was away were lost for good.

- Status starts as "connecting" and is driven by socket + catch-up state
  (connecting / live / reconnecting / offline / signed out), on desktop
  and mobile, translated EN/PL.
- After every (re)connect the client fetches GET /sync/ for the regions
  on its page and only then shows live; a broadcast during the fetch
  triggers another catch-up.
- Reconnect on visibilitychange, pageshow (bfcache), online and failed
  requests; reconnect ourselves on close codes the extension ignores;
  retire superseded sockets so retries can't stack.
- HTMX requests without a session get 401 + HX-Redirect instead of a
  followed login redirect that HTMX treated as success.
- Service worker never answers HTMX requests from cache.
- Offline toast no longer claims the change will apply later.
- Browser tests (Playwright against the real app behind a TCP proxy) via
  npm test, plus a PR test workflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The new sync-status strings were in django.po but not in the tracked
django.mo, and the Docker build doesn't compile messages, so a deploy
would have shown them untranslated. CI compiled the catalog before
testing, which hid that; drop the step so tests use what ships.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop the tracked django.mo and ignore *.mo. The Docker image now runs
compilemessages with gettext installed and purged in the same layer,
and CI compiles before tests again using the same Django command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep generated catalogs out of build context and fix Node 22 test discovery
All checks were successful
Test / test (pull_request) Successful in 1m29s
ef6da27b50
exler merged commit 112f2b7162 into main 2026-10-23 14:28:36 +02:00
exler deleted branch fix/pwa-sync-reconnect 2026-10-23 14:28:36 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
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
exler/hearth!5
No description provided.