Repository navigation
refactor(editor): tab buffer state lives in a per-tab store record, mirrored onto the tab - #30885
Conversation
…rored onto OpenFile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
ELI5
Each open editor tab keeps a few facts about its file: whether it has unsaved edits, which disk version those edits are based on, whether the file changed on disk underneath it, and a few "don't autosave yet" holds. Today those facts live directly on the tab. This PR moves them into their own small record in the store, one per tab, and keeps a copy on the tab so nothing that reads them has to change. Nothing looks or behaves differently.
This is Phase 1a of the design in #30851: the first, purely mechanical step towards one shared buffer per file.
What Changed
editorBuffersin the store holds, per open tab id, exactly six fields:isDirty,lastKnownDiskSignature,externalMutation,pendingDiskBaselineVerification,pendingLiveDiskVerificationandpendingOwnerMigration. The same fields onOpenFilestay as a copy, written in the same store update. Unsaved drafts (editorDrafts) and the move-echo marker (pendingSelfMoveEcho) stay where they are.open-file-mutations/ restored-owner setters, the restored-owner migration's success and failure paths, the self-move re-key (which also sets the move's autosave hold), and mirrored web-client tabs from a host snapshot.Why
The goal is one record per file as the single owner of its text and disk state. Doing that in one step would mix a large mechanical move with behaviour changes. Moving the state first, keyed by the existing tab id and with a copy on the tab, keeps this PR behaviour-neutral. Later phases can then switch readers and merge records without also moving state.
How the invariant protects "no behaviour change": in dev and test builds, the middleware checks after every store write that record keys equal the open tab ids and that every copied field on a tab equals its record. A store action that changes one of the six fields on a tab without going through the record throws in tests, so a missed writer fails CI instead of drifting quietly. The whole existing renderer suite runs with the check on. Fixtures that seed tabs through
useAppStore.setStateare treated like hydrate: their records are seeded from the tab. In production builds the same mismatch adopts the tab's value, so a missed writer still behaves exactly as main does.Alternatives considered: deriving the record from the tab after every write would make the tab the real owner and defeat the point. Explicit create/delete calls at every open and close site would touch dozens of places that add or remove tabs. Tying membership to the store write is smaller and can't miss a site.
Linked Issue
Phase 1a of the design in #30851.
Visual Proof
N/A: state is moved inside the store with no UI or interaction change.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
New
store/editor-buffer-record-lifecycle.test.ts: each of the six setters writes the record and its copy in a single store notification; open creates, close deletes, self-move re-key moves the record and sets the move's autosave hold on both copies; hydrate creates records from the session instead of from a replaced tab with the same id; an externally seeded tab gets a record seeded from the tab; a store action that writes a copied field without its record throws.New
runtime/editor-buffer-dirty-readers.test.ts: a dirty change made through the record reaches the web-session tab sync (sameOpenFiles), session save (buildEditorSessionDatapersists the draft), the mobile session projections, and the mobile markdown bridge read.Full
src/renderervitest suite with the invariant enabled: 4,996 files passing. One terminal-pane test (remote-snapshot-alt-screen-host-chain) timed out on a cold import under load and passes when rerun; it mocks the store.pnpm tc,pnpm run check:code-quality:changed.AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
openFiles. Writes that don't touchopenFilesreturn immediately.store/index.tsis indentation from the extra middleware wrapper. View it with whitespace hidden.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)