[docs] CalmRefresh: Analysis, review, and G0.10 closed

This commit is contained in:
2026-11-02 01:18:10 +01:00
parent a5480d2877
commit ff3a996482
6 changed files with 111 additions and 4 deletions
+62
View File
@@ -0,0 +1,62 @@
# A calm refresh — when a new version of the garden is waiting
Status: built on `feature/calm-refresh`. Gap G0.10; CLAUDE.md §8, *the stale service worker: a
precached shell keeps serving old JS to a player who has "updated". Detect a waiting worker and offer
an explicit, calm refresh control.* Needed before the Phase 1 gate, where the author plays the
installed app daily while fixes are deployed. Review:
[`feature-calm-refresh.md`](../reviews/feature-calm-refresh.md).
## 1. Why and what, in the player's terms
The garden works offline because a service worker keeps a copy of it. When a new version is
published, the browser fetches it in the background and **waits**: the garden the player has open
never changes under their hands. When the new one is ready, one quiet line appears at the foot of
the page: **"A new version of the garden is ready."** with a **Refresh** button. The player
refreshes when they like; nothing is lost either way, since the rose lives in the device's
database, not in the code.
## 2. Technical architecture
```mermaid
sequenceDiagram
participant P as the open garden (version A)
participant B as the browser
participant S as the server
B->>S: sw.js (on a navigation or a check)
S-->>B: version B's bytes differ
B->>B: install B, precache; B waits (skipWaiting: false)
B-->>P: "waiting" (workbox-window, via virtual:pwa-register)
P->>P: show "A new version of the garden is ready." + Refresh
P->>B: Refresh: SKIP_WAITING to B
B-->>P: B controls; the page reloads under B
```
| # | Decision | Why |
|:--|:--|:--|
| U1 | Register through `virtual:pwa-register` in the app; `injectRegister: false`. | The emitted `registerSW.js` registers but tells the page nothing; the virtual module reports the waiting worker. Bundled, so the CSP needs no inline script. |
| U2 | **Never refresh by itself.** The line waits for the player. | CLAUDE.md §1, *gentle*; a reload in the middle of pouring water would lose the pour. |
| U3 | The line sits in its own `aside` at the foot, on the garden and the Letter alike. | It is about the whole app, not one page; a landmark keeps it findable. |
| U4 | The e2e test serves a **real second version** (version A's build with `sw.js` changed) from the same origin. | A waiting worker exists only between two builds; a mock would test the mock. |
## 3. Risk analysis
| Risk | Answer |
|:--|:--|
| A player keeps old code forever and never sees a fix. | The line appears as soon as a new worker waits; tested end to end. |
| A silent swap mid-action loses care. | U2; the test asserts the old worker still controls the page until Refresh. |
| Feeling pushed. | One line, no badge, no repeat, no count; nothing happens if it is ignored. |
| Privacy | Nothing new leaves the device: update checks were already made by the browser to the same origin. |
## 4. Gaps
| Gap | State |
|:--|:--|
| G0.10 | Built |
| What changed in a version (release notes) | Open: not needed for the Phase 1 gate |
## 5. Verification matrix
| Case | Kind | Where |
|:--|:--|:--|
| No line without a waiting version; the line and Refresh when there is one; Refresh calls the app; on the Letter too | unit | `ui/test/Shell.test.ts` |
| Built app: version A controls; version B published; the line appears; A still controls; Refresh; B controls and the line is gone; axe | e2e | `e2e/update.spec.ts` |