Skip to content

Render Chopin in a browser that refuses its storage - #993

Merged
lavaman131 merged 6 commits into
mainfrom
storage-unavailable
Nov 22, 2026
Merged

lavaman131 merged 6 commits into
mainfrom
storage-unavailable

Conversation

@lavaman131

@lavaman131 lavaman131 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Chopin never rendered in a browser that refuses site storage. With "Block all cookies" or site data blocked, Chrome and Edge throw a SecurityError from the localStorage and sessionStorage getters themselves. The document page read storage in several places without a guard and ended on "Couldn't open this document". The theme script in index.html already coped.

What changed

  • One guard. safeLocalStorage and safeSessionStorage (@chopin/editor/browser-storage) guard every read and write on its own, the getter included, and never throw. A write the browser refuses is kept in memory for the rest of the page, so a choice, a pane width, a draft or a message still sending holds until a reload. setItem answers whether the browser actually kept the value.
  • Every use routed through it. That covers the sidebar width and fold, the workspace Chat choice, pane and thread widths, the document view, the skeleton's Chat shape, recovery context, the demo persona, Chat drafts, the outbox, the composer's Aa, the emoji picker's picks and skin tone, recent documents, decision-card selections, the repository cache, the Machines pages and preload recovery. Try/catch blocks that only guarded storage are gone; the ones around JSON.parse stay.
  • Preload recovery still can't loop. A reload for a deploy's missing chunk is made only when setItem says the browser kept its timestamp. A test with a refused store holds this.
  • lib0 patch. lib0 (pulled in by Yjs) calls localStorage.getItem unguarded when environment.js loads; its storage.js guards only the getter. A browser whose storage throws on reads (a damaged profile) therefore stopped the editor chunk from loading. 0.2.120 is the newest 0.2 release, and Yjs needs ^0.2.99, so patches/lib0@0.2.120.patch wraps that one read, applied through patchedDependencies the same way the mdxeditor patch is. With working storage nothing changes. Nothing was opened upstream.
  • CI check. scripts/check-storage.ts runs in bun run ci. It refuses localStorage or sessionStorage named in code or a string anywhere in apps/web and the packages, except the guard and index.html's theme script; tests are exempt and comments don't count. Bun silently skips a patch once the installed version moves (I checked: exit 0, guard gone), so the same check also fails while the installed lib0 isn't the patched version or lacks the guard.
  • Nothing is said to the person. A refused store is not a notice; DESIGN.md records the decision and AGENTS.md lists the guard, the check and the patch.
  • Bookkeeping.
    • The initial JavaScript budget rises to 261,130 B raw and 83,850 B gzip. The image build measures 260,727 B raw and 83,654 B gzip, and the budget sits about 400 B raw and 200 B gzip above that, as the earlier entries in bundle-budget.ts do. A local build outside the container measures 82,823 B gzip.
    • Three reviewed design-contract hashes are renewed: workspace.tsx, navigation-shell.tsx and experiments/machine-setup.tsx. Their motion and presence class producers are unchanged; only their storage calls moved.
    • e2e/shard-timings.json gains the new spec.

Design decisions and the references followed

  • Every storage access is guarded on its own, the getter included, following Excalidraw's excalidraw-app/data/localStorage.ts try/catch pattern, but without its console.error.
  • A refused write is kept in memory for the page instead of dropped, as VS Code for the web falls back to InMemoryIndexedDBStorageDatabase when its browser storage can't be opened.
  • A store that can't keep a write counts as unavailable where that matters (the reload guard), following the storageAvailable check MDN documents in "Using the Web Storage API".
  • No notice is shown, because VS Code for the web only logs that fallback and never notifies the user, and DESIGN.md keeps helper text for when people need to act or recover.
  • The outbox works in memory with no warning that a reload will lose an unsent message, the same as the existing draft behaviour and the offline bar's "Your changes are kept".

Evidence

  • The new e2e spec e2e/storage-unavailable.e2e.ts covers three modes: getters throwing SecurityError, setItem throwing QuotaExceededError, and every Storage call throwing. In each it signs in, folds and shows the sidebar, toggles Aa, sends a Chat message, opens AI accounts, chooses Dark in the account menu's Theme, goes back to the document and reloads. It asserts no page error, no console error (except unrelated image loads) and no words about storage.
    • On origin/main, the two modes the spec had then (getters throwing, every call throwing) both failed with "Couldn't open this document".
    • With the change, 3 passed.
    • With the lib0 patch reversed, the every-call mode fails again.
  • Unit tests for the guard cover both storages under each refusal: getter throws, storage is null, every call throws, and quota exceeded. They also cover working storage, a refused removal and a refused overwrite.
  • The CI check has its own test, and the CI check itself fails on the unconverted tree.
  • bun test apps/web packages scripts: 3817 passed, 3 skipped, 0 failed.
  • bun run ci and bun run types pass.
  • Related e2e specs with working storage: 178 passed, 2 skipped. The skips are the two microVM-only machine-pairing cases, skipped on hosts that can't run microVMs. The specs were theme, auth-lifecycle, chat-threads, conversation-plan-layout, decisions-empty, demo-collaborators, hosted, machines, pane-drag-skip, research-child-motion and research-child-surface, responsive-activity and responsive-workspace, setup-agents, workspace-skeleton, composer-format, documents-sheet, pane-resize, connection-navigation, message-reactions, composer-send-stop and chat-composer. The design behaviour suite's emoji.e2e.ts also passed (12 tests).
  • Docker: in the production-dependencies stage, the installed lib0 carries the patch, and a local docker build --target build passes the bundle budget.

