Repository navigation
Render Chopin in a browser that refuses its storage - #993
Merged
Merged
Conversation
…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
force-pushed
the
storage-unavailable
branch
from
November 22, 2026 08:06
6b2eb18 to
d99303e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chopin never rendered in a browser that refuses site storage. With "Block all cookies" or site data blocked, Chrome and Edge throw a
SecurityErrorfrom thelocalStorageandsessionStoragegetters themselves. The document page read storage in several places without a guard and ended on "Couldn't open this document". The theme script inindex.htmlalready coped.What changed
safeLocalStorageandsafeSessionStorage(@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.setItemanswers whether the browser actually kept the value.JSON.parsestay.setItemsays the browser kept its timestamp. A test with a refused store holds this.localStorage.getItemunguarded whenenvironment.jsloads; itsstorage.jsguards 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, sopatches/lib0@0.2.120.patchwraps that one read, applied throughpatchedDependenciesthe same way the mdxeditor patch is. With working storage nothing changes. Nothing was opened upstream.scripts/check-storage.tsruns inbun run ci. It refuseslocalStorageorsessionStoragenamed in code or a string anywhere inapps/weband the packages, except the guard andindex.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.DESIGN.mdrecords the decision andAGENTS.mdlists the guard, the check and the patch.bundle-budget.tsdo. A local build outside the container measures 82,823 B gzip.workspace.tsx,navigation-shell.tsxandexperiments/machine-setup.tsx. Their motion and presence class producers are unchanged; only their storage calls moved.e2e/shard-timings.jsongains the new spec.Design decisions and the references followed
excalidraw-app/data/localStorage.tstry/catch pattern, but without itsconsole.error.InMemoryIndexedDBStorageDatabasewhen its browser storage can't be opened.storageAvailablecheck MDN documents in "Using the Web Storage API".DESIGN.mdkeeps helper text for when people need to act or recover.Evidence
e2e/storage-unavailable.e2e.tscovers three modes: getters throwingSecurityError,setItemthrowingQuotaExceededError, 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.origin/main, the two modes the spec had then (getters throwing, every call throwing) both failed with "Couldn't open this document".bun test apps/web packages scripts: 3817 passed, 3 skipped, 0 failed.bun run ciandbun run typespass.emoji.e2e.tsalso passed (12 tests).production-dependenciesstage, the installed lib0 carries the patch, and a localdocker build --target buildpasses the bundle budget.