Repository navigation
fix(loro.js): keep a checkout of the current latest version attached - #1143
Merged
Merged
Conversation
Rust's checkout returns early when the target equals the state's frontiers, re-attaching when they are the latest frontiers, and also when the shrunk target equals them. loro.js always detached, so `doc.checkout(doc.frontiers())` stopped later imports from reaching the state and made loro.js peers diverge from loro-crdt ones that ran the same calls. The old detached-import test relied on this; it now uses detach(). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
WASM Size Report
|
…current-attached # Conflicts: # loro-js/src/runtime/document.ts
Member
Author
|
Merged the latest Still needed on |
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.
Summary
doc.checkout(doc.frontiers())detached aloro.jsdocument even when those frontiers were the latest version, so later imports stopped reaching its state.loro-crdtleaves the document attached. Aloro.jspeer and a Rust peer that ran the same calls then diverged, and the differential fuzz saw it as lost imports.Rationale
Rust's
_checkout_without_emitting_with_eventreturns early when the target equals the state frontiers, re-attaching when they are the latest frontiers. It also returns early (keeping the attach state) when the shrunk target equals them, e.g. a target with a dominated extra frontier.loro.jsnow does the same, clears#checkoutVersionwhen it re-attaches, and emits no event, like Rust. Checking out the latest version from an older one still leaves the document detached; onlycheckoutToLatest()/attach()re-attach from there, as in Rust.The existing test "records imports in the oplog while the state is detached" relied on the old behavior to detach; it now calls
detach().Validation
loro-js/tests/runtime.test.tscovering: attached checkout of the current version (imports still apply), a dominated extra frontier, a repeated checkout of an old version, old → latest staying detached, anddetach()thencheckout(frontiers)re-attaching and accepting local edits. Fails onmain. Every assertion was checked againstloro-crdt(WASM build of thismain), which returns the same attach state in all cases.pnpm --dir loro-js format:check,lint,typecheck,test(248 passed),build.bench:complexity(1k–8k), 7 alternating rounds vsmain, loadavg 25–34: 284 items, none both >1.5× and >0.3 ms slower. Total 1301 ms onmain, 1258 ms here.Found by the differential fuzz harness (#1141), and listed by #1132 as a non-MovableList divergence.
🤖 Generated with Claude Code