Repository navigation
feat(editor): accept no provider, add WriteGate and the decoration host (P2.2) - #123
Merged
9 commits merged intoNov 17, 2026
Merged
9 commits merged into
9 commits merged into
Conversation
WriteGate filters every local transaction that changes the document while canWrite() is false, appended ones included, so read-only never makes a Yjs update that would later have to be dropped (details spec §1 rules 1-2). Changes from Yjs and meta-only transactions pass. The decoration host generalises the action-preview stub (rule 6): each declared layer is one plugin holding a DecorationSet, set by the meta-only setDecorationLayer command and mapped or cleared on document changes, so comments and Find add no eager plugin of their own.
DocumentEditor now takes the session's Awareness and a provider that may be null (desktop P2.2). The caret is configured with that Awareness, and the extensions memo depends on it rather than on the provider, so attaching a provider later never calls setOptions. The connection chip renders only with a provider: its connection state creates the shared socket. UniqueID finds the caret's provider option and waits for its "synced" event, so on and off forward to the provider of the moment through a ref; the web behaves as before. WriteGate and an empty decoration host join the extensions. The new readOnly prop drives the gate and setEditable; the web never sets it.
The budget was 23.5 KB of growth (contract A12); main is at +15,691 B. D23 lowers it to main plus the 1,580 B ledger, +17,271 B, so unrelated work cannot spend the ledger's bytes. The report prints exact bytes.
…or-no-provider-a52225 # Conflicts: # CHANGELOG.md
#118 landed first: main is at +15,674 B, so the fence is +17,254 B (main plus the 1,580 B ledger). P2.2 measures 294 B on the merged tree.
expectSavedToServer (#116) read isSynced from the caret's provider option, which P2.2 made the editor's Awareness holder, so it never saw the server ack and the perf and collab runs timed out. filter.spec's copy saw undefined and stopped waiting at all. The caret option's on returns the provider's on, which returns the provider, so the helper asks it; filter.spec now uses the same helper. A unit test pins it.
…or-no-provider-a52225 # Conflicts: # CHANGELOG.md
#126 landed first: main is at +15,284 B, so the fence is +16,864 B (main plus the 1,580 B ledger). P2.2 still measures 294 B on the merged tree (+15,578 B).
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.
Desktop Phase 2, P2.2 (plan v8 §8.4, Appendix A; details spec §1 rules 2, 5 and 6; architecture §4 "Shared editor changes").
What changes
DocumentEditortakes the session'sawarenessandprovider: HocuspocusProvider | null.CollaborationCaretis configured with{ awareness, on, off }. Its 3.33 runtime reads onlyprovider.awareness.awareness, never on the provider, so attaching one later never callssetOptions.CollabStatusGrouprenders only with a provider, because itsuseConnectionStatecreates the shared socket.useYjsDocumentgains one line (awareness: provider.awareness), theDocHandleshape from feat(platform): add DocSession and DocStore port types (P2.1a) #119.provideroption and callsprovider.on("synced", …)on create.onandoffforward through a ref to the provider of the moment. The web waits on the real provider exactly as before. With no provider, nothing is waited for.WriteGate(extensions/write-gate/):filterTransaction: !docChanged || isChangeOrigin || canWrite(), over a ref and neversetEditable.readOnlyprop, which also feedssetEditable. It covers ProseMirror changes. The schema guard repairs by writing Yjs directly and is not gated yet; whoever first setsreadOnlymust gate it too, which costs a few bytes this line doesn't have.readOnlyReasonto it later (hand-over note left for P2.1).extensions/decoration-host/), the action-preview stub made general.DecorationSet, set by the meta-onlysetDecorationLayer(name, set).map: true.ActionPreviewis deliberately not migrated: its redraw-on-remote rule doesn't fit a plain layer.EDITOR_CHUNK_BUDGET_BYTES=maingrowth (15,284 B at 08b7663) + the D23 ledger (1,580 B) = +16,864 B, down from 23.5 KB. The script now prints exact bytes; CI already runs it in the checks job.Editor chunk (gz,
bun scripts/check-editor-chunk-size.ts)58a9d22main(08b7663, after #126)P2.2 measured the same +294 B on 1ed981e (after #118) and +297 B on f9cfc3a.
Stepwise while building (on f9cfc3a):
WriteGate: +109addToHistorymeta): −21The fence leaves 1,286 B for the ledger's other lines. #118 and #126 landed first, so the fence is measured on
mainafter both (commit 1c15715). Any later PR that adds tomainbefore the ledger lines land spends ledger bytes, which is the point of D23.Tests
tests/unit/extensions/write-gate.test.tsruns the app's real extension list over Yjs:updateUsergo through the Awareness;syncedwait is forwarded to the provider.tests/unit/extensions/decoration-host.test.ts: one plugin per layer, show and clear, layers are independent, plain layers clear,map: truelayers map.tests/unit/components/document-editor-no-provider.test.tsxrenders the realDocumentEditor:WebSockets;setOptionscalls;setOptions.bun run teston the tree merged with 08b7663: 1,695 pass, 0 fail.chromium+perfwith--retries=1: 526 passed, 0 failed, 1 flaky.CI= bun playwright test --project=chromium --project=perf --retries=1against isolated dev servers (Next on 3310, Hocus on 1534, raised socket limits as inplaywright.config.ts).DB_PATHto Playwright: the helpers read./db.sqlitewhile my servers used another file. WithDB_PATHset, those two files pass 9/9.perf(skipped behind them in the first run) passes 4/4: 50-heading typing p95 median 5.6 ms off and 6.0 ms on; 500-heading arrow p95 25.2 ms.bun run typecheckare clean.E2E helper fix after #118 (commit abebef8).
expectSavedToServerreadisSyncedoff the caret'sprovideroption, which this PR turns into the Awareness holder. Soperformance-collabtimed out in CI, and everyperfand soak spec that calls the helper would have done the same.filter.spec's copy of the check sawundefined, which made its wait pass at once without waiting.on, becauseHocuspocusProvider.onreturnsthis.filter.specnow uses the same helper, and a unit test pins the contract.windowhook cost 10–12 B of the 6 B left on this line, from identifier reshuffling, so the fix stays in test code. App bytes are unchanged (+294 B).performance-collab,filter,filter-collab,collaborationandidentity-dialogpass 10/10;perf4/4; quicksoakandsoak-collab2/2; all with no retries.Not in this PR
use-yjs-documentoverDocSession(P2.1).readOnlyReasontoreadOnly.