[lexical-y][lexical-playground][lexical-website] Feature: Merge a block both sides changed with diff3 when unsynced edits are replayed #9914
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #9914"
general
weight: 0.35
potatowagon
Description
describeUnsyncedEdits(@lexical/y/headless) and the replay on top of it(
replayUnsyncedEdits,recoverYOfflineEditson@lexical/y/offline)compare three documents block by block: the base, the user's and the current
one. A block only the user changed is replayed whole. A block both sides
changed was always a conflict, and went to the app's Offline edits panel
whole, even when one person fixed a word at the start of a paragraph and the
other added a sentence at its end.
Such a block is now merged three ways inside the block with diff3, the merge
version control systems use, on the Lexical JSON the report already reads (no
layout code, nothing new stored). It stays a conflict, exactly as before,
when the changes overlap or the merge cannot be shown to be safe.
internal/Diff3.ts: node-diff3 4.0.0'sLCS,diffIndicesanddiff3MergeRegions, vendored unmodified under its MIT license (thepackage takes no third-party runtime dependency; listed in
.prettierignoreso it stays byte-identical to the published source).4.0.0 is a day old, inside the 7 days
minimumReleaseAgekeeps newreleases out of dependencies; it is the release whose rewritten LCS stays
fast on repeated text (3.2.1's scans every candidate).
Diff3.test.tschecks its LCS against a dynamic-programming LCS over 3,000 random pairs,
and D133 records it.
internal/BlockMerge.tskeeps only the Lexical-specific parts around it:- Tokens. A text block becomes tokens (a character with its node's
format, style and NodeState, and the link or mark around it; one token
for a line break, a tab, a decorator or a token-mode text node).
- Pass 1, content. diff3 runs over words (a run of letters and digits;
any other token alone), compared by content only: a change one side made
is taken, the same change on both sides once, and changes to one word,
or that overlap or touch, are a conflict. Inside a word one side changed,
a second
diffIndicesover characters finds the letters it kept. In ascript written without spaces (Chinese, Japanese, Thai), each character
is its own unit.
- Pass 2, properties. Each token both sides kept merges its properties
three ways (format per bit, style, NodeState per key, link or mark).
Two bits of one exclusive group (subscript and superscript; lowercase,
uppercase and capitalize) that no side held together are a conflict.
Typed text between two tokens the other side changed alike takes that
change, and text one side removed that the other reformatted is a
conflict.
- Containers. Lists and tables merge by the same diff3 over their
children's block ids (rows and cells, which have none, by the first block
with an id inside them).
- Checks. The merge is made again by word read from the end and by
character from both ends, and every reading must make the same block;
merging the user's block into the result again must change nothing.
- Cost. A block of more than 10,000 tokens, or a side adding or
removing more than 5,000, is not merged (
unsupported): they bound theLCS, whose cost grows with how far two sequences differ.
YUnsyncedBlockgainsresolution('whole','merged','conflict'),merged,conflictandconflictDetail.replayUnsyncedEditswrites amerged block over the block it was merged from, checked as a whole block
is.
blockMerge: falseon the describe, replay and recover calls turns themerge off. All additive; the merge is on by default.
the Offline section, and two limits.
BlockMerge.tsis 1,623 lines (1,309 without comments) holding the types,the property merge, tokenizing and rebuilding runs, the container walk and
the report. A custom Myers-based merge with its own alignment widening and
closeness rules took 1,888 (1,557), plus a Myers module. The vendored diff3
is 434 lines, license header included.
Inline.tsis unchanged.Changeset
.changeset/lexical-y-offline-block-merge.md([feature], withVerify:).Test plan
A seeded corpus (
BlockMergeCorpus.test.ts,utils/blockMergeCorpus.ts) of2,800 pairs of concurrent edits to one block (paragraphs, a heading, bold and
italic runs, links, line breaks, a list, a table, repeated letters) is checked
against a model in which every character has an identity. Of the 2,769 blocks
that are conflicts without the merge:
300,000 more seeds: 172,410 of 297,399 merge, 0 wrong, 0 of 20,605
order-dependent cases merged.
BlockMergeReplay.test.tsruns 217 of thecases, and every node shape of the catalog, through stored documents and a
bound editor.
BlockMerge.test.tshas 81 rule cases, including these:reply added while text is typed inside, two side by side stay two;
in a second pass, not as edits);
- two links or marks the other side made around typed text stay two;
- NodeState merges key by key, and its keys are plain keys whatever
their names (
format,text,valueOf);- a
__proto__key in a NodeState value;- an accent in a text node of its own.
Before
On main, the new tests of
OfflineSession.test.ts:After
The full
unit,unit-sizeandscripts-unitprojects and the browserrun above were on the branch before its last review fixes, which touch only
internal/BlockMerge.tsand its tests; the lexical-y suites were rerunafter them.
pnpm run flow,tsc,eslint,prettier --list-different .andpnpm run check-changesetspass. Firefox and WebKit were not run.