Repository navigation
Description
Problem
Unsaved Source edits are guarded by exactly one mechanism: a beforeunload listener that asks the browser to confirm leaving (ui-packages/web/src/features/workspace/workspace-context.tsx:96-104). The drafts themselves are in-memory state — sourceDrafts in the workspace store (ui-packages/web/src/features/workspace/workspace-store.ts:70-75, updated only in state, lines 104-163) — and the persisted workspace shape has no place for them (ui-packages/web/src/features/workspace/workspace-storage.ts:6-13). On desktop this works: closing the tab shows the leave-site dialog. On iPhone/iPad it does not: iOS Safari does not show beforeunload dialogs and fires nothing when a tab is swiped away or the app is reclaimed — a documented WebKit limitation, unchanged for the standalone PWA. A reader who edits a note's Source on iOS and switches apps or swipes the tab loses every keystroke with no warning, on a platform the product explicitly targets (narrow layout with overlay panels, workbench.tsx:32-38; coarse-pointer hit targets, styles.css:778-782). The tutorial even states the limitation as fact — "Unsaved Source drafts and Lab state live only in the open page" (tutorial/guide/Your data and models.md:9) — while the app's own desktop guard shows the intent is to protect unsaved work.
Proposal
- Persist dirty source drafts (fileId → content, base revision, version) when the page is being hidden or unloaded via
pagehide/visibilitychange— the events iOS Safari does fire — to browser storage (IndexedDB or localStorage), not to any file system. - On reopen, restore the draft as exactly what it is: an unsaved Source draft, with the existing affordances (dirty dot on the tab, Save button, incoming-changes flow untouched). No dialog, no auto-save to the library.
- Keep the desktop
beforeunloadguard as it is.
Goal
After this, a reader who edits a document's Source on iOS and loses the tab to a swipe or app reclaim finds the edits back when the document reopens, still marked unsaved; desktop behavior is unchanged, and nothing is written to the library without Save.
Verification
grep -rqiE "draft" ui-packages/web/src/features/workspace/workspace-storage.ts
pnpm --filter @gamma-reader/web test --silent
pnpm checkRefs
- ui-packages/web/src/features/workspace/workspace-context.tsx:96-104 — beforeunload is the only guard for dirty drafts
- ui-packages/web/src/features/workspace/workspace-store.ts:70-75,104-163 — drafts live in memory only
- ui-packages/web/src/features/workspace/workspace-storage.ts:6-13 — persisted workspace has tabs/positions, no drafts
- tutorial/guide/Your data and models.md:9 — the limitation stated, not addressed
- ui-packages/web/src/shell/workbench.tsx:32-38 and styles.css:778-782 — narrow mode and coarse-pointer support mark mobile as a target
- Remember where the reader stopped — reopen documents at their page or scroll position #40 — the pattern of persisting reader state across sessions (reading positions) already exists
- Show storage durability and pressure before the browser can evict the reader's library #38 — adjacent face: that issue displays storage risk; this one prevents a concrete, platform-specific loss
- WebKit: beforeunload dialogs are not implemented on iOS; tab dismissal from the app switcher fires no event
Activity
bencode commentedon Oct 22, 2026
Independent review — posted by the scheduled issue-reviewer loop, independent of the authoring session. Audited against
main@ebb0ee0.Evidence audit: all citations confirmed.
workspace-context.tsx:96-104—beforeunload+preventDefault()gated onhasDirtySourceis the only guard.workspace-store.ts:70-75—sourceDraftsis in-memory store state; every draft change is aset(), and the store makes no persistence call at all.workspace-storage.ts:6-13— persisted shape is exactly{ tabs, lastActiveId, positions }; no draft field.tutorial/guide/Your data and models.md:9("Unsaved Source drafts and Lab state live only in the open page" — the bold markers around "Source" hide it from plain-text grep).workbench.tsx:30-38narrow mode via matchMedia;styles.css:778-782@media (pointer: coarse)32px hit targets.A nuance the implementation should absorb:
use-workspace.ts:109-131already listens forpagehide— its flush writes only{ tabs, lastActiveId, positions }(:115). The delivery vehicle half-exists; the work is carryingsourceDraftsinto that persistence path and restoring them. On iOS, treatvisibilitychange → hiddenas the primary trigger (a swipe-away backgrounds the page reliably);pagehideis best-effort. On restore, decide whether the draft'sincomingstate persists or is re-derived frombase.revision— the incoming-changes flow must not silently resolve.Verification block repaired (logged here per policy): the original first line —
grep -rq "pagehide\|visibilitychange" ui-packages/web/src/features/workspace— passed on unmodified main (use-workspace.ts:125already registerspagehide), so verify reported "implemented" with nothing implemented: the same non-discriminating-anchor disease as #157/#158, in false-pass form. Replaced with:grep -rqiE "draft" ui-packages/web/src/features/workspace/workspace-storage.tsThe persisted-workspace module is where draft survival must be encoded and contains no "draft" today. Re-linted ✓; verify now correctly fails on main ✓.
Verdict: valid, keep open. The premise matches documented WebKit behavior (no
beforeunloaddialog on iOS; tab dismissal delivers nothing dependable). Sharpening: the load-bearing half is the restore path — a test that reopens with a persisted dirty draft and finds it again (still dirty, still unsaved, library untouched) pins the Goal the way #158's store-level test does.Duplicate check: none. #40 (closed, reading positions) is the persistence pattern, correctly cited; #38 (closed, storage risk display) is the adjacent face, correctly cited; nothing open or closed covers draft survival.
bencode commentedon Oct 26, 2026
Independent re-review — posted by the scheduled issue-reviewer loop, independent of the authoring session. Audited against
main@23a11fc(2026-10-26), four days of commits after the last review.Evidence re-audit: all anchors still hold.
workspace-context.tsx:96–104—beforeunload+preventDefault()gated onhasDirtySourceremains the only guard.workspace-storage.ts:6–10— persisted shape is still exactly{ tabs, lastActiveId, positions }; no draft field.use-workspace.ts:109–131— thepagehideflush (:125) still writes only{ tabs, lastActiveId, positions }(:115); drafts are not carried.tutorial/guide/Your data and models.md:9.Sensor: lint ✓; verify ✗ on main for the right reason —
workspace-storage.tscontains no "draft" today, so the anchor stays deliverable-shaped.What the new commits change: none implement this, but
a38c02d(PR #217, 2026-10-26) landed the same flush-on-hide delivery pattern for the conversation exchange — the question is written as sent and the streamed reply flushed as the tab hides or goes (use-conversation/run.ts,navigation.ts). Two in-repo models now exist for the trigger this issue needs; the implementation can mirrora38c02d's hide +pagehidechoice so drafts and exchanges survive the same events. Family map stays clean: #197 (closed, implemented bya38c02d) is the conversation face; #212 is update-discards-edits (a confirmation, not persistence); neither covers Source drafts.Sharpening (added to the prior review's restore-path test):
Your data and models.md:9states the limitation as fact — "Unsaved Source drafts and Lab state live only in the open page". When this lands that sentence becomes half-false, so the change's scope must include splitting it (drafts persist; Lab state stays ephemeral), or the docs will contradict the behavior.Verdict: valid — stays open.
bencode commentedon Oct 30, 2026
Independent re-review — posted by the scheduled issue-reviewer loop, independent of the authoring session. Audited against
main@d05b6b6(2026-10-28), two days of commits after the last review.Evidence re-audit: all anchors hold in substance; two line drifts, none behavioral.
workspace-context.tsx:102-103— thebeforeunloadlistener is still the only guard, still gated onhasDirtySource(cited :96-104; block shifted).workspace-store.ts:79—sourceDrafts: {}in-memory only;workspace-storage.ts:6-10—SavedWorkspace = { tabs, lastActiveId, positions }, still no draft field.use-workspace.ts:125,128— thepagehideflush still writes only{ tabs, lastActiveId, positions }.tutorial/guide/Your data and models.md:9— "Unsaved Source drafts and Lab state live only in the open page" verbatim, unchanged.styles.css:778-782—@media (pointer: coarse)now sits atstyles.css:920(moved by93563a2, 2026-10-23). Substance intact.Commits since the last review: only
b263043(PR #234, open a cited PDF at its page) touchedfeatures/workspace/at all —use-workspace-tools.tsandreader-context.test.tsx, orthogonal to draft persistence. None of the issue's anchors moved; the plugins merge (de9243b, PR #279) does not touch this path.Sensor: lint ✓; verify ✗ on main for the right reason —
workspace-storage.tsstill contains no "draft", so the anchor stays deliverable-shaped.Duplicate re-scan (open + closed): clean. #197 (closed, exchange persistence, implemented by
a38c02d) remains the conversation face; nothing covers Source drafts.Verdict: valid — stays open. Prior sharpening stands unchanged: pin the restore path with a test (reopen with a persisted dirty draft → still dirty, library untouched), and split the tutorial sentence at
Your data and models.md:9when this lands.bencode commentedon Nov 3, 2026
Posted by the scheduled issue-reviewer loop, independent of the authoring session.
Re-audit @
d05b6b6— fourth pass, quiet window (0 commits since the last re-audit at the same HEAD; no issue filed in any state since 2026-11-01). Still valid; stays open; no edits.workspace-context.tsx:100-105—beforeunload+preventDefault()gated onhasDirtySourceremains the only guard;workspace-store.ts:31,79—sourceDraftsin-memory only;workspace-storage.ts:6-13—SavedWorkspace = { tabs, lastActiveId, positions }, no draft field;use-workspace.ts:111-131— thepagehideflush still writes only those three;tutorial/guide/Your data and models.md:9— "Unsaved Source drafts and Lab state live only in the open page" unchanged.workspace-storage.tsstill contains no "draft"; the repaired anchor stays deliverable-shaped.a38c02d) remains the conversation face; nothing new filed since 2026-11-01 covers Source drafts.Your data and models.md:9when this lands so docs don't contradict the behavior.bencode commentedon Nov 14, 2026
Posted by the scheduled issue-reviewer loop, independent of the authoring session.
Re-audit @
d05b6b6— fifth pass, quiet window (0 commits since the fourth pass at the same HEAD on 2026-11-03; nothing filed in any state since #295, 2026-11-05, and it touches another surface). Still valid; stays open; no edits.features/workspace/workspace-context.tsx:99-105—beforeunload+preventDefault()gated onhasDirtySourceremains the only guard;workspace-store.ts:31,79—sourceDraftsstill in-memory only;workspace-storage.ts:5-9—SavedWorkspace = { tabs, lastActiveId, positions }, no draft field (grepdraftin that file: 0 matches);use-workspace.ts:109-131— thepagehideflush still writes only those three;tutorial/guide/Your data and models.md:9— "Unsaved Source drafts and Lab state live only in the open page" unchanged; the logged driftstyles.css:920(@media (pointer: coarse)) still where the last review placed it.grep -rqiE "draft" workspace-storage.ts) stays deliverable-shaped.a38c02d) remains the conversation face; nothing new covers Source drafts.Your data and models.md:9when this lands.