…for the page

safeLocalStorage and safeSessionStorage (@chopin/editor/browser-storage)
guard every read and write on its own, the getter included: Chrome and
Edge with site data blocked throw a SecurityError from localStorage and
sessionStorage themselves, Firefox with storage off has none, a damaged
profile throws from every call and a full store from a write. Nothing
here throws. A write the browser refuses is kept in memory for the rest
of the page, as VS Code for the web keeps its state when the browser's
storage can't be opened, and setItem answers whether the browser kept it.

Co-authored-by: Alex Lavaee <lavaman131@github.com>
… refuses it still renders

With site data blocked the document page said "Couldn't open this
document": recovery context, the sidebar's width and fold, the workspace's
Chat choice, pane widths, the document's view, the skeleton's Chat shape,
the demo persona, drafts, the outbox, Aa, the emoji picker, recent
documents, the decision cards' selections and the Machines pages each read
localStorage or sessionStorage, several without a guard. Each now goes
through safeLocalStorage or safeSessionStorage, and the try/catch blocks
that only guarded storage go with them; those around JSON.parse stay.
What the browser refuses holds for the page, and nothing tells the person.

A reload for a deploy's missing chunk is still made only when the browser
keeps the time of it (setItem answers false otherwise), so a page held in
memory alone can't reload for ever. The initial bundle measures 260,731 B
raw and 82,823 B gzip locally; its raw budget allows about 400 B above
that. The workspace, navigation shell and machine setup files' reviewed
design-contract hashes are renewed: their motion and presence class
producers are unchanged, only their storage calls moved.

Co-authored-by: Alex Lavaee <lavaman131@github.com>
lib0, which Yjs loads, reads localStorage.getItem as environment.js
loads; its storage.js guards only the getter, so a browser whose storage
throws on reads (a damaged profile) stopped the editor chunk from
evaluating. 0.2.120 is the newest 0.2 (Yjs needs ^0.2.99), so
patches/lib0@0.2.120.patch wraps that one read, as mdxeditor's patch is
applied; with working storage nothing changes.

scripts/check-storage.ts, in bun run ci, refuses localStorage or
sessionStorage named in code or a string anywhere in apps/web or the
packages but the guard and index.html's theme script (tests aside). Bun
drops a patch without a word once the installed version moves, so the
same check fails while the installed lib0 isn't the patched version or
lacks the guard.

Co-authored-by: Alex Lavaee <lavaman131@github.com>
Before any script runs the spec makes localStorage and sessionStorage
throw a SecurityError from their getters (site data blocked), then
setItem throw QuotaExceededError (a full or private store), then every
Storage call throw (a damaged profile). Each time it signs in, folds and
shows the sidebar, turns Aa off and on, sends a Chat message, opens AI
accounts, chooses Dark in the account menu, goes back to the document and
reloads, and holds that no page error or console error was raised and
nothing was said about storage. Without the lib0 patch the third mode
can't open the document. Timed locally: 3 tests in 7.3 s.

Co-authored-by: Alex Lavaee <lavaman131@github.com>
AGENTS.md's browser traps name the guard, the CI check and the lib0
patch. DESIGN.md records the decision: everything Chopin keeps in the
browser holds for the page when storage is refused, a reload starts from
the defaults, and nothing tells the person, as VS Code for the web says
nothing when it keeps its state in memory.

Co-authored-by: Alex Lavaee <lavaman131@github.com>
The image build measures the guard's initial bundle at 260,727 B raw and
83,654 B gzip, 4 B over the gzip limit, where a local build measures
82,823 B. The gzip limit is now 83,850, about 200 B above the container's
measurement, as the raw limit is about 400 B above.

Co-authored-by: Alex Lavaee <lavaman131@github.com>
@lavaman131
lavaman131 merged commit 778912b into main Nov 22, 2026
50 of 52 checks passed
@lavaman131
lavaman131 deleted the storage-unavailable branch November 22, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant