| 1 | # Local patches |
| 2 | |
| 3 | Original crates.io yrs 0.23.5 package SHA-256: `197c2b4b298f35c3ba4d549884ac872a961112095b29f173ab45e3d5cf609018`. |
| 4 | |
| 5 | Only `src/transaction.rs`, `src/block.rs`, `src/block_iter.rs`, `src/gc.rs` and `src/undo.rs` differ from the published Rust source. On a yrs bump, check each patch below against the new release: drop it if upstream has it, re-apply it if not, and keep its regression tests either way. |
| 6 | |
| 7 | ## Deletion backports (`src/transaction.rs`) |
| 8 | |
| 9 | - Move the deletion scan outside the initial item-split guard so a range beginning at a garbage-collected block still deletes later live blocks. Adapted from upstream [PR 614](https://github.com/y-crdt/y-crdt/pull/614), commit `97095f2e27e4045002b656cec6347e9f9a989c89`. |
| 10 | - Store an unapplied deletion tail beginning at the known client state, rather than the original range start; this matches current upstream `apply_delete` and preserves deletion when missing inserts arrive later. |
| 11 | |
| 12 | - Retain complete deletion ranges for clients whose first insert has not arrived yet, matching the upstream missing-client branch. |
| 13 | |
| 14 | Regressions live in `native/crdt/tests/rule_delta_convergence.rs`, `native/crdt/tests/delete_tail_review.rs`, and the server core native-rule fixture tests. |
| 15 | |
| 16 | ## Undo-kept children of a collected type (`src/block.rs` `Item::gc`, `src/gc.rs`) |
| 17 | |
| 18 | Backport of upstream commit [`0e5df000867d703cbc403feece4312900b954565`](https://github.com/y-crdt/y-crdt/commit/0e5df000867d703cbc403feece4312900b954565) ("fix relation between Item::gc and keep flag", issues [#667](https://github.com/y-crdt/y-crdt/issues/667) and [#676](https://github.com/y-crdt/y-crdt/issues/676)), first released in yrs 0.28.1. oficina/docs discussion #145, finding 1. |
| 19 | |
| 20 | - `Item::gc` no longer checks the keep flag. `GCCollector::mark_in_scope` and `mark_all` check it for the top-level candidates instead, and `collect_marked` replaces every marked item. |
| 21 | - So the children of a collected type are collected whatever their keep flag, as Yjs's `ContentType.gc` does. Before, clearing the redo stack un-kept an item's whole parent chain (`Item::keep(false)`) while a sibling on the undo stack stayed kept; when a peer then deleted that parent, the parent's branch was freed and the kept child still pointed into it. The next snapshot panicked (`slice.rs`, "Could not get parent branch info for item") or, in WASM, read freed memory and wrote a struct a fresh document could not integrate. |
| 22 | - Drop on a bump to yrs 0.28.1 or later. |
| 23 | |
| 24 | Regressions: `native/crdt/tests/gc_undo_kept.rs` (the editor repro and upstream's own test on this API), `native/crdt/tests/gc_undo_kept_fuzz.rs`, and the browser replay `native/crdt/src/bin/gc_undo_kept_probe.rs` with `native/scripts/check-gc-undo-kept-wire.mjs`. |
| 25 | |
| 26 | ## Local inserts into a deleted parent (`src/block.rs` `ItemPtr::redo`, `src/transaction.rs` `TransactionMut::create_item`, `src/block_iter.rs` `BlockIter::insert_contents`) |
| 27 | |
| 28 | Local patch; upstream has the same behaviour since its integration refactor (`0e450204ae`, "refactored transactions and correlated apply update / integrate block logic", yrs 0.27), where `TransactionMut::integrate_item` deletes an item whose parent is deleted for every caller. oficina/docs discussion #145, finding 9. |
| 29 | |
| 30 | - `Item::integrate` answers true when the new item's parent is deleted. The remote path (`Update::integrate`) then deletes the item, as Yjs's `Item.integrate` does for every insert, local or remote. The three local paths dropped the answer, so the inserting replica alone kept the item live: invisible under its deleted parent, but with a delete set no peer shared. Each now deletes the item after storing it, as `Update::integrate` does. |
| 31 | - `ItemPtr::redo` is how the editor reaches it: undo follows a deleted parent's `redone` chain to its restored copy, which a peer may since have deleted. `create_item` (text, element and attribute inserts) and `insert_contents` (array inserts) are patched for parity; the editor's commands address live nodes, so they are not known to be reachable from it. |
| 32 | - Drop on a bump to yrs 0.27 or later, after checking `integrate_item` still deletes for all three. |
| 33 | |
| 34 | Regressions: `native/crdt/tests/insert_into_deleted_parent.rs` (the undo case, and every local insert path into a type a peer deleted; each fails without its patch). `gc_undo_kept_fuzz.rs` found the undo case at seed 42, and the engine branch's `convergence_fuzz.rs` at seeds 76 and 113. `check-gc-undo-kept-wire.mjs` checks Yjs deletes a local insert into a deleted parent. |
| 35 | |
| 36 | ## Redo origins (`src/block.rs` `ItemPtr::redo`) |
| 37 | |
| 38 | Local patch; neither upstream yrs (main, November 2026) nor Yjs 13.6.27 has it. oficina/docs discussion #145, found by `gc_undo_kept_fuzz.rs` at seed 98. |
| 39 | |
| 40 | - `redo` finds the restored item's neighbours by following `redone` chains, and both can land on the same restored item: the left neighbour traces to it directly, the right one through an original whose restored copy starts there. Both libraries then integrate the item right after it locally, but write origins (after the end of the merged block that item now ends, before the item inside it) that every receiver resolves to a place before it. Yjs's own `redoItem` and `getMissing` do the same (checked: Yjs's editor shows "Axz", a Yjs peer "Azx"). |
| 41 | - When the traced right neighbour is not to the right of the left one, `redo` now names the item actually after the left one instead. The item still goes after the left neighbour, but local placement can change slightly. Before, the local integrate scanned from the left neighbour's right for conflicts and could step past siblings with the same origin from a lower client. Now nothing lies between the two neighbours, so it goes directly after the left one, which is where the origins put it on every receiver, Yjs's included. The walk that checks the right neighbour is linear in the parent's length only in this case; otherwise the neighbours are adjacent or the right one is absent. |
| 42 | - Keep on a bump unless upstream has changed `redo`'s right-hand trace. |
| 43 | |
| 44 | Regression: `native/crdt/tests/insert_into_deleted_parent.rs`, `an_undo_whose_neighbours_trace_to_one_item_places_it_as_every_peer_does` ("Azx" at the peer without the patch). |
| 45 | |
| 46 | ## Redo order (`src/undo.rs` `UndoManager::pop`) |
| 47 | |
| 48 | Local patch. oficina/docs discussion #145. |
| 49 | |
| 50 | - `pop` collected the items to restore in a `HashSet<ItemPtr>` and restored them in its iteration order, which depends on the process's random hash keys. Restoration order decides where restored items are placed relative to each other, so the same undo could come out differently from run to run: the redo-origins failure above appeared in about one run in four. Yjs restores in its `Set`'s insertion order, the order the deletions are found. |
| 51 | - Items are now restored in the order the deletions are found, the `HashSet` kept for membership. yrs's delete set iterates clients in a fixed order (`ClientHasher`); Yjs's is the order the deletions were made, so the order across clients can still differ from Yjs, but it no longer differs between runs. |
| 52 | - Keep on a bump unless upstream has made the order deterministic. |
| 53 | |
| 54 | ## Unchanged |
| 55 | |
| 56 | Garbage collection remains enabled. Wire format, client IDs, undo policy, and sandbox limits are unchanged. |
| 57 | |
| 58 | The registry package omits its license text; `LICENSE` is copied from the exact upstream VCS commit `3996e91df00acdb67334695944bc43f60627103f` recorded in `.cargo_vcs_info.json`. Original attribution is retained. |
| 59 | |