Commit 370f6f0
feat: support mergeable map child containers (#85)
* feat(core): support mergeable map child containers
* fix(core): harden mergeable map child updates
* test(core): cover mergeable child container variants
* fix(core): keep container registration warnings debug-only
* refactor(core): avoid detached containers for mergeable map inserts
* docs(core): explain mergeable map child containers
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>
* fix(core): resolve mergeable child containers in toNormalizedJson
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>
* chore(deps): require loro-crdt >=1.13.3 for mergeable containers
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>
* chore: refresh pnpm lockfile
* test(core): fix type errors in mergeable toNormalizedJson test
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>
---------
Co-authored-by: Zixuan Chen <me@zxch3n.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 7a521bc commit 370f6f0
12 files changed
Lines changed: 1282 additions & 351 deletions
File tree
- packages
- core
- src
- core
- schema
- tests
- jotai
- react
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| 169 | + | |
169 | 170 | | |
170 | 171 | | |
| 172 | + | |
171 | 173 | | |
172 | 174 | | |
173 | 175 | | |
| |||
409 | 411 | | |
410 | 412 | | |
411 | 413 | | |
412 | | - | |
| 414 | + | |
413 | 415 | | |
414 | 416 | | |
415 | 417 | | |
| |||
427 | 429 | | |
428 | 430 | | |
429 | 431 | | |
| 432 | + | |
430 | 433 | | |
431 | 434 | | |
432 | 435 | | |
| |||
476 | 479 | | |
477 | 480 | | |
478 | 481 | | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
479 | 486 | | |
480 | 487 | | |
481 | 488 | | |
| |||
495 | 502 | | |
496 | 503 | | |
497 | 504 | | |
498 | | - | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
499 | 509 | | |
500 | 510 | | |
501 | 511 | | |
| |||
505 | 515 | | |
506 | 516 | | |
507 | 517 | | |
508 | | - | |
509 | | - | |
510 | | - | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
511 | 521 | | |
512 | 522 | | |
513 | 523 | | |
| |||
518 | 528 | | |
519 | 529 | | |
520 | 530 | | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
526 | 531 | | |
527 | 532 | | |
528 | 533 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
122 | 154 | | |
123 | 155 | | |
124 | 156 | | |
| |||
155 | 187 | | |
156 | 188 | | |
157 | 189 | | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
163 | 195 | | |
164 | 196 | | |
165 | 197 | | |
| |||
200 | 232 | | |
201 | 233 | | |
202 | 234 | | |
203 | | - | |
| 235 | + | |
204 | 236 | | |
205 | 237 | | |
206 | 238 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
0 commit comments