Skip to content

v0.18.10

Latest

Choose a tag to compare

@isac322 isac322 released this 11 Nov 21:51
· 60 commits to main since this release
v0.18.10
a63eed0

Update your devices and self-hosted hubs for the co-editing and merge fixes; running daemons switch over the first time the updated bdrive runs. Client wire and local volume on-disk formats remain backward-compatible, and v0.18.10 hubs read the bare-sha ydoc/head/<path> records older hubs wrote.

Upgrade every hub process that shares a storage root together. v0.18.10 hubs write ydoc/head/<path> as JSON ({sha, win}), which a v0.18.9 or earlier hub process cannot read. During a mixed-version rollout or a rollback, that older process skips the newest stored room state and falls back to the per-blob CRDT history (ydoc/<sha>) or, when none matches, to fresh file bytes. Multi-instance self-hosted operators should not run v0.18.9 and v0.18.10 side by side on one storage root.

Changes

  • Co-editing rooms seed from the newest stored state across hub processes. ydoc/head/<path> now stores {sha, win}, where win is the winKey of the journal op that produced the stored room state. A head write with an older win is refused, so an older fold in any process can no longer move the head backwards, and a room whose file no longer matches the head seeds from the file. knows() merges the other state into a scratch copy and checks whether anything changed, so stored histories that contain deletions compare correctly. Empty rooms stay loaded for 2 minutes (collabRoomIdleTimeout), and the Redis relay keeps 30 minutes of updates (StreamRetention, up from ygo's 60-second default); a failed snapshot republishes the room's full state into the relay.
  • Outside writes merge into live rooms without losing concurrent typing. moveDocLive computes the change on a private copy of one atomic room snapshot and applies only the resulting CRDT item delta, so keystrokes that arrive during the merge stay in place instead of shifting by stale character offsets.
  • POST /api/p/<id>/ycollab/sync merges browser edits into a room over HTTP. A browser without a connected socket sends its Yjs state, or its text with the base it started from; peek reads the room without writing. The hub answers ok only after storage holds the edit, waiting up to 8 seconds (ycollabSyncDurableWait), including for the lease holder in another process (snapshotMax lowered to 6 seconds); otherwise it returns 503 and the browser keeps its edits. bdrive desktop proxies the route to the hub.
  • Concurrent text edits merge per hunk and per word. internal/textmerge and its browser port frontend/src/lib/merge3.ts diff each side with Myers O(ND), so edits in different parts of a file merge as separate hunks (diff3). Two edits to the same line merge word by word when they change different words, and insertions at the same point are ordered by content, so merge(base, a, b) equals merge(base, b, a). The merge runs in PUT /api/p/<id>/upload/content on a stale If-Match (text up to 4 MiB; X-Bdrive-No-Merge opts out), MCP write and edit on an outdated sha, live room reconciliation, and internal/syncer.
  • Hub writes record their base, and devices skip redundant merges. Conditional hub writes record the version they were built on in Op.Base. The sync engine merges a losing op against the op that won, and when the result equals the winner's content, it fast-forwards without writing a duplicate op.
  • Browser co-editing keeps edits through slow joins, saves, and most tab closes. When the room has not answered after 2.5 seconds, the editor mounts a staging buffer (onStalled, and stageDoc in VisualEdit), checkpoints it over ycollab/sync, and merges it three ways when the socket connects instead of dropping permanently into solo mode after 8 seconds. save() and offline room flushes are single-flight with sequence watermarks. Mod-s saves immediately, and Done saves every edit, including any typed during the save, before leaving, and stays in the editor if the save fails or opens a shrink confirmation. pagehide sends pending edits with keepalive when the encoded HTTP request body is at most 60,000 bytes (KEEPALIVE_MAX_BYTES, below the browser's 64 KiB in-flight keepalive limit); a larger body goes out as a regular fetch, which the browser may cancel during unload, and delivery is never guaranteed once the browser tears the page down. pageshow resets the exit-send guard, so a page restored from the back/forward cache can flush again on a later close. VisualEdit splices only changed spans within an element, and post-saved room snapshots advance saved and base without raising #peer-wrote.
  • VisualEdit flushes unacknowledged iframe edits through a same-origin exit worker when the tab closes. The editing iframe stays sandbox="allow-scripts" and is never given a session, token or URL. VisualEdit starts a dedicated Web Worker on the app's origin (editexit.worker.ts), keeps it current with the rendered source, the anchored ranges and what the file and document hold after every save, and hands the iframe only one end of a MessageChannel (bd-edit:port). The iframe streams each edit to the worker as it happens (bd-edit:span) and keeps no record of its own; the app tells the worker directly which patches it applied (ack), so all span and acknowledgement state lives in the worker. When the iframe unloads it posts bd-edit:exit, and the worker saves whatever is still unacknowledged, marking sent spans acknowledged only after a confirmed 200 OK response (reconciling and retrying across bfcache restores on 5xx or network errors) while advancing each span's acknowledged sequence (ackedSeq) monotonically so a late response never rolls the merge ancestor backward. This exit save is best-effort and runs only once the worker has started and been armed with the anchored render. The worker splices only anchored, script-free spans onto the render, merges the result three ways with the current document, and saves it with the app's own cookie: POST /api/p/<id>/ycollab/sync on a hub or bdrive desktop, or PUT upload/content on the latest If-Match in a plain folder, so it also works after earlier auto-saves. A same-word clash parks a conflict copy, an unconfirmed sharp shrink is not sent, and delivery is still subject to the browser's teardown limits (keepalive up to 60,000 bytes).
  • The VisualEdit iframe talks to the app only over a sealed channel, and the exit worker re-arms after a back/forward-cache restore. The editable view now injects /inline-edit.js synchronously before any script in the synced HTML file, so it captures the browser's own MessageChannel, MessagePort methods and Event.isTrusted, uncurries the WeakMap, Map and Set builtins it uses, and freezes the DOM, Event, Range, Selection and geometry prototypes before page code can replace them. It opens a private MessageChannel and sends bd-edit:hello with one port to the app once; every later editor message (ready, patch, port, flush, unlock) uses that channel instead of window.postMessage, and an editor opens or changes only on a trusted user event. Pasted formatting is kept only from the trusted clipboard's text/html. When a page comes back from the back/forward cache, VisualEdit sends the exit worker rearm with a fresh port, so an unacknowledged edit made after the restore is still saved when the tab closes again.
  • VisualEdit edits only the ranges the hub stamped, and page scripts cannot write into an open editor. The bootstrap tag now also carries data-src-ranges, the stamped start,end list the hub measured. inline-edit.js reads and removes its data-src-* attributes at load, locks data-bd-src against page-script writes, and binds each stamped element once, refusing a duplicate or unstamped range. A page script that changes the element being edited (its own key or input listener, execCommand, any DOM write) is refused, and the frame reports bd-edit:clobbered instead of saving. Before anchoring a range or arming the exit worker, VisualEdit checks that the element's initial HTML matches the source slice, comparing both as an inert <template> parses them.
  • The VisualEdit editor runs inside a closed shadow root. inline-edit.js mounts the editor on an element inside a closed shadow root (attachShadow({ mode: "closed" }), captured at load) attached to a <span data-bd-shadow> inside the element being edited, and writes the edited inner HTML back to that element when the editor closes. Page scripts in the synced file get null for its shadowRoot and see events retargeted to the host, so they cannot reach the editor's live nodes through reflected properties such as a link's href, through references saved before the editor opened, or through another frame's DOM setters, including during a real paste. Removing the edited element or the shadow host reports bd-edit:clobbered, and nothing is saved.

Known limitations

  • Simultaneous edits to the exact same word outside a live CRDT room (offline, CLI, or MCP) still park a .bdrive-conflict-* copy so neither rewrite is dropped.
  • A pagehide flush, or a VisualEdit exit-worker save, whose encoded HTTP request body exceeds 60,000 bytes is sent as a regular fetch without keepalive, and the browser may cancel it during unload.
  • Hub processes on v0.18.9 or earlier cannot read the new JSON ydoc/head/<path> records and fall back to the per-blob CRDT history (ydoc/<sha>) or, when none matches, to fresh file bytes, so a mixed-version rollout or rollback across processes sharing one storage root can skip the newest stored room state.
  • Windows builds remain unsupported (pre-existing Unix flock / signal dependencies in internal/store and internal/daemon).