feat: support mergeable map child containers#85
Merged
Conversation
zxch3n
marked this pull request as ready for review
June 15, 2026 04:01
Document the problem mergeable map child containers solve (concurrent child creation under the same Map key being dropped by last-writer-wins), what enabling the option does (logical-position-derived identity so peers converge on one CRDT object), and how to configure it. Adds a usage example to the core README and expands the JSDoc on both `SchemaOptions` and `InferContainerOptions`, with links to the Loro blog. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
toNormalizedJson built each map via LoroMap.getShallowValue(), which leaks
mergeable child containers as raw binary markers instead of resolving them.
As a result the public helper (and the schema-less buildRootStateSnapshot
fallback) returned garbage (e.g. {0:0,1:76,...}) for any mergeable Map/List/
Text/MovableList/Tree child, even though getState() and doc.toJSON() were
correct.
Resolve containers explicitly via get()/toJSON() so both regular and mergeable
children are normalized uniformly with $cid injected on every map. Because
toJsonWithReplacer re-resolves mergeable container-id strings found in the
returned structure (corrupting nested $cid), inject $cid behind a sentinel
prefix during the pass and strip it in restoreCidDescriptors.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
loro-crdt 1.13.2 panics (unreachable at container_store/container_wrapper.rs) when importing an out-of-order op on a mergeable child container; fixed upstream in 1.13.3. Raise the peer dependency floor across core/react/jotai and update the docs/JSDoc version requirement accordingly so the mergeable feature only runs against a loro-crdt build that has the fix. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
vitest typecheck (CI) flagged the object-literal setState calls: the record value omitted a required field and the tree node omitted its required `id`. Drop the unused optional field from the schema and add the tree node id so the test type-checks while exercising the same runtime behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
LoroMapkeys.schema.LoroMap(..., { mergeableMapChildContainers: true })andschema.LoroMapRecord(..., { mergeableMapChildContainers: true }), withinferOptions.mergeableMapChildContainersas the schema-less/global fallback.setContainerdata, and by keeping the default behavior disabled.Why
Loro's mergeable container APIs avoid concurrent first-creation races for child containers under the same Map key. Loro Mirror previously always used regular
setContainercreation for Map child containers, so two offline peers could create distinct children for the same logical field and one child would become hidden after sync.Behavior Notes
LoroMapuseensureMergeableMap/List/MovableList/Text/Tree.Validation
pnpm --filter loro-mirror test tests/mergeable-containers.test.tspnpm --filter loro-mirror buildpnpm typecheckpnpm lint(passes with existing warnings)pnpm --filter loro-mirror test -- --testTimeout=10000