Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/y
@lexical/yjs
commit: |
…website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding
## Description
A new experimental package, `@lexical/y`: a collaboration binding for
Lexical on Yjs 14 (`@y/y`). `@lexical/yjs` (Yjs 13) is unchanged (its
source; one test file of composition traces is added, see Core): Yjs 14 is a
different npm package with a different API, so a Yjs 14 binding cannot
replace it in place, and an application uses one or the other.
Try it: [jot.rovira.sh](https://jot.rovira.sh), a full-page note anyone
with the link can edit at the same time, built on `@lexical/y` (source:
[zurfyx/jot](https://github.com/zurfyx/jot)).
Current behavior: the only binding, `@lexical/yjs`, stores one shared
element per Lexical node. Splitting, joining, retyping or re-indenting a
paragraph, and linking or unlinking text, are written as a delete and a
re-insert, so a collaborator's concurrent typing there can be lost or
misplaced, and every Enter or heading change rewrites elements.
New behavior: `@lexical/y` stores a paragraph, heading, quote or list item
as its characters followed by a marker, a list as the items it groups and a
link as a format over its characters. The storage is derived from general
facts the node classes declare in `$config` (`inline`, `children`,
`mergeAdjacent`, `derived`), with one fixed rule, first match wins: a block
with `children: 'inline'` is a line; an inline element with `mergeAdjacent`
is a format; a block listing line classes as `children`, with
`mergeAdjacent`, is a group (a line holding its own group, a list item
holding a list, is the only nesting); anything else is nested. The first
three also need the class's data to be fully in its schema and NodeState.
These edits then keep the characters and merge with concurrent typing.
Built on the `$config` keys, their declarations on Lexical's nodes and the
opt-in `NodeStructureExtension` (#9452, on main); the binding registers that
normalization, so each client writes its own edits in the normalized form
the declarations describe, and shows a remote change as it is stored (the
binding writes nothing for a remote change or when a document is opened,
except `BlockIdExtension`'s renaming of blocks inside named slots that
repeat an id, and, rarely, of a quote nested in a quote that holds
paragraphs after a deep copy (see Known open issues); every update the
binding makes itself
(its reads and its refresh) is tagged `COLLABORATION_TAG`, so an app
listener that edits on every change skips those; the update Lexical makes
to run a newly registered transform, which the binding runs on its own,
keeps Lexical's tags).
There are no collab-specific keys
in core and no binding-level storage overrides.
Also new here: `describeStorage(editor, binding?)` (the kind per type), and a
per-document pin: the first write of a type records its kind and identity
fields on the root (`k:<type>`, outside the undo history); a later client
whose class derives another kind uses the recorded kind when it can store
the class that way, and opens read only otherwise. List identity is the
declared `mergeAdjacent.by` fields only (`listType`), so NodeState such as a
block id never splits a list.
Entries (all `@experimental`):
- `@lexical/y`: `YBinding` (its `editor`, `doc`, `root`, `status`, `pins`
and `undoManager` are read-only getters), `YCollabExtension` (binding,
collaborative undo, `status` signal; conflicts with the history
extensions), `describeStorage`, `DEFAULT_ROOT_NAME`, `LAYOUT_VERSION`, and
the types `YBindingOptions`, `YBindingStatus`, `YCursor`, `YCollabConfig`,
`ClientIDRange`, `StorageKind`, and the warning code constants below with
their union type `YWarningCode`. No React, no DOM requirement.
- `lexical`: `LexicalWarning` (`extends Error`, `readonly code: string`,
`readonly data?`), a generic class with no codes of its own, and the
update tag `DEFER_COMPOSITION_MERGE_TAG` (see Core). The node structure
normalization gains one internal hook, `INTERNAL_$liftsFromStructure`,
beside its merge and split hooks (see Lists), and the editor state
internal records of text splits and text edits (see Core).
- `@lexical/list`: no new API. Where `NodeStructureExtension` enforces
declared structure (opt-in), a list item that holds a nested list holds
nothing else (lifted only out of an item an update creates or changes);
the outdent of a wrapper item's only or middle item, which deleted what
the wrapper holds beside its nested list, keeps it, in reading order, in
every editor (see Lists).
- `@lexical/extension`: one new `BlockIdExtension` option,
`repairTransforms` (default `true`, behaviour unchanged; see Block ids).
- The www entry stub `packages/lexical-y/LexicalY.js`, as every other
single-entry package has.
- No server entry: old clients write other roots (see "Old clients"), so a
server needs no API of its own; the two constants a server may want
(`DEFAULT_ROOT_NAME`, `LAYOUT_VERSION`) come from the main entry.
- Seeding a document on a server is `seedYState` in `@lexical/y/headless`
(#9437, stacked on this); the internal one-off writer is not exported.
Warnings: `lexical` exports `LexicalWarning` (`extends Error`, `readonly
code`, `readonly data?`), which packages pass to the editor's existing
`onWarn` (its `(error: Error) => void` signature is unchanged) for warn-level
conditions with a stable, package-namespaced code (`code` is a `string`;
core knows no codes). Documented under "Errors and warnings" in Defining
Extensions, with neutral example codes. `@lexical/y` has no `onWarn` option
of its own: every
warning goes to the editor's `onWarn` as a `LexicalWarning`, with an exported
constant per code: `UNSUPPORTED_LAYOUT_WARNING`
(`'@lexical/y/unsupported-layout'`), `UNKNOWN_NODE_TYPES_WARNING` and
`STORAGE_MISMATCH_WARNING` (each makes the binding read only),
`SELF_CHECK_WARNING`, `RECOVERED_READ_WARNING`, `RECOVERED_WRITE_WARNING`,
`NESTED_FALLBACK_WARNING` (a class stored nested, for example a link subclass
that overrides `shouldMergeAdjacentLink`), `UNSYNCED_VALUE_WARNING`,
`UNSUPPORTED_SLOTS_WARNING` (a named slot the document cannot store: the
change is not written and the binding is read only) and
`UNSUPPORTED_CONFIG_WARNING` (`BlockIdExtension` with `repairTransforms:
true`: nothing is written and the binding is read only), each with
documented `data`, and their union, the `YWarningCode` type. Codes are
public API: never renamed or reused, only added, so a `switch` over them
needs a `default`. A warning is delivered once a change has been applied
in full, never from inside a Yjs observer or transaction, and a handler that
throws does not affect syncing (its error is rethrown in a microtask). The
class and value warnings (`NESTED_FALLBACK_WARNING`,
`UNSYNCED_VALUE_WARNING`) are found once per process and reported once per
binding (a class's only to editors that register it), so a second editor
gets them too. `YBindingOptions.onStatus` is called the same way: once the
binding's work is done and Yjs is idle, never inside a Yjs observer.
Without an `onWarn`, Lexical's default applies (it throws in development,
outside Yjs, and `console.warn`s in production).
Docs: a new page, Collaboration > Yjs 14 (`@lexical/y`): when to use it
rather than `@lexical/yjs`, install, setup with `YCollabExtension` and a
provider, the options, warnings (the codes, their `data`, delivery and the
default handler), how content is stored (diagrams of a paragraph and a
heading, a nested list, a link and a table next to the sequence that stores
them), the wire format (a diagram of layout 1: a container's sequence of
characters, `¶` markers with their attributes, format ranges and nested
nodes, and the root's layout record and storage pins, with the stored names
checked against a dumped document and a link to the README's
specification), what changes when collaboration is on (why, a before/after diagram per
rule: a block split around, a heading in a link, paragraphs in a quote
becoming one quote with line breaks, a horizontal rule splitting a numbered
list with its numbering continued, adjacent equal links; and what it means for an
app), edits made by code (agents and tools: edit text in place, apply an
edit to the state it was computed from and merge), servers (old clients,
yrs before 0.28), limits, and upgrading from
`@lexical/yjs` (no in-place migration yet). `LexicalWarning` is documented
under "Errors and warnings" in Defining Extensions. The package README is
short (install, a minimal example, links to the pages and the API reference,
how to run the long fuzz and replay a seed) and holds the frozen wire
format. `DEFER_COMPOSITION_MERGE_TAG` is listed under
Updates > Common Update Tags. A scripted session of 10,000 edits (fixed
peer ids, gc off) grows the document by about 230 KB (230,394 bytes;
217,143 before the word snap of an earlier revision), against 2.8 MB with
the default `@lexical/yjs` layout (a historical comparison, not measured
again).
`@y/y` is a peer and dev dependency pinned exactly to 14.0.0-rc.29 (npm's
`latest` tag points at an older release candidate). rc.29 is past the
repository's 7-day minimum release age; the lockfile resolves `@y/y@14.0.0-rc.29`
(integrity `sha512-A4W9Bnrf…`) and nothing else. The cursor equivalence test
passes on it.
Core (`lexical`): four generic pieces, and nothing about collaboration
(no collaboration vocabulary, API or behaviour; `@lexical/y` keeps its own
codes and checks):
- `LexicalWarning` (above).
- A new update tag, `DEFER_COMPOSITION_MERGE_TAG` (`'defer-composition-merge'`,
exported from `lexical` next to the other tags, documented in Updates >
Common Update Tags). While an IME composition is active, an update carrying
it does not merge text into or out of the composed text node: a merge
rewrites the composed DOM text node, and the browser's composition range
would take in the merged text. Once such a merge was held back, later steps
of the same composition hold it back too (a private `_compositionMergeHeld`
key, cleared whenever the composition key changes); the nodes merge when
the composition ends. It is for any update that changes text next to a
composition without user input (changes applied from another source);
`@lexical/y` adds it to the updates that apply a remote change. Without it
normalization ignores the composition, so every other update, including
one tagged `COLLABORATION_TAG` or `SKIP_COLLAB_TAG`, merges exactly as
before: `LexicalNormalizationComposition.test.ts` runs 112 scenarios (7
operations next to the composed node × 8 tags, including
`COLLABORATION_TAG`, × with and without `skipTransforms`) composing and not
composing and requires identical JSON and node identities, and
`SyncCompositionUnchanged.test.ts` (`@lexical/yjs`) drives v1 and v2
bindings (8 scenarios × 2 client id orders each) with a composition in
progress and compares every step with traces recorded on main. A hold
keyed on `COLLABORATION_TAG`, as an earlier revision of this PR had, fails
2 of them (v1). Checked that `@lexical/y` still needs it: without the tag,
6 of the 21 tests in its main composition block fail (a peer joins the
lines while composing).
- An internal record of text splits, `EditorState#_splitNodes`
(`@internal`, beside `_movedNodes`, and kept like it, by the previous
node map): while an editor records moves (`_recordNodeMoves`, which the
Yjs bindings set), `TextNode#splitText` records, for each new part, the
node it was split from and where in that node's text it starts (a part
of a part counts from the node first cut). Nothing is recorded otherwise,
and nothing reads it but `@lexical/y`, which keeps the characters of a
part split off a node an update deletes (see the range deletes through
`extract()` below). `LexicalTextSplitRecord.test.ts` covers it.
- An internal record of text edits, `EditorState#_textEdits` (`@internal`,
kept like `_splitNodes`): while an editor records moves, every change of
a text node's text, in order, with the node's text before it:
`TextNode#spliceText` with its offset, what it deleted and what it
inserted (the selection's text insertion goes through it); the
selection's text removal, which still calls `setTextContent` (so a
subclass's override runs) and says which splice it makes; a split, with
where each part starts; a merge; the text Lexical types into a node it
makes for it (typing in another format); a node the selection removes
with what it holds (a range that covers it, typing over a token), as
deleted; any other `setTextContent`, with the node's text before and
after; and every node inserted into or removed from an element's
children, where (its parent and its siblings there, and a text node's
text then), so that a node swapped for another (a transform's `replace`,
`$wrapNodeInElement`, an insert and a remove) is seen where it was: the
three places that link and unlink children (`$insertNodeBetween`,
`$detachNode`, `$detachSiblingRange`) push the entry. Lexical makes the
same calls with and without it, and an editor that does not record moves
pays one flag check per call (`LexicalTextEditRecord.test.ts` compares the states; a typing
and editing bench shows no difference from the base tree). Nothing reads
it but `@lexical/y` (see the exact text edits below).
Block ids: `@lexical/y` works with `BlockIdExtension` (#9421, on main),
which gives every new block an id stored as NodeState:
- The blocks a remote change brings without a unique id are named by the
reader, and nothing is written. Every block shows the first id of its own
list that no block before it (in document order) shows: the id it stores,
then the id derived from its own Yjs identity (`y`, a client, `_`, a
clock, in base 36: a line's marker, a line without a marker's first
character (with `_l` when that is a node stored in the line, which
derives its own id from it), and so the first character of text a read
shows in a paragraph of its own inside a quote that holds paragraphs,
a stored node's item, in a container or
inside a line (a list stored as a node, inside a line: its item, with
`_g`); another list's first item, with `_g` and its level
below the top, `_g1`, `_g2`; a wrapper item's first nested item,
with `_w`, `_w1`, `_w2`, so lists and wrappers nested at the start of a
list differ), then that id followed by `_d`s. So a block that stores no
id, or an id an earlier block also stores or shows (a copy of the JSON of
a block as a reader showed it, whatever id it showed), shows its derived
id; a block that derives an id competes for it with the blocks that store
it whether or not it stores one itself. Each block's id depends only on
blocks before it, so every client with `BlockIdExtension` and every
fresh reader with the same configuration shows the same (a client
settles the ids each change touched: those of the blocks it added,
removed, moved or gave another id); the author's next edit of that block
stores it. `BlockIdExtension` then
has nothing to name after a read (except blocks inside named slots,
below, and the rare nested quote in Known open issues); its
naming update, when one still follows a commit, is a follow-up, which may
set attributes or delete, never insert (see Write path). Clients without
`BlockIdExtension` show only stored ids. Mixed configurations (some
clients that write without `BlockIdExtension`, or with another
`$isIdentifiedBlock`) are supported but discouraged: each client shows
what a fresh reader of its own configuration shows, and the document is
the same for all, but the ids differ between configurations. A client
without the extension shows no id on a block written without one (where
the others show its derived id), keeps the id of a block it copies (two
blocks then store one id: it shows it twice, the others on the first in
document order and a derived id on the second), and shows an id stored on
a list that is not an identified block (a list moved or pasted into a
table cell), where the others show none. Any other block that is not an
identified block where it sits (a box or table pasted into a table cell)
keeps its stored id on every client, so a copy pasted there shows the
original's id on both blocks for every configuration (documented in
Block IDs and y.md). `BlockIdExtension`
gains an option, `repairTransforms` (default `true`, unchanged): with
`false`, the follow-up sets the ids without running transforms and changes
nothing else. `YCollabExtension` sets it through a peer dependency
(`declarePeerDependency('@lexical/extension/BlockId',
{repairTransforms: false})`), so an app that adds both extensions gets it.
With `true` (an editor that uses `YBinding` directly without setting it,
or an app that sets it, which overrides `YCollabExtension`), the naming
update would also run the editor's transforms over what a remote change
brought, and what they derive (the start of a list they split) can differ
between clients: in the previous revision 3 of 100 randomized
normalization sessions ended with clients showing different content. So
the binding fails closed: with `true` it writes nothing (the initial
content neither), is read only, and warns `'@lexical/y/unsupported-config'`
(`UNSUPPORTED_CONFIG_WARNING`, `data: {options}`).
One other `BlockIdExtension` change, in every editor: a copy of a block
created where it is not an identified block (a list pasted into a nested
list item, where it nests) keeps no id, so the block it was copied from
stays the only holder of its id (before, the nested copy kept it). Its
existing tests are unchanged.
- A line that concurrent edits leave without its marker (text typed into a
paragraph a peer removed, read as a paragraph) has no stored id. Its
positional id would cover the whole document, so clients holding
different concurrent edits derived different ids, and with follow-ups
limited to attributes they could not converge. The reader derives it
instead, from Yjs identity: `y`, the client of the line's first character's
item, `_` and that item's clock (base 36), with `_l` when that item is a
node stored in the line (an inline node, or a block decorator written
without the normalization, which derives its own id from that item), set
as the block's
NodeState when `BlockIdExtension` is registered and the line is a block
it names. Every client and a fresh reader derive the same id from the
same document, whatever order they saw changes in; the edit that next
changes the line stores it with the marker it writes, so the id does not
change. An update that sets another id on the line writes it the same
way, as any change of the line's attributes.
No storage, no follow-up write; part of layout 1 (unreleased). A read
that recovers by rebuilding the editor keeps it.
- Initial content: two clients that initialize a new document with the same
content write the same bytes with `BlockIdExtension` too (both id orders,
with and without text, with a different `generateId` per client): the
extension names a document's first content positionally, so the ids are
the same before the content is hashed (see Data model). The hash covers
the exact bytes the client writes, with its own block id configuration,
which changes them (a nested list's id is stored where nested lists are
not identified blocks): two clients whose configurations differ write
their content twice, never different items under one id.
Changes in this revision (each with a regression test that fails on the
previous revision, unless noted):
- An app's own `blockId` NodeState works without `BlockIdExtension`: where
the editor has no `BlockIdExtension`, the binding never reads or sets
`blockIdState`, so a stored `blockId` key is NodeState like any other, on
lists (whose state their items carry) too. Before, the binding's
transform on lists and its read of a list's id used `@lexical/extension`'s
StateConfig whether or not the extension was registered; Lexical allows
one StateConfig per key on a node class, so an app with its own `blockId`
state (a production app's block id extension) threw `State key collision
"blockId"` on every update that read a list (`AppBlockIdState`: an
author, a peer and a fresh reader show the app's ids, nested lists
included, through edits of those lists; 2 new tests failed). Without the
extension, a nested list whose id equals its parent list's keeps it (the
writer, the reader and the transform no longer drop it): it is the app's
state.
- A shadow root inside a named slot holds its inline children in a
paragraph on the author too: the binding wraps them, as core's shadow
root transform does. The binding enforces node structure, which turns
that transform off, and the normalization starts from the root, so it
never reached a named slot. Before, the `> ` shortcut in a slot (a
production app's details body) left the author with text directly in a
shadow-root quote, where every reader shows a paragraph (the text is
stored as a line without a marker), and apps that read the tree threw
(`Children of root nodes must be elements or decorators`)
(`ShadowRootQuote`: the shortcut with an app transform, and a quote that
takes the paragraph's text while a peer types in it, in both id orders;
4 new tests failed).
- A block decorator in a quote that holds paragraphs (a shadow root)
stays a child of the quote on every reader, as on its author: a read
wraps only inline content there in a paragraph. Before, every
reader showed an image, or a component holding a named slot, inside a
paragraph of its own (`BlockDecoratorContainers`: widgets and a component
put into the root, a cell, a slot's body, a quote and a quote in a cell;
the 4 quote cases failed).
- A read keeps the selection valid while it moves nodes: a point in a text
node it reuses for shorter text goes to the node's end, and where Lexical
throws on a point that the read left invalid (detached in a subtree the
read took apart, gone, or past its node's end) when it removes or moves a
node, that point goes to the other one and the change runs again. The
selection put back afterwards still comes from relative positions;
putting it back never fails the read, and a read that fails clears the
selection, so that the update an undo or redo runs in still commits.
Before, select all over a block decorator, type, undo and redo failed
the redo's read (`$getTextNodeOffset: invalid offset 17 for size 2`), and
Enter over a backward range from a heading, undo and redo, failed it too
(`no common ancestor`, then `selection has been lost`): the editor was
rebuilt, showing text the redo had deleted until the rebuild ran, or the
redo changed nothing (`UndoSelection`: both cases, both undo paths, both
capture timeouts, and a cursor that cannot be put back; 7 new tests
failed).
- A custom text class's flat StateConfig survives the splits Lexical makes:
a line feed's line break gets all of the part's NodeState, flat keys
included, and a plain text node a split made from such a node (it keeps
the class's state configuration, so its JSON has the key flat, where a
plain text node read from JSON ignores it) has the key
stored as NodeState, which every reader keeps; its author reads the line
back, so it shows the same JSON. Before, the line break lost the value
everywhere, and the plain parts lost it on every reader (R11-B F-02;
`FlatTextState`: line feeds in normal, token and segmented nodes, and a
part split off by formatting; 10 new tests failed).
- Two mergeable text nodes that store the same attributes are one run on
the author once a composition between them ends, as on every reader: the
keystroke path leaves an edit whose text node now runs with the node next
to it to the general write, which reads the author back. Before, the edit
that ends the composition went through the keystroke path, which skipped
that check (R11-B F-03; `Composition`: equal object NodeState parsed
apart, both id orders; 2 new tests failed).
- Initialization puts a node selection back by the Yjs identity of its
nodes, never by position: a node's item, a line's marker, a text node's
first character, and for any other node (a list, a list item holding a
nested list, a link) the first of those inside it. The read shows a line
feed as a line break node, which moved the later nodes along, so a node
selection on an inline decorator after a raw line feed (a state set
whole) selected its neighbour, which Delete then removed; a selected node
inside a named slot was dropped (R11-B F-05 and F-01; `Init`: pristine
and used roots, a line feed at the end and in the middle, and a node in
a slot; 6 new tests failed). A selected list, nested list's item, link
or text node, also after a line feed, is kept, and Delete removes what
it removes without the binding (`InitNodeSelectionKinds`, 14 new tests,
which the previous revision passes by position, and which an identity
restore that took only nodes with an item of their own failed 10 of:
R12B-S1).
- After deleting block nodes, the writer diffs what follows from the formats
in effect where the diff starts. Before, deleting a block node and the
line after it took the formats in effect after the block node, so a
format opener that the lines after relied on (a stored run left across a
block node and a marker by concurrent edits: a comment over a callout)
looked redundant and was deleted: every reader lost the comment, or the
bold, on those lines, and the author kept it; where the deleted range
held a closer, a resolved comment came back over the rest of the
document. Replaying the 61 whole-block deletions captured in a soak's 6
sessions, 39 changed blocks the deletion never touched on readers
(comments lost or gained over 1 to 234 blocks, text turning bold or
italic or losing it, once text appearing in a paragraph); now none does,
on the author, a peer or a fresh reader (soak S3-6; `DeletedBlockFormats`:
2 new tests failed).
- Deleting a unit gives the unit after it the deleted unit's start
formats, as it now starts where the deleted one started, so every delete
and diff after deleted units starts from the formats in effect there: one
rule for every unit delete, which the diff above now uses too. Before, a
follow-up's delete (an app's deletion that Lexical merges into
BlockIdExtension's naming commit) of a block node and the line after it,
or its write of a line it emptied after a deleted block node, deleted a
format opener that the content after relied on: every reader lost the
bold there (R12B-C1; `DeletedBlockFormats`: the same deletions in a
follow-up, and a line emptied after the block node in an edit and in a
follow-up, 6 new tests failed; `NamingCommitDeletes`: the deletion merged
into the naming commit, and into an ordinary commit, 4 new tests
failed).
- A remote read maps a caret in a line without a marker that a block node
follows to that line. Before, a caret in text whose line a peer's undo
left without its marker, before a table, went to the end of the line
before, so the next keystrokes landed in another block (soak S3-5;
`RemovedLineCaret`: 1 new test failed, the paragraph control passed).
- The development self-check builds its scratch editor with
`LexicalBuilder` where the bound editor was built so: a node whose
constructor builds a nested editor with `NestedEditorExtension` (the
playground's image caption) threw there, so every self-checked write in a
document holding one warned (soak S3-1; `SelfCheckBuilder`: 1 new test
failed).
- The self-check compares a segment key only where the editor holds the
text in a node that keeps it (a token, segmented or unmergeable node, a
code highlight): a reader keeps a mergeable text node apart only by its
type, mode or detail. Before, a segment key opener that an undo put back
over later lines made 45 of 73 lines of a soak room warn `format k at 0`
on every write; that state now warns on 1 line (see Known open issues)
(`CodeHighlightSelfCheck`: 1 new test failed).
- A change that only touches formats or marks is written as format items,
never as a delete and a re-insert of the text it touches. Lexical's
normalization merges text that no longer differs from its neighbours
into the text node before it; the writer now finds such a merge exactly
(the node's own old text followed by the old texts of the nodes the
normalization merged into it, as the update's own record of them,
`normalizedNodes`, names them, the last one possibly cut where Lexical
split it; a node the update removed without merging it was deleted,
whatever its text), so every character keeps its item. Before, it gave the merged
text to that node whenever the node's own old text happened to end like
it, or when the merged node had been split first: resolving a comment
whose words were followed by a space and a formatted run (`…redanox
[redanux redapax redapex](c1) **redapix…**`), removing bold, italic,
code or a link there, or giving the start of a node the format of the
run before it, deleted the words and inserted them again (64 B against
14 B). Two clients resolving at once showed them twice, a word a peer
deleted meanwhile came back, and text a peer typed right after them
could move in front of them (soak S3-8, from agents' and people's
resolves; `FormatOnlyChanges`: comments, bold, italic, code and links,
added and removed, next to a bold, plain, link or code run, at the
start, middle and end of a line, and in a list item, a table cell, a
collapsible's title and an update that also adds a paragraph, alone and
while a peer makes the same change, deletes one of the words or types
after them; 118 of 576 new tests failed: removals next to a formatted
run in the middle of a line, in every one of those places, and the
first word of a node joining the run before it). A node deleted in the
same update whose text equals the text merged after it (`same ` deleted
and the next `same ` unformatted; `la ` | **`la `** | `la `, the bold one
deleted) is never taken for the merged one, so a peer's concurrent
delete of the merged text, or typing in front of it, stays where it was
made (R13B-C1, R13-A D1; `FormatOnlyChanges`: a run deleted next to an
equal run merged in the same update, by a format, a resolved comment, a
split and three runs, while a peer deletes or types at the start of the
merged run or deletes in the deleted one, both id orders, 10 of 48 new
tests failed; `EqualTextDeletes`: 2 of 6 new tests failed, the
deletions with the caret at the join, which took the first of two
equal removed texts). A range delete across text nodes that Lexical
then merges (`t6z ` | *`t7z `* | `t8z `, `t7z t8` deleted, `t6z ` and
`z ` merged; in a link too) is written as that delete only: the node
keeps a part its old text starts with, the first node merged into it a
part its old text ends with, and the nodes merged after that their
whole texts, where one split of the text fits, or, of several, the one
at the caret the delete leaves at the join. Before, it was written as a
replacement of the merged text, or deleted an equal run of another
node, so a peer's concurrent delete there came back and its typing
moved (soak S4-1: 214 of 600 random range deletes over 3 or 4 text
nodes were written wrong; `LinkMergeDeletes`: in a link and outside
one, equal and other letters, a peer deleting or typing, both id
orders, and those 600 deletes; 5 of 17 new tests failed).
- The same deletes made by app code through `extract()`, the extracted
nodes then removed with no caret left, are written as those deletes too
(`extract()` splits `t8z ` into `t8` and a new `z `, the app removes
`t7z ` and `t8`, and Lexical merges `z ` into `t6z `). With Lexical's
record of its splits (see Core), a part split off a node the update
deleted keeps that node's characters: merged into another node, after
the node's own kept prefix and before the whole texts of nodes merged
after it, or left on its own. Before, the part had no old text of its
own: the write deleted `t7z t8z ` and inserted `z `, or kept an equal
run of another node, and a peer's concurrent delete or typing there was
undone or moved (soak A4 S4-1 through `extract()`: 20 of 32 cases, 225
of 600 random deletes written wrong; `LinkMergeDeletes`: those cases, at
a link's and a line's end, and 600 random deletes through `extract()`;
21 of 33 new tests failed).
- The merge record spans every update a commit batches (two
`editor.update()` calls in one task, or a text transform that edits after
the normalization merged): a node merged in one update and deleted again
in a later one is still in it. The writer takes a split of a merged
node's text only at the caret a range delete leaves at the join, or,
without a caret, where the node's own old text does not explain what is
left, and takes the exact merge only when every node the record merged
into it is in its text. Before, `x ` | **`la `** unbolded and then `la `
deleted kept the deleted node's space and deleted `x `'s, and a delete
that let an equal `la ` merge in kept the deleted node's `la ` and
deleted the survivor (R14-A F1, data loss under a peer's concurrent edit,
from this revision's merge detection by Lexical's record;
`BatchedMergeDeletes`: 2 shapes, the delete by a caret range or node
edits, one commit or two, 4 peer edits, both id orders, and the same by
a text transform; 6 of 72 new tests failed on the previous revision, 24
with that merge detection before this fix).
- The paragraph a read shows around text that lands directly in a quote
that holds paragraphs (typed into a paragraph a collaborator moved into
the quote) gets the block id derived from that text's first character,
as a line without a marker does, settled with the other derived ids, so
`BlockIdExtension` has nothing to name there. Before, the reader gave
that paragraph no id; `BlockIdExtension` named it from each client's
document of the moment, and its naming update, a follow-up that changes
the quote, was not written: clients kept different ids that no one
stored, a fresh reader showed yet another, and the self-check warned on
every read (R12-A B1: 19 to 40 of 300 to 400 sessions per lane in its
lanes with such quotes). A quote in a table cell that comes to hold
paragraphs (no identified block there) now shows no id on a client that
reads that change in place, as on a fresh reader: a line read in place
decides whether it keeps its derived id once its new attributes are
applied (it kept the one it had as a quote that held text). And a
follow-up records no storage kinds: it inserts nothing, so it writes no
type for the first time, and a client that only applied a change wrote
`k:quote` before the record of the change's author arrived
(`ShadowRootQuoteIds`: two and three clients, the paragraph moved into
or replaced by the quote while a peer types, one derived id everywhere,
nothing written on apply, kept by the next local edit there; a stored
copy of that id before and after the quote; the cell's quote read in
place; 27 new tests failed).
- The re-read after a refused follow-up shows a quote that holds text
without a paragraph as a fresh read does. Before, the read took a line of
another container that the refused follow-up had moved into the quote
(the next root paragraph, put first in the quote) for the paragraph it
shows around that text; the line went back to the root, and the text was
gone from its author's editor for good while every peer and fresh reader
showed it (soak A4 S4-4; `QuoteRunReread`: the text before or after the
quote's paragraph, then nothing or an edit elsewhere, each comparing the
re-read with a fresh read; 4 of 4 new tests failed).
- After that race the typist's caret stays in the text it typed: a remote
read resolves a position in a line that holds blocks into the paragraph
that shows it, and a caret a read leaves on such a line goes into the
nearest block. Before, it landed on the quote after its last block, so
the next keystroke started a new paragraph (R12-A S1;
`ShadowRootQuoteIds`: both id orders, moved and replaced, typed into an
empty paragraph or into text, 8 new tests failed).
- A line feed in text set whole shows as a line break node on its author,
as on every reader. A state taken from another editor
(`setEditorState(other.getEditorState())`) marks only its root dirty and
runs only the root's transforms, so the author's normalization now takes
the text nodes Lexical did not mark dirty too; and initial content
written into a used root is read back in every container, a table
cell's included. Before, the author kept `a\nb` in one text node there
(R12-A N3; `AdoptedStateNewlines`: 10 shapes, initialized into a
pristine or used root, with and without a node selection, set from
another editor and parsed while bound; 12 of 60 new tests failed: every
shape set from another editor while bound, and the table cell
initialized into a used root).
- An undefined entry in an array property (a table's `colWidths` after a
column is inserted past the stored widths) is stored with `null` there,
which every reader parses as the class does (`TableNode`: `0`, as its
own JSON round trip gives); the author's normalization now gives its
node that value too, and writes it. Before, the author kept
`[92,92,null,null]` in its JSON against `[92,92,0,0]` on every reader,
for good (soak S3-10; `ColWidthHoles`: holes, and a column inserted past
the widths, alone and while a peer types in a cell; 4 new tests failed).
- Text left without a marker before a block node (a join while a
collaborator puts a widget between the two lines) survives an update
that deletes the block node and the line after it: that text is given a
marker in that write unless nothing followed it before the update
either, and a follow-up's delete of the line after the block node starts
after that text. A follow-up that deletes only the block node is not
written (readers would show that text joined to the next line, which
only a marker, an insert, keeps apart), and its author reads the
document again. Before, the edit was written from the container's start
and deleted the title and that text for every reader while the author
still showed them, and the follow-up deleted that text too (R13-A P1,
data loss; `ImplicitLineDeletes`: by either client, in an edit and in a
follow-up; 6 of 8 new tests failed).
- A line without a marker that a follow-up deletes after a block node it
also deletes is deleted from its own first item, right after the block
node's item: when no line around the block node has a marker (`Title`
[widget] ` XX`, which three clients' concurrent edits leave; or `Head` ¶
`before` [widget] `after`, in the root or a callout), there is no end
item before it to start from. Before, that delete started at the
container's start or after `Head`, and deleted `Title` or `before` too:
every reader and fresh reader showed an empty document, or lost
`before`, while the author kept it (soak A4 S4-3, data loss;
`NoMarkerDeletes`: three clients, each making the follow-up; a table and
a widget with no marker around them; the root and a callout, deleting
the widget with the line after it, before it, both or neither; in an
edit and in a follow-up; 16 of 26 new tests failed).
- A follow-up's change of the content of a line without a marker (left by
concurrent edits anywhere: after a block node at the end of a container,
before a widget, as the last line of a callout or a table cell) is not
written, and its author reads the document again: only a marker, an
insert, could keep the line as the author shows it. Before, emptying the
line, typing in it, deleting from it, or deleting the block node before
it and emptying it was neither written nor refused: the author showed
the change, every peer and fresh reader kept the old text, and no
warning said so (soak A4 S4-2; `ImplicitLineFollowUps`: a quote and a
widget before the line at the end of the root, a widget after it, in an
edit and in a follow-up; 10 of 30 new tests failed).
- A follow-up's change of a field that only a structure write (an insert)
could store is read again: the text format or style of an element that
is not a line (a wrapper list item, a nested list, a callout), which a
follow-up does not write, and the format, indent or direction of a line
without a marker or of the paragraph a read shows around text left
directly in a quote, which keep them nowhere (a read now gives that
paragraph what a fresh read does). Before, those were neither written
nor read again: the author kept them while every reader showed the
stored ones (soak A4 S4-5; `FollowUpTextFields`: set directly, and by
formatting from the end of an item into its nested list, in an edit and
in a follow-up; 11 of 30 new tests failed).
- After a follow-up is written (BlockIdExtension's naming update), the
binding compares each container it touched with what a fresh reader
shows for the document there, and reads that container again where they
differ, as for a change the writer refuses. Only the part holding the
top-level children the follow-up changed and their neighbours is read,
by the reader itself, into an editor of its own; left out are fields
every client derives itself (list numbering, the text format and style a
client's reconciler derives under text), fields no update stores (a
link's own alignment, indent and direction, a list's own indent) and
block ids settled across the document. It is skipped while a composition
holds back remote text and while the author's normalization of an
update without transforms is pending (the editor differs there on
purpose). Before, each shape the follow-up rules missed (a line without
a marker, a field stored nowhere, a paragraph a read made) left its
author showing a change no peer or fresh reader had, with no warning
(soak A4 S4-2, S4-4, S4-5; R15-A 2: a follow-up's NodeState on a line
without a marker or on a quote's run paragraph, `ImplicitStateFollowUps`
2 of 24 new tests failed; a follow-up that indents a list's first item
into the next item's nested list, `ListIndentFollowUps`: the author kept
the nested list's textFormat 18 against 16 on every reader, 1 of 20
failed; `FollowUpFuzz`: random follow-ups over every node kind and
field, in lines without a marker, a quote's raw run, list wrappers,
cells and a callout, the author equal to a fresh read after each and
every peer after the exchange, 19 of 120 sessions failed). With a
follow-up after every keystroke in a 10,000-block document, the check
costs about 1 ms per follow-up (a few blocks read), against 11 to 13 ms
for the follow-up's update itself (`FollowUpCheckCost`).
- An element's text format and style are stored where no text is below
it (an empty line, list item or cell paragraph, one holding only inline
decorators or line breaks), and a follow-up writes them there as every
update does: a follow-up that sets them, or that empties the element
(Lexical sets them from the text removed). Where text is below the
element, Lexical's reconciler derives them on each client that renders
it: a follow-up's change of them is not written and its container is
read again (a paragraph holding only a link included, which Lexical
serializes them for). Before, a follow-up wrote them nowhere and refused
nothing: the author kept them while every reader showed the stored ones
(soak A4 S4-5's residual; `FollowUpEmptyFields`: a root line, a cell, a
callout and a quote paragraph, a paragraph holding only a link or an
inline decorator, text and a link, an empty list item, each field, in an
edit and in a follow-up; 14 of 100 new tests failed).
- A read again gives the paragraph a read shows around text in a quote
what a fresh read gives it, its text format and style and NodeState
included (its block id is derived again). Before, a refused follow-up's
text format or style of such a paragraph holding no text stayed on its
author (R15-B F2; `RunParagraphFollowUps`: a line break or an inline
equation alone in it; 4 of 4 new tests failed).
- A format-only update made of several formatText calls on one line is
written as format items alone. When a line's text is its old text, cut
and joined again by the update's splits and merges alone (each text node
holding it is an old node of the line or a part Lexical split off one,
and starts where its text did; every old node no longer shown was merged
by the normalization), each character keeps the item at its own place.
Before, a node merged after a split was taken for an equal run of
another node, and the words were deleted and inserted again (`<u>ab` |
`<i>la ` | `la la `, italic over [3,9) and underline over [7,8):
`del "abla " ins "abla "`), which undid a peer's concurrent delete there
or moved its typing (soak A4 S4-6; `FormatCallsRewrite`: 4 of 4 new
tests failed; `FormatCallsScan`: of 800 random updates of one to three
calls, 20 rewrote words, 0 now).
- Typing at the start of a commented run after an equal word writes the
typed text alone. MarkStateExtension cuts the typed text off the comment
and it joins the word before; the rest of the run is a part split off
it, which holds its whole old text and now keeps those characters before
any node claims them. Before, the word before claimed the start of the
removed text it begins with: `del "da" ins "da t30z"` for `t30z ` typed
(soak A4 S4-7; `TypeAtMarkStart`: 1 of 5 new tests failed, the equal
word).
- The attribution of a split tail merged into the node before it (the
range deletes through `extract()` below) declines where a node the merge
record holds after it is not in the text (merged and deleted again in a
later update of the same commit, or by a transform), where it would keep
only part of the node's own old text that Lexical did not cut there, and
where the node's own old text explains all that is left and a caret in
it is elsewhere than at the join; the other attributions decide then, as
before that change. Before, it found the tail in an equal neighbour
merged in later, or in the node's own equal characters, and kept the
deleted tail's items and deleted a survivor's (R15-A 1, R15-B F1: data
loss with a peer's concurrent edit; `SplitTailMergeDeletes`: R15-A's
shapes T2 and T3, by node edits or a caret range, in one commit, two
commits or a transform, 24 of 72 new tests failed, all in one commit or a
transform; `SplitTailCaretDeletes`: R15-B's, 4 of 4 failed). R14-B's
merged run that an app transform removes (R14B-C1) holds (12 of 12, as
before this change).
- The writer writes the text edits Lexical records (Core, above) where
they were made, whether or not a caret is left in the text: an insert or
a delete next to equal text keeps every other character, and a
replacement made through them is written as made, not widened to whole
words. The record is replayed over the previous state into each text
node's lineage (which characters are which old characters, and which are
new), used only where it covers every change of the node (its text then
equals what the lineage gives). A node's text set whole
(`setTextContent`, a change the browser makes to the DOM text, as an IME
composition does) is diffed within that node, anchored at the caret and
in whole words, as before (see the next change for what it no longer
touches); a node made with its text (typed in another format, inserted
by app code) is new text (see the next change for a node made again). A
line's write keeps the old characters the record keeps between its
edits (several edits in one update, a split tail left between deleted
runs) rather than writing one hunk around them. Before, the writer
diffed the old and new text,
anchored by the caret, so an edit made without one (an agent's or app
code's edit, typing in an update that then clears or moves the
selection or makes another edit) was written shifted next to equal
text: `t5z ` typed before `t4z ` was written as `5z t` after the `t` of
`t4z`, and with a peer's concurrent delete of `z t4z` every client ended
on `t35z t `, the typed word's `t` gone (soak A4 S4-9; `ExactTextEdits`:
3 of its 4 shapes failed (with the caret kept it passed), and 129 of 300
seeded inserts and deletes next to equal text, one or two in an update,
through the selection or `spliceText`, each checked character by
character against the shared items, were written otherwise than made).
It also writes exactly what the diff guessed at: range deletes with the
selection cleared (soak S4-1's scan: 102 of 600 deleted an equal run of
the right length elsewhere, 0 of 3,000 now; `LinkMergeDeletes` runs its
600 with the selection cleared too), the equal-run cases of
`BatchedMergeDeletes` (now asserted exactly: 12 of 72 failed) and of
R14-A's batched merges, R15-A's split tail left between deleted runs
(T1) and deleted again by node edits in a second commit (T2;
`SplitTailMergeDeletes` now asserts both: 24 of 120 failed), R16-A's
delete-and-retype cases (4 of 8 failed), several edits in one update
(soak S3-4's scan: 113 of 400 written otherwise, 8 now, each a delete
of text typed earlier in the same update, which the scan counts as
deleted), typing in another format twice in one update (171 of 400, 0
now), and typing over a
selection, which Lexical types into a node it makes, cuts into the text
and merges back: "abcdef" with `c` selected and `X` typed, the caret
kept, was written `del "abcdef" ins "abXdef"`, so a peer's concurrent
delete of `a` came back and its typing landed at the start of the text
(soak A5 S5-1; `TypeOverSelection`: 902 of 1,176 type-overs at every
position of four lines (formatted neighbours, comments), selections of
0 to 5 characters, a new letter or text equal to its neighbour, the
caret kept or cleared, were written otherwise than made, and the peer's
delete came back); "the quick brown fox", `x` typed over `ick bro` ‖
bolding `quick` now gives **`qu`**`xwn fox` (it lost the bold).
- A part Lexical split off a node keeps that node's characters by the
record of text edits, not by equal text: the rule of soak S4-7 above (a
part holding a removed node's whole old text keeps its characters) now
applies only to a part the record does not cover. Before (the previous
revision's last change), a part whose text only equalled the node's old
text took them: typing `ab` at the end of a bold `ab` and unbolding the
original half, which merges into the text before it, gave the typed
`ab` the original characters' items, so a peer's concurrent delete of an
original character deleted the typed one instead, and its typing
between them landed inside the typed text (R16A-1, data loss;
`SplitPartReserve`: in one commit, one update or an app transform, a
peer deleting an original character or typing between them, 12 of 32
new tests failed; two commits are a control).
- Several edits in one update, as agents and app code make them, are each
written where they were made, and nodes the update makes are new where
they are put. Before, each of these was written as a rewrite, which
undid a peer's concurrent delete of an untouched character or moved its
typing (every case below fails on the previous revision):
- A text node made next to an edited one, with its format, which Lexical
merges into it: "abcdef" with `X` spliced at 2 and a node `Y` made
after it was written `del "abcdef" ins "abXcdefY"` (soak A5 S5-2; also
with the node made first, and with caret typing). The same with the
caret then put inside the made text, as a snippet insert does (the new
text was written shifted into the equal text before it, S5-5), and a
paste over a selection, plain or rich, whose text Lexical makes as
nodes (R17A-2: written as whole words replaced, as the docs said it
no longer was).
- Edits on either side of a line break or an inline node: `abc` | line
break | `def` with `X` spliced into `abc` and `Y` into `def` was
written `del "abc\ndef" ins "aXbc\ndYef"`, the break included, and an
inline node between them was deleted and made again (S5-3, the S3-4
residual). A line break or an inline node of the line before keeps its
item, and one made in the update is new where it is: a line break
typed or inserted right before another was matched with the old one
and written after it, so a peer's typing after the old break was left
alone on the new line (S5-4, 12 of 24 failed, every one where the
author had the higher client id). Where the record does not say what
some atoms are, the atoms it keeps stay and only the gaps between
them are diffed, each on its own; a whole-word widening never passes
an atom the record keeps.
- A node set whole by `setTextContent` had no lineage, and nor had a
node it merged with, so that node's untouched characters were diffed
with it and written again (`ab` | line break | `a X`, the second set to
`a ` and the break removed, rewrote `ab`). The record now holds the
set's text before and after, and its lineage keeps the prefix and
suffix they share in whole words, the rest replaced: the change stays
in that node. Keeping part of a word is not safe (two replacements of
one word at once would interleave), so a replacement inside one word
is still written as the whole word replaced (documented).
- A node removed by app code and another made in one update (an agent
replacing a word) had the new text take equal characters of the
removed one, as if made again. Now text made where the line's text
changed is new (the next change places text by where it is), and a
node the selection removes with its text is recorded as deleted, not
as a node that left.
`CompoundTextEdits` checks it: seeded updates of 2 to 4 operations
(splice, typing, typing over a range, `setTextContent`, a node made
before or after of the same or another format, a line break or an
inline node made, a node removed, a range formatted, a split, a range
extracted and removed, a range deleted, the caret set or cleared) on one
or two adjacent text nodes, with line breaks and inline nodes between
and beside them, equal ones side by side too, and every character's
provenance modelled: the write must keep every character the update
kept, by its Yjs item, and a peer's concurrent delete of a kept
character must stay deleted. On the previous revision 131 of 525 seeded
updates were written otherwise (1,301 of 5,271 with 6,000 seeds); now 0
(0 of 5,271, and 0 of 17,617 with 20,000 seeds). What it allows is what
the record cannot place exactly: text set whole, and the text or line
break of a made node, may keep characters of text that left the line
otherwise than by a delete (a text set whole, a node removed or
extracted and removed; the next change places it by where it is).
`MadeNodeEdits` (16 tests, 14 failed) holds the shapes above.
- Which characters a line kept follows where they are in the line, not
which node holds them: in storage a node's type, format, link and
segment key are attributes of its characters, so nodes swapped without
changing the line's text change attributes, never text. The record of
node insertions and removals (Core) is replayed with the text edits over
the previous state, each text node's characters as runs of old
characters, typed text (new where it was typed) and text that arrived
otherwise (a node made, a text set whole), and what a node removed from
a line held is kept where it was removed. Each line is then resolved
once: the old characters still in place, in order, are kept (they pin
the line), and in each stretch between them the text that left (a
removed node's, the text a set replaced) and the text that arrived (a
text set, a node made) are aligned by the diff a write makes without the
record, their common start and end in whole words, anchored at the caret
where it is in text that was there before: first all that arrived, of
which set text keeps what it is aligned with; then set text still new,
with what is left between what is kept; then the text of nodes made. A
removed node's text is aligned whole or not at all; typed text and the
characters an exact edit deleted are new and gone where they are, outside
the alignment; the rest is deleted and inserted.
A node made with exactly the text that the nodes
removed right around it held holds those characters from then on, so
what the update does to it next (typing into it, making it again, a
merge) keeps them. Where the record does not explain a line's text (an
unrecorded change, an entry the binding does not know), the line is
diffed as before the record. This replaces the previous revisions'
per-node rules: text a set only inserts taken for text moved out of a
sibling, a node made with exactly the text of one node that left taken
for it made again (`remakes`, `moves`, `made` and `remade` runs), the
made-text checks of the line writer (`placed`, the removed-text check,
the line feeds a line break takes, `partLeft`) and the lineage branch of
the origins: the writer loses 509 lines (614 removed, 105 added), the
replay gains 475 (621 removed, 1,096 added), and `@lexical/y`'s source
as a whole is 26 lines longer (1,235 removed, 1,261 added). Before, a node swap the rules
did not foresee was guessed per node and lost characters next to equal
text, so a peer's concurrent delete there came back or its typing moved:
two equal hashtags or keywords made plain text at once, a hashtag grown
over a keyword the same update made plain text (`TextEntityEdits`: 18 of
2,738 seeded updates with 3,000 seeds, 4 of them new in the previous
revision; now 0), and node swaps around caret edits in one update
(`NodeSwapEdits`, new: a custom text class and a link; a part split off
and made again as the other class, maybe bold, a node made again whole,
two equal neighbours made plain text at once, an entity grown over the
next node or shrunk into it with `setTextContent`, a range wrapped in a
link or unwrapped, each of these where typing, Backspace or Delete land
before and after them in the same update, a peer deleting a kept
character or typing between two at the same time, each character's
provenance checked, and the peers and a fresh reader converging: of 380
seeded updates, 39 written otherwise on the previous revision;
now 0; with 4,000 seeds 390 of 3,850 before, now 17, each
written anew, see Known limits). `TextEntityEdits`, `RemadeText`,
`MadeNodeEdits`, `CompoundTextEdits` and every repro of the previous
revisions' text-entity findings (R17A-1, R18A-1 to R18A-4, R18B-F1) give
what they gave on the previous revision or better. Lexical's record
gains a `delete` entry for a node the selection removes with what it
holds (a text node's removal was a splice of all its text): a line break
or an inline node a selection deletes is a delete, never text that left
(`CompoundTextEdits`: a line break deleted and another made in its
place).
- A stretch's text sets are resolved together, against all the text that
left the stretch. Before, a text set kept the common start and end of
its own node's old text only, and nothing where text arrived in more
than one node:
- a hashtag grown over the bold neighbour after it, once a node made
before its text (a paste, or app code without a caret) had merged into
it, kept its own old `b` for its last character, which came from the
neighbour, so a peer's concurrent edit there landed on the wrong
character on every client (R19A-1);
- a node set whole and a node made after it in one update (an agent's
compose), or text pasted at the end of a stored hashtag (the plugin
moves the pasted letters into it and sets the pasted node to the rest:
two nodes set whole), wrote the set nodes' untouched characters anew,
so a peer's concurrent delete there came back (R19A-2, R19B-F1).
Now the text that arrived in a stretch is aligned with the text that
left it by their common start and end, whatever nodes hold either, and
the text that sets put in place of old characters keeps what it is
aligned with; the text a node made holds, and a set's text in place of
new text only, take their place in the alignment and are new. Text that
left with a removed node is aligned only whole, and next to text a set
replaced that the alignment keeps, so an agent's rewrite of a line keeps
the rewritten node's own last space, not the removed tail's `. `
(`RewriteMerge`). The comparison stays a common prefix and suffix,
linear in the stretch. `MadeNodeEdits` holds these shapes (10 new tests,
9 failed before; the tenth, a node removed before a node set whole,
guards the alignment's ends).
- Text a node made holds takes no old characters from set text, each end
of a stretch's alignment keeps the removed text it covers whatever the
other end does, and a node set whole keeps at least what its own diff
keeps. Before:
- a node made next to a node set whole, with the set node's old text or
its first or last word (an agent's compose, a copy pasted next to the
original), took the alignment, so the set node's own characters were
written anew and a peer's concurrent delete there came back on every
client (R20B-F1, R20A-2);
- a node set whole that took a removed neighbour's text, with a node
made after it, wrote that text anew, as the removed text was aligned
only where the common end covered it, though the common start covered
it and the set node's own text (R20B-F2);
- a text set and a delete of part of the text just set, in one update
(an entity grown and Backspaced, a word set and deleted again), gave
up the stretch, so the set node's untouched characters were written
anew (R20A-1).
Now the old characters the alignment gives made text stay free, and the
set text still new between two kept characters (or a kept one and an
end of the stretch) is aligned with the free old characters between
them, as the stretch is. An end that keeps all the text sets replaced
goes on over the removed node's text right beyond it, where it covers
all of it. Text deleted after it arrived stays in the alignment where it
is, so the old characters its set text is aligned with are deleted, not
given to other text. Last, where one node is set whole in the stretch,
it keeps the old characters of its own that its own diff (its old text
against its text now, as an update that changes only that node is
written) keeps, where the stretch keeps them nowhere else and they fall
in order with what it keeps; a development build checks this floor (an
invariant). Where several nodes are set whole in one stretch (an entity
grown or shrunk into its neighbour), a node's own diff can name
characters that moved into the other node, so the stretch's alignment
alone decides there (with the floor there, `NodeSwapEdits` kept a
character for another in 2 seeds, which no revision since the record
did); where the record lost which old characters a delete took (blind),
nothing is kept, as before (a node's own diff kept a deleted character
in 2 more). The comparisons stay a common prefix and suffix, linear in
the stretch. The new regression suite (`__tests__/unit/regressions/`,
5 files, 78 tests) holds these shapes (R20B-F1, R20B-F2, R20A-1 and
R20A-2: 23 failed before) and the reviews' findings whose repros were
not committed (R14B-C1, R15B-F2, R17A-2, J-1), with the three open
items below as expected failures.
- Each stretch between the old characters the record keeps in place is
resolved by one mechanism, the diff a write makes without the record,
where the record decides nothing; the rules stacked on it before (made
text claims nothing, removed text aligned only at an end and next to
kept set text, one removed node beyond the set text, a node's own diff
as a floor) are gone. Before:
- a node set whole that took the text of two removed neighbours, with a
node made after it, wrote the second neighbour's text anew, so a
peer's concurrent delete there came back (R21B-F1);
- an entity transform that grew a stale entity over its neighbour and
made it plain again, next to a node the update made, wrote the
entity's text anew (R21A-1);
- a text set, edited inside the text just set and set again in one
update, wrote the node's old text anew (R21A-2): the stretch was given
up once the record lost where the deleted text was;
- the floor compared each set run with every old run: quadratic in a
line…
777c5dc to
b0b85cd
Compare
db24986 to
6919907
Compare
…server-side editing API (@lexical/y/headless) ## Description Stacked on #9449 (block moves in `@lexical/y`), which is stacked on #9400 (`@lexical/y`, the Yjs 14 binding). Today `@lexical/y` gives a server `inspectUpdateRoots` (from `@lexical/y/server`) and nothing else. Everything a server needs to seed, edit or read a stored document is left to each integration: bind a headless editor to a Yjs state, wait for the layout record, run one edit, collect the updates it writes (including the ones opening the document writes, which the edit can build on), merge them, check their roots, and dispose of the editor, the binding and the document without leaking listeners. This adds a new entry, `@lexical/y/headless`, with three plain functions (all `@experimental`): - `seedYState(config, $build)` writes `$build`'s content into an empty root through the binding's `initialize()`: a client id derived from the content (53 bits under `'uint53'`, 32 under `'uint32'`), outside any undo history. Identical content gives identical bytes, so two seeds merge into one copy (content with random parts, such as drawn block ids, is not identical). The state holds only the layout root, so it is also how a converter moves a `@lexical/yjs` document: seed the content an editor read from it and merge the seed into the stored document, next to the old root. It is the one documented way to seed or convert a document. - `editYState(state, config, $edit, {allowedRoots, transact, tag})` runs `$edit` in one discrete update on the document at `state`, commits the updates it made listeners schedule (an extension giving new blocks ids; without this they were lost when the editor was disposed), and returns `{update, state, warnings}`: one merged update of everything written (or `null` when nothing changed) and the state with it merged in. The update is refused unless every root it writes to is allowed (default: the layout root); `transact(doc)` writes other shared types (an activity log) into the same update. An error thrown by `$edit` is rethrown after Lexical has restored the previous state, so nothing is written. - `readYState(state, config, $read)` returns what `$read` reads. What opening the document writes (ids an extension gives blocks stored without one, repairs) is read but not stored, so such values can differ between reads; the docs tell servers to store the update of a no-op `editYState` once first. - `YHeadlessError` with a `code`: `'not-initialized'`, `'read-only'` (a newer layout, unknown node types; the message carries the binding's reason), `'foreign-roots'`. `config` is the editor (`extensions`, built with `buildEditorFromExtensions`, or `nodes`), the root name, `clientIDRange` (`'uint32'` for yrs before 0.28), `onWarn` and `selfCheck`. Warnings are structured `{code, message}` objects (`YHeadlessWarning`), on both `config.onWarn` (default: `console.warn` outside production) and the result's `warnings`. The codes are the binding's `YWarningCode` from `@lexical/y` (`'unsupported-layout'`, `'unknown-node-types'`, `'storage-mismatch'`, `'self-check'`, `'recovered-read'`, `'recovered-write'`) plus two of the helpers' own: - `'editor-warning'`: a warning the editor reported through its `onWarn` (Lexical or an extension), forwarded with its message; - `'follow-ups-exhausted'`: the edit's listeners kept scheduling updates; after 8 follow-up updates the rest are not committed and are not part of the result (previously this was silent). Warnings never refuse an edit, in development or production: the self-check runs only in development by default, so refusing on it would make the two behave differently, and a recovered write leaves the document right. The headless editor's document does not garbage collect, so the root check resolves deleted items without loading the state a second time. The headless editor itself (`createHeadlessYEditor`) stays internal: the three functions cover seeding, editing and reading, and nothing outside this entry's tests uses a handle. Exposing it later is additive. `@lexical/y/server` keeps no editor dependencies. The new entry imports `@lexical/y` and `@lexical/y/server` as external siblings, so the binding is not bundled twice (`dist/LexicalYHeadless.dev.js` is 10 kB). Flow libdef `flow/LexicalYHeadless.js.flow`; `.flowconfig` and the tsconfig paths are regenerated (`update-flowconfig`, `update-tsconfig`). Docs: a "Server-side editing" section in the package README and a website page, `docs/collaboration/y-server.md` (API, the warning codes, and the server patterns: store what opening writes, one writer per document, rejecting updates to old roots with `inspectUpdateRoots`, converting a `@lexical/yjs` document with `seedYState`, yrs compatibility), in the Collaboration sidebar and linked from the `@lexical/y` page. The README and the `@lexical/y` page now point to `seedYState` for seeding and conversion. `@lexical/yjs` is untouched. ## Test plan New tests: `Headless.test.ts` (round trip; identical seeds merge; no-op edits; a throwing edit writes nothing; a server edit merging with two offline peers' edits, delivered before and after the peers sync; an edit to a line a peer is typing in, replacing a word and turning the line into a heading, keeps the peer's text; a foreign root is refused and an allowed one goes through; `'uint32'` keeps every struct's client id in 32 bits; a newer layout is refused by every entry point with the binding's reason and an `'unsupported-layout'` warning; an empty state is `'not-initialized'`; after dispose, the editor and the document have exactly the listeners a bare editor and a bare document have; with an extension that gives blocks random ids from an update listener, an edit's update includes the new block's id, a document stored without ids reads different ids each time until the update of a no-op edit is stored, and then reads agree; warnings are structured, reported, returned and do not refuse the edit, also with `NODE_ENV=production`, and go to `console.warn` without `onWarn`; a listener that never stops scheduling updates gives `'follow-ups-exhausted'` (once for opening, once for the edit) while the edit still goes through; a seed of an old editor's content merged into a document whose `@lexical/yjs` root has content converts it and leaves the old root as it was), `HeadlessScale.test.ts` (10,000 paragraphs), and relay round trips in `YrsCompat.test.ts` (seed, a peer typing, a server edit and a reconnect through ywasm 0.23.5 and 0.28 relays; with 53-bit server ids a 0.23 relay makes a peer that also got the update directly show it twice). ### Before ``` $ npx vitest --project unit --no-watch packages/lexical-y/src/__tests__/unit/Headless.test.ts packages/lexical-y/src/__tests__/unit/HeadlessScale.test.ts packages/lexical-y/src/__tests__/unit/YrsCompat.test.ts FAIL |unit| packages/lexical-y/src/__tests__/unit/Headless.test.ts Error: Cannot find module '../../headless' imported from .../packages/lexical-y/src/__tests__/unit/Headless.test.ts FAIL |unit| packages/lexical-y/src/__tests__/unit/HeadlessScale.test.ts Error: Cannot find module '../../headless' imported from .../packages/lexical-y/src/__tests__/unit/HeadlessScale.test.ts FAIL |unit| packages/lexical-y/src/__tests__/unit/YrsCompat.test.ts Error: Cannot find module '../../headless' imported from .../packages/lexical-y/src/__tests__/unit/YrsCompat.test.ts Test Files 3 failed (3) Tests no tests ``` ### After ``` $ npx vitest --project unit --no-watch --reporter=verbose packages/lexical-y/src/__tests__/unit/Headless.test.ts packages/lexical-y/src/__tests__/unit/HeadlessScale.test.ts packages/lexical-y/src/__tests__/unit/YrsCompat.test.ts ✓ Headless.test.ts > seed, edit and read round trip ✓ Headless.test.ts > identical seeds give the same bytes and merge into one copy ✓ Headless.test.ts > an edit with no change returns no update ✓ Headless.test.ts > an error thrown by the edit is rethrown and nothing is returned ✓ Headless.test.ts > a server edit merges with concurrent peer edits (server first) ✓ Headless.test.ts > a server edit merges with concurrent peer edits (peers first) ✓ Headless.test.ts > an edit to a block a peer is typing in keeps their text ✓ Headless.test.ts > an update to a root that is not allowed is refused ✓ Headless.test.ts > clientIDRange 'uint32' keeps every client id in 32 bits ✓ Headless.test.ts > a document with a newer layout is read only and refused ✓ Headless.test.ts > an empty state is not initialized ✓ Headless.test.ts > dispose leaves no listeners on the editor or the document ✓ Headless.test.ts > updates scheduled by an edit are part of its update ✓ Headless.test.ts > values assigned on open are stored by a no-op edit, not by a read ✓ Headless.test.ts > warnings are reported and never refuse an edit ✓ Headless.test.ts > listeners that never stop scheduling updates are reported ✓ Headless.test.ts > a seed merged next to an older layout converts the document ✓ Headless.test.ts > extensions define the editor ✓ YrsCompat.test.ts > @lexical/y with yrs relays > yrs 0.23 duplicates the content of a 53-bit client on reconnect ✓ YrsCompat.test.ts > @lexical/y with yrs relays > yrs 0.23 with clientIDRange uint32: no duplication ✓ YrsCompat.test.ts > @lexical/y with yrs relays > yrs 0.28 handles 53-bit client ids ✓ YrsCompat.test.ts > @lexical/y with yrs relays > uint32 range survives Yjs drawing a new client id ✓ YrsCompat.test.ts > @lexical/y/headless with yrs relays > ywasm 0.23 relay round trip, 32-bit ids ✓ YrsCompat.test.ts > @lexical/y/headless with yrs relays > ywasm 0.23 relay round trip, 32-bit ids, update also sent directly ✓ YrsCompat.test.ts > @lexical/y/headless with yrs relays > ywasm 0.28 relay round trip, 32-bit ids ✓ YrsCompat.test.ts > @lexical/y/headless with yrs relays > ywasm 0.28 relay round trip, 32-bit ids, update also sent directly ✓ YrsCompat.test.ts > @lexical/y/headless with yrs relays > ywasm 0.28 relay round trip, 53-bit ids ✓ YrsCompat.test.ts > @lexical/y/headless with yrs relays > ywasm 0.23 relay with 53-bit server ids duplicates a direct update ✓ HeadlessScale.test.ts > @lexical/y/headless at scale > open, edit and dispose a 10,000-block document Test Files 3 passed (3) Tests 29 passed (29) ``` (The four existing YrsCompat tests also pass.) Scale, Node 24, development build (self-check on), 10,000 paragraphs vs 1,000: ``` {"big":{"blocks":10000,"disposeMs":0,"editMs":327,"openMs":199,"readMs":193,"seedMs":477,"stateBytes":578012,"updateBytes":69,"writeMs":47}, "small":{"blocks":1000,"disposeMs":0,"editMs":34,"openMs":19,"readMs":24,"seedMs":61,"stateBytes":56011,"updateBytes":71,"writeMs":5}} ``` `editMs` is `editYState` end to end (open, one edit, root check, merge, dispose); `openMs`/`writeMs`/`disposeMs` are the phases through an internal handle. `writeMs` varies between runs with the development self-check's sampled full-container comparison, which is off in production. Also run, on this revision of the stack: `npx vitest --project unit packages/lexical-y` (53 files, 2,151 tests pass, 2 skipped), `pnpm run tsc`, `pnpm run flow` (0 errors), the source tree-shaking test (`@lexical/y (packages/lexical-y/src/headless.ts)` and `internal/HeadlessEditor.ts` retain nothing), `pnpm run build` (`LexicalYHeadless.dev.js` imports `@lexical/y`, `@lexical/y/server`, `@y/y`, `lexical` and `@lexical/extension` as externals), eslint and prettier on the touched files. Not exercised: real browsers, a real network relay (the relays are ywasm documents in the test process), production builds' timings, and the preview builds of this commit (pkg.pr.new publishes them when it is pushed).
…round, with e2e specs ## Description Stacked on #9437 (the `@lexical/y` stack: #9400, #9449, #9437). Current behavior: the playground can run collaboration on `@lexical/yjs` only (collab v1 with `CollaborationPlugin`, v2 with `CollaborationPluginV2__EXPERIMENTAL`, chosen with `?isCollab=true` and `?useCollabV2=true`). The experimental `@lexical/y` binding (Yjs 14, `@y/y`) cannot be tried in the playground, and the repo's e2e suite does not cover it. New behavior (opt-in; the default playground, `pnpm run start` and collab v1/v2 are unchanged): - `?isCollab=true&useCollabY=true` runs the playground on `@lexical/y`: the editor gets `YCollabExtension` with a `@y/y` document and a `@y/websocket` provider (`4.0.0-rc.2`, the published Yjs 14 client). The playground pins `@y/y` to `14.0.0-rc.29`, the version `@lexical/y` pins, so the lockfile holds one `@y/y`. The mode lives in its own chunk (`collaborationY.tsx`, loaded with `import()`), so the default playground does not load a second Yjs. `HistoryExtension` is left out in this mode (`YCollabExtension` provides undo and conflicts with it). The toolbar's connect button connects and disconnects the provider; the binding is initialized after the provider's first sync; a document whose layout this client does not support shows a read-only notice. - `pnpm run collab:y` starts a Yjs 14 relay on `localhost:1235` (`packages/lexical-playground/scripts/collab-y-server.mjs`), and `pnpm run start:y` starts it together with the playground dev server. `pnpm run start` is unchanged (dev server and the `@lexical/yjs` collab server). The published `@y/websocket-server` still depends on the pre-`@y/y` Yjs 14 prereleases (`yjs@14.0.0-*`), whose documents are not compatible with `@y/y`, so the relay is a small in-memory y-websocket protocol server on `@y/y`, `@y/protocols` and `lib0` 1.x, with a test-only `/delay` endpoint. - Playground features the binding does not sync are handled explicitly: nested editors (image captions, sticky notes) are read only in this mode and "Add Caption" is not offered; comments are off (as in collab v2: the comment threads live in a Yjs 13 document); there are no remote cursors. Playground nodes without collab declarations use the binding's nested storage. Comments keep using MarkNode. - E2E: a new editor mode, `E2E_EDITOR_MODE=rich-text-with-collab-y` (`pnpm run test-e2e-collab-y-{chromium,firefox,webkit}`, against `pnpm run start:y`), runs `Collaboration.spec.mjs` and the new `CollabY*.spec.mjs`. `Collaboration.spec.mjs` is parameterized: where collab v1/v2 drop a peer's text on undo, collab Y asserts that the peer's text stays (undo only reverts the client's own changes), and collab Y does not restore the selection an undo step was made with, so that test places the caret explicitly. The new specs open each client in its own browser context (own keyboard), delay the relay's server-to-client messages while clients edit at the same time, and end every case by checking that all clients converge, that a client loading the document afterwards shows the same, that no typed token is lost or duplicated, and that no client logged an error or warning (the binding's development self-check reports through warnings). They cover: Enter, Backspace and Delete at line boundaries, heading/quote toggles and list create/indent/outdent while peers type; links while peers type inside and after the link; offline edits on both sides (text and structure, and a 30-lines-per-side divergence) and reconnect; undo isolation (own typing, Enter and heading undone after peer edits, undo while the peer types inside the undone text); the layout version gate (a document marked with layout 3, which this client does not read, makes open and late-joining clients read only); tables (cell typing, concurrent row and column insert stays rectangular, two rows inserted at one place); images (synced, no caption offered); and IME composition (Chromium, CDP) while a peer types, splits or joins the line. - CI: a `collab-y-linux` job (Chromium and Firefox) runs the mode the way `collab-v2-linux` runs collab v2, starting `pnpm run collab:y` instead of `pnpm run collab`. ## Test plan ### Before ``` $ pnpm run collab:y [ERR_PNPM_NO_SCRIPT] Missing script: collab:y $ pnpm run start:y [ERR_PNPM_NO_SCRIPT] Missing script: start:y $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --list --project=chromium | grep -c CollabY 0 ``` `?useCollabY=true` is not a playground setting (it is ignored, and `?isCollab=true` runs collab v1); no playground source imports `@lexical/y`. ### After ``` $ HOST=localhost PORT=1291 node packages/lexical-playground/scripts/collab-y-server.mjs # what collab:y runs, on a free port Yjs 14 (@lexical/y) relay running on ws://localhost:1291 $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --list --project=chromium Total: 26 tests in 4 files # Collaboration 6, CollabYNodes 6, CollabYStructure 8, CollabYSync 6 ``` Collab Y mode, development playground build (`pnpm run build-playground-dev`, served with `vite preview`), relay from `collab-y-server.mjs`, no retries: ``` $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --project=chromium --workers=2 --retries=0 26 passed (1.1m) $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --project=firefox --workers=2 --retries=0 3 skipped 23 passed (1.3m) # the 3 IME specs are Chromium only $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --project=webkit --workers=2 --retries=0 3 skipped 23 passed (1.2m) $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --project=chromium --workers=6 --retries=0 --repeat-each=3 78 passed (1.3m) # previous base revision ``` The version gate spec marks the document with layout 3. Marking it one past the root's version, as the previous revision of the spec did, writes layout 2 on a new document, which `@lexical/y` reads since block moves (#9449): ``` $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --project=chromium CollabYSync -g 'version gate' # previous revision of the spec Error: expect(received).toBe(expected) // Object.is equality Expected: "readonly" Received: "active" 1 failed # this revision 1 passed (4.3s) ``` Collab v1/v2 are unchanged: ``` $ E2E_EDITOR_MODE=rich-text-with-collab npx playwright test --project=chromium --workers=2 --retries=0 Collaboration.spec 6 passed (7.3s) $ E2E_EDITOR_MODE=rich-text-with-collab-v2 npx playwright test --project=chromium --workers=6 --retries=0 Collaboration.spec 6 passed (3.8s) # previous base revision ``` Also: `pnpm run tsc` (0 errors), `pnpm run flow` (0 errors), eslint and prettier on the touched files, the tree-shaking tests (`scripts/__tests__/integration/tree-shaking.test.mjs`, 286 tests; `treeShakingSource.test.ts`, 363 tests), `npx vitest --project unit packages/lexical-playground` (33 files, 390 tests), `pnpm run build`, and `pnpm run build-playground-dev` (`@lexical/y` is only in the `collaborationY` chunk). Not exercised: the CI workflow itself (run locally only), macOS and Windows, the production playground build in a browser, and real IME input (CDP composition events only).
## Description Stacked on #9438 (the `@lexical/y` stack: #9400, #9449, #9437, #9438). Depends on #9380 (`MarkStateExtension` and `collab: 'set'` NodeState). This branch carries that commit as a temporary dependency commit, to be dropped once #9380 merges. Current behavior: `@lexical/y` stores each NodeState entry of a text run, line break or inline node as one `s:<key>` format holding the serialized value. A set-valued state such as `MarkStateExtension`'s `markIds` is one array per run, so when two peers comment on the same text concurrently, one peer's comments win (last writer wins on the whole set). New behavior: - On text runs, line breaks and nodes stored as their own Y.Node, a set-valued state known for the node type is written as one `s:<key>\u001f<member>` format per member (`splitCollabStateEntries`). Concurrent additions and removals of different members merge. Reading is unchanged: NodeState joins the member entries back into the set (#9380). Block markers, wrappers and list groups still store the set whole. - A peer that does not know the state keeps each member as its own NodeState key and writes it back unchanged, so it never collapses the members. - The self-check's fresh editor gets the set-valued StateConfigs registered on the binding's editor, so it reads the members the same way (otherwise every write of a set would be reported to the binding's `onWarn` as a `'self-check'` warning). - Tests: the harness takes a `prepare(editor)` hook (run before the binding starts; fresh readers reuse it). The fuzz now stores comments as one set-valued state, like `MarkStateExtension`; `FUZZ_COMMENTS=keys` keeps the previous one-boolean-key-per-id model. `Size.test.ts` budgets three `MarkStateExtension` operations. - Docs: the "Set-valued NodeState" limit in the `@lexical/y` README and on the Yjs 14 collaboration page now says where the set is stored per member and where it is still one value (line markers, groups, inline wrappers). Bytes the editing client emits (`@y/y` 14.0.0-rc.29, gc off, pinned client ids), op / undo / redo: ``` one format per id whole set (before) add a comment 83 / 10 / 77 92 / 10 / 86 add an overlapping comment 83 / 10 / 77 196 / 45 / 190 remove one of two comments 12 / 142 / 10 113 / 144 / 113 ``` ## Test plan New `packages/lexical-y/src/__tests__/unit/MarkState.test.ts`: two peers (ids 1,2 and 2,1, causal and per-sender delivery) and three peers, with concurrent comments on the same and on overlapping ranges, across a line break, resolving while a peer types, resolving one of two comments, undo while a peer types, the stored format keys, and a peer that does not know the state editing commented text. ### Before `Schema.ts` and `SelfCheck.ts` reverted to the dependency commit: ``` $ npx vitest --project unit --no-watch --maxWorkers=1 packages/lexical-y/src/__tests__/unit/MarkState.test.ts packages/lexical-y/src/__tests__/unit/Size.test.ts × each id is its own format key (4 of 4 orders) AssertionError: expected [ 's:markIds' ] to deeply equal [ 's:markIds\u001fc1', …(1) ] × two peers mark the same range (4 of 4 orders) AssertionError: expected 'paragraph("Revenue " "grew 4%"[c2] " …' to be 'paragraph("Revenue " "grew 4%"[c1,c2]…' × two peers mark overlapping ranges (4 of 4 orders) × two peers mark overlapping ranges across a line break AssertionError: expected 'paragraph("a"[c2] "b"[c1] linebreak[c…' to be 'paragraph("a"[c2] "b"[c1,c2] linebrea…' × keeps each id as its own format when it edits marked text × add a comment (MarkStateExtension) AssertionError: expected 92 to be less than or equal to 90 × add an overlapping comment (MarkStateExtension) AssertionError: expected 196 to be less than or equal to 90 × remove a comment (MarkStateExtension) AssertionError: expected 113 to be less than or equal to 14 Tests 17 failed | 40 passed (57) ``` ### After ``` $ npx vitest --project unit --no-watch --maxWorkers=1 packages/lexical-y packages/lexical-yjs packages/lexical-mark packages/lexical-react/src/__tests__/unit/Collab packages/lexical/src/__tests__/unit/LexicalNodeState.test.ts Test Files 75 passed (75) Tests 3209 passed | 8 expected fail | 2 skipped (3219) ``` The 8 expected failures are `MarkStateCollab.test.tsx`'s pinned v2 and v1 limits from #9380 (#9381 is not in this stack). The 2 skipped tests are in `ListsInLines.test.ts` and are skipped on #9400 as well. Fuzz with comments as one set-valued state, 500 seeds plus 100 gc seeds: ``` $ FUZZ_SEEDS=500 npx vitest --project unit --no-watch --maxWorkers=1 packages/lexical-y/src/__tests__/unit/Fuzz.test.ts ✓ seeds 1..51 ... ✓ seeds 451..501, ✓ gc seeds 1..51, ✓ gc seeds 51..101 Tests 12 passed (12) ``` On the whole stack (this commit on top), the same fuzz at 2,000 + 500 gc seeds, with and without block moves, passes (116 of 116 chunks), and so does `pnpm run test-unit` (443 files). Also run: `pnpm run tsc`, `pnpm run flow` (0 errors), eslint and prettier on the touched files, `pnpm run build`, the tree-shaking tests (source 364 pass, build output 286 pass) and `pnpm run build-docs`. Not exercised: real Yjs 14 providers and browsers.
b0b85cd to
b2d43d9
Compare
6919907 to
c14c0a2
Compare
…server-side editing API (@lexical/y/headless) ## Description Stacked on #9449 (block moves in `@lexical/y`), which is stacked on #9400 (`@lexical/y`, the Yjs 14 binding). Today `@lexical/y` gives a server nothing beyond the main entry's `DEFAULT_ROOT_NAME` and `LAYOUT_VERSION`. Everything a server needs to seed, edit or read a stored document is left to each integration: bind a headless editor to a Yjs state, wait for the layout record, run one edit, collect the updates it writes (including the ones opening the document writes, which the edit can build on), merge them, check their roots, and dispose of the editor, the binding and the document without leaking listeners. This adds a new entry, `@lexical/y/headless`, with three plain functions (all `@experimental`): - `seedYState(config, $build)` writes `$build`'s content into an empty root through the binding's `initialize()`: a client id derived from the content (53 bits under `'uint53'`, 32 under `'uint32'`), outside any undo history. Identical content gives identical bytes, so two seeds merge into one copy (content with random parts, such as drawn block ids, is not identical). The state holds only the layout root, so it is also how a converter moves a `@lexical/yjs` document: seed the content an editor read from it and merge the seed into the stored document, next to the old root. It is the one documented way to seed or convert a document. - `editYState(state, config, $edit, {allowedRoots, transact, tag})` runs `$edit` in one discrete update on the document at `state`, commits the updates it made listeners schedule (an extension giving new blocks ids; without this they were lost when the editor was disposed), and returns `{update, state, warnings}`: one merged update of everything written (or `null` when nothing changed) and the state with it merged in. The update is refused unless every root it writes to is allowed (default: the layout root); `transact(doc)` writes other shared types (an activity log) into the same update. An error thrown by `$edit` is rethrown after Lexical has restored the previous state, so nothing is written. - `readYState(state, config, $read)` returns what `$read` reads. What opening the document writes (ids an extension gives blocks stored without one, repairs) is read but not stored, so such values can differ between reads; the docs tell servers to store the update of a no-op `editYState` once first. - `YHeadlessError` with a `code`: `'not-initialized'`, `'read-only'` (a newer layout, unknown node types; the message carries the binding's reason), `'foreign-roots'`. `config` is the editor (`extensions`, built with `buildEditorFromExtensions`, or `nodes`), the root name, `clientIDRange` (`'uint32'` for yrs before 0.28), `onWarn` and `selfCheck`. Warnings are structured `{code, message}` objects (`YHeadlessWarning`), on both `config.onWarn` (default: `console.warn` outside production) and the result's `warnings`. The codes are the binding's `YWarningCode` from `@lexical/y` (`'unsupported-layout'`, `'unknown-node-types'`, `'storage-mismatch'`, `'self-check'`, `'recovered-read'`, `'recovered-write'`) plus two of the helpers' own: - `'editor-warning'`: a warning the editor reported through its `onWarn` (Lexical or an extension), forwarded with its message; - `'follow-ups-exhausted'`: the edit's listeners kept scheduling updates; after 8 follow-up updates the rest are not committed and are not part of the result (previously this was silent). Warnings never refuse an edit, in development or production: the self-check runs only in development by default, so refusing on it would make the two behave differently, and a recovered write leaves the document right. The headless editor's document does not garbage collect, so the root check resolves deleted items without loading the state a second time. The server API is plain functions only. The headless editor itself (`openHeadlessYEditor`, `OpenedHeadlessYEditor`) stays internal: the three functions cover seeding, editing and reading, and nothing public needs a handle (`Source.test.ts` pins the entry's exports to `seedYState`, `editYState`, `readYState` and `YHeadlessError`). Exposing it later is additive. The root check of `editYState` uses an internal helper (the roots an update writes to); there is no `@lexical/y/server` entry. The new entry imports `@lexical/y` as an external sibling, so the binding is not bundled twice. Flow libdef `flow/LexicalYHeadless.js.flow`; `.flowconfig` and the tsconfig paths are regenerated (`update-flowconfig`, `update-tsconfig`). Docs: a website page, Collaboration > Server-side editing with `@lexical/y` (the API, errors and warnings, and the server patterns: store what opening writes, one writer per document, converting a `@lexical/yjs` document with `seedYState`), linked from the `@lexical/y` page, whose servers section covers old clients (they write other roots, so no check is needed) and yrs compatibility. The `@lexical/y` page and the README point to `seedYState` for seeding and conversion, and the page's "Changing the layout and migrating" section (which replaces "Upgrading from `@lexical/yjs`") explains the frozen wire format, what keeps the layout and what bumps `LAYOUT_VERSION`, field changes, and the steps (with a diagram and a sample) to reseed a room from Lexical JSON, an `@lexical/y` room or a `@lexical/yjs` room. `@lexical/yjs` is untouched. ## Test plan New tests: `Headless.test.ts` (round trip; identical seeds merge; no-op edits; a throwing edit writes nothing; a server edit merging with two offline peers' edits, delivered before and after the peers sync; an edit to a line a peer is typing in, replacing a word and turning the line into a heading, keeps the peer's text; a foreign root is refused and an allowed one goes through; `'uint32'` keeps every struct's client id in 32 bits; a newer layout is refused by every entry point with the binding's reason and an `'unsupported-layout'` warning; an empty state is `'not-initialized'`; after dispose, the editor and the document have exactly the listeners a bare editor and a bare document have; with an extension that gives blocks random ids from an update listener, an edit's update includes the new block's id, a document stored without ids reads different ids each time until the update of a no-op edit is stored, and then reads agree; warnings are structured, reported, returned and do not refuse the edit, also with `NODE_ENV=production`, and go to `console.warn` without `onWarn`; a listener that never stops scheduling updates gives `'follow-ups-exhausted'` (once for opening, once for the edit) while the edit still goes through; a seed of an old editor's content merged into a document whose `@lexical/yjs` root has content converts it and leaves the old root as it was), `HeadlessScale.test.ts` (10,000 paragraphs), and relay round trips in `YrsCompat.test.ts` (seed, a peer typing, a server edit and a reconnect through ywasm 0.23.5 and 0.28 relays; with 53-bit server ids a 0.23 relay makes a peer that also got the update directly show it twice). ### Before ``` $ npx vitest --project unit --no-watch packages/lexical-y/src/__tests__/unit/Headless.test.ts packages/lexical-y/src/__tests__/unit/HeadlessScale.test.ts packages/lexical-y/src/__tests__/unit/YrsCompat.test.ts FAIL |unit| packages/lexical-y/src/__tests__/unit/Headless.test.ts Error: Cannot find module '../../headless' imported from .../packages/lexical-y/src/__tests__/unit/Headless.test.ts FAIL |unit| packages/lexical-y/src/__tests__/unit/HeadlessScale.test.ts Error: Cannot find module '../../headless' imported from .../packages/lexical-y/src/__tests__/unit/HeadlessScale.test.ts FAIL |unit| packages/lexical-y/src/__tests__/unit/YrsCompat.test.ts Error: Cannot find module '../../headless' imported from .../packages/lexical-y/src/__tests__/unit/YrsCompat.test.ts Test Files 3 failed (3) Tests no tests ``` ### After ``` $ npx vitest --project unit --no-watch --reporter=verbose packages/lexical-y/src/__tests__/unit/Headless.test.ts packages/lexical-y/src/__tests__/unit/HeadlessScale.test.ts packages/lexical-y/src/__tests__/unit/YrsCompat.test.ts ✓ Headless.test.ts > seed, edit and read round trip ✓ Headless.test.ts > identical seeds give the same bytes and merge into one copy ✓ Headless.test.ts > an edit with no change returns no update ✓ Headless.test.ts > an error thrown by the edit is rethrown and nothing is returned ✓ Headless.test.ts > a server edit merges with concurrent peer edits (server first) ✓ Headless.test.ts > a server edit merges with concurrent peer edits (peers first) ✓ Headless.test.ts > an edit to a block a peer is typing in keeps their text ✓ Headless.test.ts > an update to a root that is not allowed is refused ✓ Headless.test.ts > clientIDRange 'uint32' keeps every client id in 32 bits ✓ Headless.test.ts > a document with a newer layout is read only and refused ✓ Headless.test.ts > an empty state is not initialized ✓ Headless.test.ts > dispose leaves no listeners on the editor or the document ✓ Headless.test.ts > updates scheduled by an edit are part of its update ✓ Headless.test.ts > values assigned on open are stored by a no-op edit, not by a read ✓ Headless.test.ts > warnings are reported and never refuse an edit ✓ Headless.test.ts > listeners that never stop scheduling updates are reported ✓ Headless.test.ts > a seed merged next to an older layout converts the document ✓ Headless.test.ts > extensions define the editor ✓ YrsCompat.test.ts > @lexical/y with yrs relays > yrs 0.23 duplicates the content of a 53-bit client on reconnect ✓ YrsCompat.test.ts > @lexical/y with yrs relays > yrs 0.23 with clientIDRange uint32: no duplication ✓ YrsCompat.test.ts > @lexical/y with yrs relays > yrs 0.28 handles 53-bit client ids ✓ YrsCompat.test.ts > @lexical/y with yrs relays > uint32 range survives Yjs drawing a new client id ✓ YrsCompat.test.ts > @lexical/y/headless with yrs relays > ywasm 0.23 relay round trip, 32-bit ids ✓ YrsCompat.test.ts > @lexical/y/headless with yrs relays > ywasm 0.23 relay round trip, 32-bit ids, update also sent directly ✓ YrsCompat.test.ts > @lexical/y/headless with yrs relays > ywasm 0.28 relay round trip, 32-bit ids ✓ YrsCompat.test.ts > @lexical/y/headless with yrs relays > ywasm 0.28 relay round trip, 32-bit ids, update also sent directly ✓ YrsCompat.test.ts > @lexical/y/headless with yrs relays > ywasm 0.28 relay round trip, 53-bit ids ✓ YrsCompat.test.ts > @lexical/y/headless with yrs relays > ywasm 0.23 relay with 53-bit server ids duplicates a direct update ✓ HeadlessScale.test.ts > @lexical/y/headless at scale > open, edit and dispose a 10,000-block document Test Files 3 passed (3) Tests 29 passed (29) ``` (The four existing YrsCompat tests also pass.) Scale, Node 24, development build (self-check on), 10,000 paragraphs vs 1,000: ``` {"big":{"blocks":10000,"disposeMs":0,"editMs":327,"openMs":199,"readMs":193,"seedMs":477,"stateBytes":578012,"updateBytes":69,"writeMs":47}, "small":{"blocks":1000,"disposeMs":0,"editMs":34,"openMs":19,"readMs":24,"seedMs":61,"stateBytes":56011,"updateBytes":71,"writeMs":5}} ``` `editMs` is `editYState` end to end (open, one edit, root check, merge, dispose); `openMs`/`writeMs`/`disposeMs` are the phases through an internal handle. `writeMs` varies between runs with the development self-check's sampled full-container comparison, which is off in production. Also run, on this revision of the stack: `npx vitest --project unit packages/lexical-y` (54 files, 2,198 tests pass, 2 skipped), `pnpm run tsc`, `pnpm run flow` (0 errors), the source tree-shaking test (`@lexical/y (packages/lexical-y/src/headless.ts)` and `internal/HeadlessEditor.ts` retain nothing), `pnpm run build` (`LexicalYHeadless.dev.js` imports `@lexical/y`, `@y/y`, `lexical` and `@lexical/extension` as externals), eslint and prettier on the touched files. Not exercised: real browsers, a real network relay (the relays are ywasm documents in the test process), production builds' timings, and the preview builds of this commit (pkg.pr.new publishes them when it is pushed).
…round, with e2e specs ## Description Stacked on #9437 (the `@lexical/y` stack: #9400, #9449, #9437). Current behavior: the playground can run collaboration on `@lexical/yjs` only (collab v1 with `CollaborationPlugin`, v2 with `CollaborationPluginV2__EXPERIMENTAL`, chosen with `?isCollab=true` and `?useCollabV2=true`). The experimental `@lexical/y` binding (Yjs 14, `@y/y`) cannot be tried in the playground, and the repo's e2e suite does not cover it. New behavior (opt-in; the default playground, `pnpm run start` and collab v1/v2 are unchanged): - `?isCollab=true&useCollabY=true` runs the playground on `@lexical/y`: the editor gets `YCollabExtension` with a `@y/y` document and a `@y/websocket` provider (`4.0.0-rc.2`, the published Yjs 14 client). The playground pins `@y/y` to `14.0.0-rc.29`, the version `@lexical/y` pins, so the lockfile holds one `@y/y`. The mode lives in its own chunk (`collaborationY.tsx`, loaded with `import()`), so the default playground does not load a second Yjs. `HistoryExtension` is left out in this mode (`YCollabExtension` provides undo and conflicts with it). The toolbar's connect button connects and disconnects the provider; the binding is initialized after the provider's first sync; a document whose layout this client does not support shows a read-only notice. - `pnpm run collab:y` starts a Yjs 14 relay on `localhost:1235` (`packages/lexical-playground/scripts/collab-y-server.mjs`), and `pnpm run start:y` starts it together with the playground dev server. `pnpm run start` is unchanged (dev server and the `@lexical/yjs` collab server). The published `@y/websocket-server` still depends on the pre-`@y/y` Yjs 14 prereleases (`yjs@14.0.0-*`), whose documents are not compatible with `@y/y`, so the relay is a small in-memory y-websocket protocol server on `@y/y`, `@y/protocols` and `lib0` 1.x, with a test-only `/delay` endpoint. - Playground features the binding does not sync are handled explicitly: nested editors (image captions, sticky notes) are read only in this mode and "Add Caption" is not offered; comments are off (as in collab v2: the comment threads live in a Yjs 13 document); there are no remote cursors. Playground nodes without collab declarations use the binding's nested storage. Comments keep using MarkNode. - E2E: a new editor mode, `E2E_EDITOR_MODE=rich-text-with-collab-y` (`pnpm run test-e2e-collab-y-{chromium,firefox,webkit}`, against `pnpm run start:y`), runs `Collaboration.spec.mjs` and the new `CollabY*.spec.mjs`. `Collaboration.spec.mjs` is parameterized: where collab v1/v2 drop a peer's text on undo, collab Y asserts that the peer's text stays (undo only reverts the client's own changes), and collab Y does not restore the selection an undo step was made with, so that test places the caret explicitly. The new specs open each client in its own browser context (own keyboard), delay the relay's server-to-client messages while clients edit at the same time, and end every case by checking that all clients converge, that a client loading the document afterwards shows the same, that no typed token is lost or duplicated, and that no client logged an error or warning (the binding's development self-check reports through warnings). Console messages that are not about the editor are filtered by one list in the collab Y spec utilities (the other e2e specs do not read the console): failed resource loads, relay reconnects, Vite and React DevTools notices, and Firefox's "Loading failed for the <script>" for the playground's Vercel analytics scripts (`/_vercel/insights/script.js`, `/_vercel/speed-insights/script.js`), which a local or CI build does not serve (Chromium and WebKit report the same as "Failed to load resource"). They cover: Enter, Backspace and Delete at line boundaries, heading/quote toggles and list create/indent/outdent while peers type; links while peers type inside and after the link; offline edits on both sides (text and structure, and a 30-lines-per-side divergence) and reconnect; undo isolation (own typing, Enter and heading undone after peer edits, undo while the peer types inside the undone text); the layout version gate (a document marked with layout 3, which this client does not read, makes open and late-joining clients read only); tables (cell typing, concurrent row and column insert stays rectangular, two rows inserted at one place); images (synced, no caption offered); and IME composition (Chromium, CDP) while a peer types, splits or joins the line. - CI: a `collab-y-linux` job (Chromium and Firefox) runs the mode the way `collab-v2-linux` runs collab v2, starting `pnpm run collab:y` instead of `pnpm run collab`. ## Test plan ### Before ``` $ pnpm run collab:y [ERR_PNPM_NO_SCRIPT] Missing script: collab:y $ pnpm run start:y [ERR_PNPM_NO_SCRIPT] Missing script: start:y $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --list --project=chromium | grep -c CollabY 0 ``` `?useCollabY=true` is not a playground setting (it is ignored, and `?isCollab=true` runs collab v1); no playground source imports `@lexical/y`. ### After ``` $ HOST=localhost PORT=1291 node packages/lexical-playground/scripts/collab-y-server.mjs # what collab:y runs, on a free port Yjs 14 (@lexical/y) relay running on ws://localhost:1291 $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --list --project=chromium Total: 26 tests in 4 files # Collaboration 6, CollabYNodes 6, CollabYStructure 8, CollabYSync 6 ``` Collab Y mode, development playground build (`pnpm run build-playground-dev`, served with `vite preview`), relay from `collab-y-server.mjs`, no retries: ``` $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --project=chromium --workers=2 --retries=0 26 passed (1.1m) $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --project=firefox --workers=2 --retries=0 3 skipped 23 passed (1.3m) # the 3 IME specs are Chromium only $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --project=webkit --workers=2 --retries=0 3 skipped 23 passed (1.2m) # previous base revision $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --project=chromium --workers=6 --retries=0 --repeat-each=3 78 passed (1.3m) # previous base revision ``` Firefox without the Vercel scripts (as in CI; the build serves no `/_vercel/` files), the previous revision of the console filter, then this one: ``` $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --project=firefox --workers=2 --retries=0 # previous revision Error: console errors or warnings + "[F] console.warning: [JavaScript Warning: \"Loading failed for the <script> with source “http://localhost:4471/_vercel/speed-insights/script.js”.\" …]" 17 failed 3 skipped 6 passed (1.5m) # this revision 3 skipped 23 passed (1.3m) ``` The version gate spec marks the document with layout 3. Marking it one past the root's version, as the previous revision of the spec did, writes layout 2 on a new document, which `@lexical/y` reads since block moves (#9449): ``` $ E2E_EDITOR_MODE=rich-text-with-collab-y npx playwright test --project=chromium CollabYSync -g 'version gate' # previous revision of the spec Error: expect(received).toBe(expected) // Object.is equality Expected: "readonly" Received: "active" 1 failed # this revision 1 passed (4.3s) ``` Collab v1/v2 are unchanged: ``` $ E2E_EDITOR_MODE=rich-text-with-collab npx playwright test --project=chromium --workers=2 --retries=0 Collaboration.spec 6 passed (7.3s) $ E2E_EDITOR_MODE=rich-text-with-collab-v2 npx playwright test --project=chromium --workers=6 --retries=0 Collaboration.spec 6 passed (3.8s) # previous base revision ``` Also: `pnpm run tsc` (0 errors), `pnpm run flow` (0 errors), eslint and prettier on the touched files, the tree-shaking tests (`scripts/__tests__/integration/tree-shaking.test.mjs`, 286 tests; `treeShakingSource.test.ts`, 363 tests), `npx vitest --project unit packages/lexical-playground` (33 files, 390 tests), `pnpm run build`, and `pnpm run build-playground-dev` (`@lexical/y` is only in the `collaborationY` chunk). Not exercised: the CI workflow itself (run locally only), macOS and Windows, the production playground build in a browser, and real IME input (CDP composition events only).
## Description Stacked on #9438 (the `@lexical/y` stack: #9400, #9449, #9437, #9438). Depends on #9380 (`MarkStateExtension` and `collab: 'set'` NodeState). This branch carries that commit as a temporary dependency commit, to be dropped once #9380 merges. Current behavior: `@lexical/y` stores each NodeState entry of a text run, line break or inline node as one `s:<key>` format holding the serialized value. A set-valued state such as `MarkStateExtension`'s `markIds` is one array per run, so when two peers comment on the same text concurrently, one peer's comments win (last writer wins on the whole set). New behavior: - On text runs, line breaks and nodes stored as their own Y.Node, a set-valued state known for the node type is written as one `s:<key>\u001f<member>` format per member (`splitCollabStateEntries`). Concurrent additions and removals of different members merge. Reading is unchanged: NodeState joins the member entries back into the set (#9380). Block markers, wrappers and list groups still store the set whole. - A peer that does not know the state keeps each member as its own NodeState key and writes it back unchanged, so it never collapses the members. - The self-check's fresh editor gets the set-valued StateConfigs registered on the binding's editor, so it reads the members the same way (otherwise every write of a set would be reported to the binding's `onWarn` as a `'self-check'` warning). - Tests: the harness takes a `prepare(editor)` hook (run before the binding starts; fresh readers reuse it). The fuzz now stores comments as one set-valued state, like `MarkStateExtension`; `FUZZ_COMMENTS=keys` keeps the previous one-boolean-key-per-id model. `Size.test.ts` budgets three `MarkStateExtension` operations. - Docs: the "Set-valued NodeState" limit on the Yjs 14 collaboration page says where the set is stored per member and where it is still one value (paragraphs and list items, lists, links); the README's wire format adds the member entries (`s:<key>\u001f<member>` = `true`); the Comments and NodeState pages name `@lexical/y` among the bindings that store members separately. Bytes the editing client emits (`@y/y` 14.0.0-rc.29, gc off, pinned client ids), op / undo / redo: ``` one format per id whole set (before) add a comment 83 / 10 / 77 92 / 10 / 86 add an overlapping comment 83 / 10 / 77 196 / 45 / 190 remove one of two comments 12 / 142 / 10 113 / 144 / 113 ``` ## Test plan New `packages/lexical-y/src/__tests__/unit/MarkState.test.ts`: two peers (ids 1,2 and 2,1, causal and per-sender delivery) and three peers, with concurrent comments on the same and on overlapping ranges, across a line break, resolving while a peer types, resolving one of two comments, undo while a peer types, the stored format keys, and a peer that does not know the state editing commented text. ### Before `Schema.ts` and `SelfCheck.ts` reverted to the dependency commit: ``` $ npx vitest --project unit --no-watch --maxWorkers=1 packages/lexical-y/src/__tests__/unit/MarkState.test.ts packages/lexical-y/src/__tests__/unit/Size.test.ts × each id is its own format key (4 of 4 orders) AssertionError: expected [ 's:markIds' ] to deeply equal [ 's:markIds\u001fc1', …(1) ] × two peers mark the same range (4 of 4 orders) AssertionError: expected 'paragraph("Revenue " "grew 4%"[c2] " …' to be 'paragraph("Revenue " "grew 4%"[c1,c2]…' × two peers mark overlapping ranges (4 of 4 orders) × two peers mark overlapping ranges across a line break AssertionError: expected 'paragraph("a"[c2] "b"[c1] linebreak[c…' to be 'paragraph("a"[c2] "b"[c1,c2] linebrea…' × keeps each id as its own format when it edits marked text × add a comment (MarkStateExtension) AssertionError: expected 92 to be less than or equal to 90 × add an overlapping comment (MarkStateExtension) AssertionError: expected 196 to be less than or equal to 90 × remove a comment (MarkStateExtension) AssertionError: expected 113 to be less than or equal to 14 Tests 17 failed | 40 passed (57) ``` ### After ``` $ npx vitest --project unit --no-watch --maxWorkers=1 packages/lexical-y packages/lexical-yjs packages/lexical-mark packages/lexical-react/src/__tests__/unit/Collab packages/lexical/src/__tests__/unit/LexicalNodeState.test.ts Test Files 76 passed (76) Tests 3256 passed | 8 expected fail | 2 skipped (3266) ``` The 8 expected failures are `MarkStateCollab.test.tsx`'s pinned v2 and v1 limits from #9380 (#9381 is not in this stack). The 2 skipped tests are in `ListsInLines.test.ts` and are skipped on #9400 as well. Fuzz with comments as one set-valued state, on the whole stack (this commit on top), 2,000 seeds plus 500 gc seeds, without and with block moves (25 seeds per test): ``` $ FUZZ_SEEDS=2000 FUZZ_GC_SEEDS=500 FUZZ_MOVE_SEEDS=2000 FUZZ_MOVE_GC_SEEDS=500 \ npx vitest --project unit --no-watch packages/lexical-y/src/__tests__/unit/Fuzz.test.ts ✓ @lexical/y fuzz (100) ✓ @lexical/y fuzz with block moves (103) Tests 203 passed (203) ``` `pnpm run test-unit` on the whole stack: 444 files, 11,999 passed, 3 skipped. Also run: `pnpm run tsc`, `pnpm run flow` (0 errors), eslint and prettier on the touched files, `pnpm run build`, the tree-shaking tests (source 364 pass, build output 286 pass) and `pnpm run build-docs`. Not exercised: real Yjs 14 providers and browsers.
c456553 to
cd4b7e5
Compare
16c6136 to
a7e918e
Compare
a7e918e to
ffe3ca1
Compare
cd4b7e5 to
76444e5
Compare
76444e5 to
6b487b4
Compare
ffe3ca1 to
1d4155e
Compare
1d4155e to
d9c1545
Compare
6b487b4 to
21e445f
Compare
d9c1545 to
ed6b7ed
Compare
21e445f to
aeeccdf
Compare
aeeccdf to
f3d4116
Compare
ed6b7ed to
419777f
Compare
419777f to
62f1300
Compare
f3d4116 to
88aaa2d
Compare
There was a problem hiding this comment.
Thanks for the detailed write-up and the wire-format docs. The move-record design is easy to follow, and the deterministic concurrency cases in Moves.test.ts (three peers, four id and delivery orders, exact converged text on every peer and a fresh reader) are thorough. Two things need to change before this can merge.
1. Rebase onto the landed stack. The base pull request (#9439) has merged, and the base branch was rebased after #9400, #9437 and #9438 landed. This branch still carries the earlier revisions of those commits, so GitHub shows 288 changed files and reports conflicts. Even rebasing only the move commit (5a2870b) onto the base conflicts in Binding.ts, Cursor.ts, Write.ts, constants.ts, Lifecycle.test.ts, Storage.test.ts, the README and y.md, because the binding changed underneath it. Please rebase the move commit alone onto main, retarget the pull request, and rerun the tests and fuzz there. The current results are for the old binding.
2. Moves need a new layout number. On the base, lexical-y:2 already means member entries of set-valued NodeState (SET_MEMBERS_LAYOUT_VERSION = 2), and the base README says layout 3 is planned for this pull request. This branch assigns MOVES_LAYOUT_VERSION = 2 (packages/lexical-y/src/internal/constants.ts:38) and documents moves as layout 2 (packages/lexical-y/README.md:197, packages/lexical-website/docs/collaboration/y.md:890 and :898). If both meanings are kept, a client that knows only the set-member layout 2 opens a room with move records as writable and shows moved blocks at their old place. The README's wire-format rule is that a change to how stored data is read gets a new version, and AGENTS.md asks that stored content stay readable across versions. Please take the next free version on the branch you rebase onto, and update the README, y.md, the layout test and the "move a block" byte budget.
Optional, non-blocking suggestions:
Fuzz.test.ts:135drops everylossanddupsignature in the move seeds, so the fuzz never checks the main claim, that same-container moves neither lose nor duplicate text. Consider allowing only the documented cross-container cases. Also consider keepingloss-concurrent-moves-of-one-paragraph-s6372.jsonreplaying with its new expected outcome, or saying which documented limit it now hits.State.movesis alwaystrue(State.ts:363), so the first move by an upgraded client puts every older client of that room into read-only mode. An opt-in binding option would let deployments upgrade their clients first.formatsAfterItem(Moves.ts:834) walks the container from its first item on every jump into or out of a join range, and on every gap of a structure write. Consider measuring typing, Enter and Backspace next to records at 10,000 blocks, or reusing the one-walk format tablesMoveRead.tsalready builds.- Per CONTRIBUTING.md, add a changeset after the rebase, for example
.changeset/lexical-y-moves.mdwith'@lexical/y': patchand[feature] Move blocks within a container in @lexical/y with move records, so text a collaborator types in a moved block moves with it. - Rebase rather than merge: a merge would also bring back an outdated comment on
LexicalEditor._recordNodeMoves(packages/lexical/src/LexicalEditor.ts:1184).
| /** The version a new document records. */ | ||
| export const BASE_LAYOUT_VERSION = 1; | ||
| /** The version of a document holding move records or lifted blocks. */ | ||
| export const MOVES_LAYOUT_VERSION = 2; |
There was a problem hiding this comment.
On the base, lexical-y:2 already means member entries of set-valued NodeState (SET_MEMBERS_LAYOUT_VERSION = 2), and the base README plans layout 3 for moves. With both meanings, a client that only knows the set-member layout opens a room with move records as writable and shows moved blocks at their old place. Please take the next free version on the branch this is rebased onto, and update the README, y.md, the layout test and the byte budget to match.
| const sigs = res.failures | ||
| .map(f => f.sig) | ||
| .filter( | ||
| s => !allowed(s) && !s.startsWith('loss') && !s.startsWith('dup'), |
There was a problem hiding this comment.
Optional: this drops every loss and dup signature in the move seeds, so a same-container move that loses or duplicates text still passes. Consider allowing only the documented cross-container cases (the harness already tags delete-wins tokens as container).
| /** Containers that hold (or held) move records, and their ownership. */ | ||
| private readonly withMoves = new WeakSet<YNode>(); | ||
| /** Write moved units as move records (off: as a delete and a reinsert). */ | ||
| moves = true; |
There was a problem hiding this comment.
Optional: moves is always true and no binding option changes it, so the first move by an upgraded client puts every older client of that room into read-only mode. An opt-in option that keeps writing a delete plus a re-insert until a deployment enables moves would allow a rolling upgrade.
| * Physical formats right after `item` (null: at the start) in its | ||
| * container: every format item before it applies, whatever its zone. | ||
| */ | ||
| export function formatsAfterItem( |
There was a problem hiding this comment.
Optional: this walks the container from _start on every call. The cursor, readAtoms, $pieces and Writer#formatsAfter call it on every jump into or out of a join range and on every structure-write gap, so typing and Enter in a container with records cost O(items). Consider reusing a one-walk table, as MoveRead.ts and Reader#pz do, or measuring this path at 10,000 blocks.
Stacked on #9439 (the
@lexical/ystack: #9400, #9437, #9438, #9439). ThisPR is now last in the stack.
Today a block move in
@lexical/yis a delete plus a re-insert: the bindingre-creates the cheaper side, so text a collaborator types into the moved
block at the same time lands in its old neighbour, and two collaborators
moving the same block can duplicate it. The normalization repairs every peer
runs (a block lifted out of the paragraph it was written in) are written the
same way, so two peers that lift one block from different surroundings both
re-create it, and text typed into it meanwhile is lost. (On #9400 v3 the
author normalizes its own write instead of every peer repairing it; see
"Lifted blocks" below.)
A move now keeps the moved items where they are and writes a small move
record where the block shows. A move changes only position, never the moved
content's characters.
↷is a childY.Nodeof the container. It names arange of the container's own sequence by Yjs item id (
sis the itembefore the range, or none;
eis the range's last item) and has a priorityp. Items a peer inserts later inside the range (typing, Enter) belong toit too. This ports the semantics of Yjs' unmerged range move (ContentMove:
highest priority wins, loops are broken) to binding-level records. Yjs 14
has no native move.
belongs to the active record of highest priority (then client, then clock)
whose range holds it. A record placed inside its own range, directly or
through other records, shows nothing. Nothing is repaired or written back.
A record written again keeps its rank (
o). A write that splits an anchoritem (typing inside the last word of a range) keeps the range: anchors
resolve to the item holding their id.
its item is in, so text typed concurrently at a line start stays in its
line. Formats stay positional, as in Yjs.
Delete, a deletion across lines) writes join records (
j: 1) at the endof the first line's text. They show the second line's text in their place,
so the joined line can span ranges and the second line's characters are
never copied. A second line that is not one range (a block moved away
from between its parts, or it starts inside a joined range) gets one join
record per piece. Two peers that make the same join write records of the
same ranges; one wins and the other shows nothing, so the text appears
once.
joined line, or joined across a moved range, is moved with one join record
per piece but its last (written at the start of the last piece) and a
block record over the last piece, instead of being re-created.
table appended to a paragraph without the normalization, an older client)
keeps its shared node when the normalization lifts it out (on [lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400 v3,
the normalization of its author) (a line written
inside a line, such as a heading in a list item, is stored as lines by
[lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400 and needs no lift): the node is
marked a unit of its container (
u: 1on thei:<type>node), whichsplits the line around it, and the line parts get markers. (The earlier
design, where every peer lifted it under a content-derived client id, is
gone with [lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400's shared repairs.) Lexical replacing such a block by a new one of its type (Enter at
its start) keeps the shared node too.
characters when the line around it changed at the same time: a peer
joined the lines around it (the record is inside the joined range), or
removed the line before it while another typed in that line. New units
then go right after the block the record shows only when that is a line
boundary, otherwise right before the next line, and when the block shows
from inside that next line it is written again with a record where it
shows. A moved line that such a record interrupts moves with its pieces
(its text before the record too). A record is written again at its line
start only when the same records stay active (moving it out of another
record's range can make a record that showed nothing show its range).
holds a record" or "this write lifts a block". The per-keystroke cost,
size, 10k-edit growth and load time of documents that never move are
unchanged, and Enter and Backspace there are within 3% of [lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400.
structural edit in a container with records re-parses only windows around
the records whose ownership changed. Each window is bounded by end items
its zone owns before and after the change, so a unit keeps its node only
when its content provably did not change. Format edits, join records and
unresolved records still read the whole container.
ownership is checked against the document (records deleted, anchors
split or merged) once after each transaction starts and once after Yjs
cleans one up, instead of on every use; inside a transaction it is still
checked on every use. Which records are active, and the ownership before a change in an
incremental read, come from a painted index instead of a scan of the
records per position. An incremental read takes formats from one walk of
the container, and the check for records left inside a line stops where
the previous record's check stopped. Nothing written changes: the updates
of a scripted session and of every fuzz session are byte-identical before
and after. At 10,000 random moves on 1,000 blocks (every block moved,
1,000 live records), a local move goes from 347 to 34 ms, a remote read
from 1,049 to 27 ms and a load from 647 to 46 ms ([lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400: 5.1, 3.6 and
27 ms). What is left grows with the container's items, deleted records
included.
Yjs collects garbage (a delete and a re-insert on [lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400 leaves 16.5 B).
Live records stay at most one per moved range, apart from rare cases (a
block moved back to where it was, a record that lost a loop, a record
whose range a peer deleted, until the next local write of that
container), tracked in [lexical-y] Bound move records over time (follow-up to #9449) #9455.
NodeKey under the same container) recognizes the moved units. The records
go to the units the user moved, and a whole range that moves again reuses
its record.
and whole lists), a table (rows), a row (cells, so column moves), a cell's
or collapsible's content, and block decorators and containers moved as
units. A move into another container is still a delete plus an insert
(documented).
typing. Redo writes it again. A local write that deletes a record can let
another record show. The writer then reads the container again, as a peer
would.
lexical-y:1: true). Thefirst move record, join record or lifted block adds
lexical-y:2: trueto[lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400's monotone layout record, in the same transaction as the record (so
no client ever receives a record without the version), and undo never
deletes it; nothing else is rewritten. Clients without moves then open it
read only instead of misreading it, and the record never shrinks.
LAYOUT_VERSIONisnow 2, and documents without moves stay editable by older
@lexical/ybuilds. The README's wire format section documents layout 2 (records, join
records, lifted blocks, the upgrade) next to the frozen layout 1.
repair exceptions for containers with records.)
onWarnasLexicalWarnings, and the codeuses the binding's read-only getters.
On main, the update that flips a node's
isInline()lifts the node itself(the normalization runs on what an update writes), so the flip is written as
a block of its container, not as an inline node a later repair lifts in
place; this PR therefore leaves
IsInline.test.tsas #9400 has it.Prior art. We studied Bob Ippolito's etrepum#65, which gives
every node its own Yjs node and moves a node by writing a
{id, token}placement into its new parent. We chose instead to port Yjs's own unmerged
range-move design (
ContentMoveon themovebranch: a record at thedestination points at the moved range, the higher priority wins, loops are
broken) as binding-level records. Our reasons: splits and joins stay cheap
marker edits, documents pay nothing until something moves, and #65's
per-node layout has known cases where a split or join racing a collaborator's typing loses or
misplaces that typing (marked as expected failures in its tests). Credit to
one format key per mark id, the same as the follow-up #9439.
No change to
lexical,@lexical/yjsor any other package. Docs: they.mdpage's "Wire format" section, which #9400 starts with a diagram oflayout 1, gains diagrams of layout 2 (a move record next to the order the
editor shows, and a join record) and of the upgrade from 1 to 2, checked
against a dumped document, and links the README's layout 2 specification; its limits
describe moves within and across containers, joins, and layout version 2.
Its limits also cover text typed into a block moved out of a container that
a peer removes or moves (lost), the same block moved into two containers
(shown twice), and an undo of a removal racing a move out of the removed
range (shown twice), and how records and tombstones grow over time, with
the Yjs advice to reload long-lived rooms on the server. The README's wire
format documents layout 2, and its
fuzz note lists the moves fuzz variables.
@lexical/yis unreleased and@experimental.Adapted to #9400 v3 in this rebase: the layout test now checks the record
(
lexical-y:1andlexical-y:2=true), that the version is written inthe transaction of the first move record, and that undoing the move keeps
it; the two "lifts in place" tests deliver the author's normalization with
its write (receivers no longer lift); the "move a block" byte budget is
108 (was 104: the record's attribute is now part of the move's update). Also
pnpm run test-unitcompared test by test with #9439 (0 failed, 0 changed;the replay of a fixture this PR deletes no longer runs),
pnpm run tsc,tsc-test,tsc-scripts,tsc-website,tsc-extension,pnpm run flow(0 errors),
pnpm run lint,pnpm run prettier, the tree-shaking tests (369source, 286 built),
pnpm run build-prodandpnpm run build-docspass.The rest of this test plan is from the previous base (#9400 before its v3
rework) and is re-measured in the fix round.
The new tests against the previous revision of this change (joins of lines
that are not one range copied, lines that span ranges re-created, repairs
written as a delete and a re-insert):
Randomized normalization fuzz, 2,000 seeds (3 peers, 40% of edits written
without the normalization, peers typing into the same blocks, partial
delivery): 490 sessions copied or lost text: 102 sessions
without a nested line (101 with a copied block, 1 with a lost token) and
388 with one (a heading a peer wrote inside a list item: 387 copied, 2
lost).
Fuzz.test.ts/ the fuzz utilities: a token a peer moves into a table,box or column counts as lost by delete wins when another peer made a
removal, exactly like a token typed there. Duplicates are not excused.
Block id integration (BlockIdExtension on this change), moves fuzz, 2,000
duplicated text (joins written as a copy, lines that span ranges moved as
a delete and a re-insert).
This revision's fixes, against the previous revision of this change (a
record left inside a line by concurrent edits: a unit written after the
block it shows split the line, and a moved line left its text before the
record behind; a heading written inside a list item stored as its own
node):
The normalization fuzz at 2,000 seeds copied text in 8 sessions and lost
it in 2, all with a heading written inside a list item. The block id
moves fuzz with undo and redo off failed 2 of 2,000 seeds (162: a
self-check mismatch after a move; 741: a self-check mismatch and lost
text after a new line was written next to a moved block). Enter and
Backspace in a 10,000 paragraph document without moves took 71.2 and
71.5 ms against 67.0 and 66.8 ms on [lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400 (3 alternating runs, +6%).
A move at 10k blocks with 100 earlier moves on [lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400 without this change:
[lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400 writes a move as a
delete and a re-insert, 78 ms end to end with 100 earlier moves at 10,000
blocks (its undo writes 131 B).
Many moves, before this revision's caching (1,000 blocks, gc on): at
10,000 random moves (1,000 live records) a local move took 347 ms, a
remote read of it 1,049 ms and a load 647 ms, against 5.1, 3.6 and 27 ms
on [lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400; at 1,000 moves (634 live records), 24.5, 16.1 and 400 ms.
Re-run on this revision (main with the final node structure, #9452, and the
updated #9400): the commands above; the moves fuzz at 2,000 + 500 gc seeds
through the same counting harness as before: 26 and 7 seeds with lost or
duplicated text, the same seeds as on the previous base, and 1,997 of 2,000
and 498 of 500 sessions write byte-identical updates (the other 3 + 2 differ
where main's normalization now runs in a local update); the block id
integration (moves fuzz, 2,000 + 500 gc: duplicated text on 882 and 1993
only, as before; the BlockIdExtension fuzz, 2,000 seeds, passes); and the
collab Y e2e suite in Chromium (26/26) and Firefox (23 passed, 3
Chromium-only skips). From the previous base and not re-run: the 25,000 +
5,000 gc moves fuzz, the differential, the scripted byte-identity session,
the block id run with undo and redo off, the playground drag spec, and the
perf and many-moves tables below.
Moves.test.ts(249 tests, most in 4 orders) covers:neighbour moves, move ‖ delete, move ‖ retype, move ‖ bold, move ‖
Enter;
Delete, both, a range across a moved line), join ‖ split, join ‖
typing, join ‖ move, split ‖ move, undo of a join, a join ‖ an undo
that restores a line inside the joined range;
typing in it and ‖ another move), a line another zone interrupts moved
‖ typing in both parts and joined ‖ typing and ‖ the same join, and a
line that ends inside a joined range moved and then typed in, a block
shown from inside a joined line ‖ a new line right after it, and a line
typed into after a removal, shown around a record, then moved (each
checks that the result is exactly the writer's intent);
item, table row ‖ type and column ‖ type, container ‖ type, block
decorator;
layout bump, no record for documents that never move, and reads that
stay incremental.
document after every step, across undo and redo with a peer typing,
records that arrive out of order, a record whose anchors arrive late,
text anchors split by typing (with and without gc), anchors merged by
gc, and a moved block deleted with its old neighbour under gc. Taking
out the anchor check fails them.
NormalizationConvergence.test.ts: the 3-peer matrix (18 violations × 8delivery schedules × 6 id orders) passes 864/864; new lift tests (a block
lifted out of the middle of a line ‖ typing next to it and in it, two
blocks written at the end of one line by two peers and lifted by a
third, a heading written inside a list item ‖ typing in it, a block put
inside such a heading and lifted from other surroundings; 6 id orders ×
2 deliveries each) check the text, the stored node (
u, no copy, noi:heading) and the layout bump. The randomized fuzz fails on anycopied or lost token, in every session, and always runs the seeds that
failed during this work. A second randomized fuzz adds edits that write
plain paragraphs into quotes and list items (joined into them as lines by
the normalization) and new quotes, starting from a document with a quote
and a numbered list. Both pass at 2,000 and 10,000 seeds each (0 copies,
0 losses).
Fuzz with block moves (the whole stack): 2,000 + 500 gc and 25,000 + 5,000
gc seeds, 0 absolute findings (divergence, exceptions, fragments,
self-check, fresh readers). The fuzz now counts a block moved into a
container a peer removed as delete wins, as it already did for text typed
into one. Seeds with lost or duplicated text: 26 of 2,000 (1.3%; 69 before
that accounting change), 7 of 500 gc (20 before), 278 of 25,000 (1.1%; 767
before) and 52 of 5,000 gc (157 before). All of them are documented
limits: two peers moving the same block when one moves it into another
container (shown twice), a move into another container racing a move of
its container or an undo of a removal (shown twice), text typed into a
block a list conversion lifts, and joins written as a copy.
Fuzz.test.tsat 2,000 + 500 seeds with and without moves passes, including a regression seed (a comment over a line joined with a line of
two pieces, then an undo).
Differential
against v2, 2,000 + 500 gc: 0 absolute findings, 5 + 1 seeds worse than
v2.
This revision writes exactly what the previous one wrote. Every update
of a scripted two-peer session (900 steps of moves, typing, Enter,
joins, removals, undo and redo, with and without gc), of the moves fuzz
(2,000 + 2,000 gc and 25,000 + 5,000 gc seeds, every peer's updates
hashed per seed) and of 10,000 random moves is byte-identical before and
after, and the fuzz findings, the differential (the same 5 + 1 seeds)
and the block id runs below are unchanged.
Block id integration (BlockIdExtension on this stack): the moves fuzz,
2,000 + 500 gc seeds, has 0 divergence, 0 self-check warnings and 0 lost
text; 2 + 0 seeds show duplicated text (882, 1993): in both, two peers
remove the same text and both undo the removal, and each undo restores
its own copy, which Yjs does with plain
Y.Texttoo (no move isinvolved). With undo and redo off, 2,000 + 500 seeds have no finding
(162 and 741 failed before). The BlockIdExtension fuzz, 2,000 seeds,
passes.
Many moves (1,000 blocks; ms: local move, remote read of it, load; mean
of the last 50 moves, median of 3 loads; [lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400 / before / after):
A keystroke in a moved block stays at 2.2 to 4.6 ms ([lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400: 2.2 to 3.0).
Sizes are unchanged (235 KB after 10,000 random moves with gc, 157 KB on
[lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400). The remaining cost grows with the container's items, deleted
records included, which Yjs keeps in the sequence.
Perf at 10,000 blocks (end to end, shared machine, [lexical][lexical-devtools][lexical-extension][lexical-list][lexical-website][lexical-y][lexical-yjs] Feature: @lexical/y, an experimental Yjs 14 collaboration binding #9400 → the top of
the stack): Enter and Backspace in a document without moves, median of
the per-round ratio over 6 alternating rounds, +0.0 to +0.5% at the top
of the stack and -1.8 to +1.3% with this change alone (+6% for the
previous revision); keystroke 38.7 → 38.6 ms (list item 47.9 → 46.3),
load 195 → 193 ms, size, 10k-edit growth and bytes per edit identical; a
move 97 → 124 ms (131 → 106 B), its undo 69 → 73 ms (131 → 11 B).
Playground (
?isCollab=true&useCollabY=true, the stack's playgroundmode, a scratch spec): drag a block while the other tab types in it, a
list, a list item, a table row, undo, and the same block dragged twice:
Chromium 21/21 (3 repeats), Firefox 7/7, WebKit 7/7; the collab Y e2e
suite passes in all three (26/26, 23/23 + 3 Chromium-only IME skips).
On this commit:
pnpm run tsc,tsc-test,tsc-scripts,pnpm run flow(0 errors),
pnpm run lint,pnpm run prettier, the source tree-shakingtest (368 passed),
pnpm run build-prodand the built tree-shaking test(284 passed).