Repository navigation
[lexical-y][lexical-website] Bug Fix: A code highlighter's re-tokenization of a held code line is not written onto the block a collaborator made of it - #9835
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
49dc00a to
e321a21
Compare
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: |
|
AI review status for this pull request.
|
There was a problem hiding this comment.
This looks good, thanks: the joined paragraph or list item now keeps its underline and comment marks on its own words on every peer and a fresh reader, and the new regression file fails on main and passes here. The suggestions below are optional and non-blocking.
1. The rule also catches other re-typing transforms (packages/lexical-y/src/internal/HoldGuard.ts, lines 310-341). $reshapesRestyledLine refuses any update that keeps the composed line's text but changes the type of a node holding it, not only code highlight tokens. With registerLexicalHashtag, a hashtag that forms when a composition ends while a collaborator's alignment change (or heading change) is held is refused, and since the re-read runs without transforms it never forms: every client converges on paragraph/center[aa #tag], where main gives aa followed by a HashtagNode for #tag, until that text is edited again. No text or format is lost, but the JSDoc's "the transforms then run on what is stored" (lines 304-305) does not hold here. Narrowing the rule to code highlight nodes in a line whose stored type is not code, or running the author's transforms on the owner line after the re-read, would cover it, and a hashtag case in ComposeHoldRestyledLineTransform.test.ts would pin it (packages/lexical-y/AGENTS.md: every bug fix lands with a regression test).
2. Document the warning-free refusal. packages/lexical-website/docs/collaboration/y.md describes a refusal for the hold as reported with 'held-composition' (the UNSUPPORTED_EDIT_WARNING row), and its "Input method composition" limit does not mention this case. packages/lexical-y/AGENTS.md asks a pull request that makes a consequential decision or accepts a new limit to add its DECISIONS.md row and the y.md Limits entry in the same pull request.
3. Smaller points
HoldGuard.tslines 278-284: the reader (Read#$lineFromMarker) reads a line whose stored type is not registered asparagraph, but$showsRestyledcompares the raw stored type, so it reports a restyle under any hold on such a line.convergedin the new test could also assert thatpeer.warningsis empty, which pins the no-warning behaviour.heldQuietinBinding.tsis instance state reset on one path only; returning the flag with'held'would keep it per write.- The tests model Chromium's composition end. Firefox ends a composition inside the following input event and desktop Safari inside
insertFromComposition; where that update also changes the line's text, the rule does not fire. A collab-Y e2e case would show which happens.
e321a21 to
37d605a
Compare
There was a problem hiding this comment.
This looks good to me. The rule is well targeted at the case in the description: storage keeps the joined line's underline and per-word comment ids instead of code-highlight tokens, the edit of another line in the update that ends the composition is now stored, and the new regression file covers gc on and off, both client orders and a fresh reader. The two points below are optional and non-blocking.
Optional: narrow the restyle test so it does not catch entity transforms (packages/lexical-y/src/internal/HoldGuard.ts:269-271)
$showsRestyled returns true for any held marker change, not only for a stored type that differs from the shown one, and $reshapesRestyledLine accepts any change of leaf node types. A hashtag that registerLexicalHashtag forms when a composition ends (Lexical skips transforms on the node being composed, so aa #tag is split in the update that clears the composition key) is then left out of the write whenever a collaborator centered that line during the composition. The line is read back with skipTransforms, so every client and a fresh reader end with #tag as plain text in the centered paragraph until it is edited again, where main stores the hashtag; a held heading change, or none, behaves as on main. With these three lines removed, ComposeHoldRestyledLineTransform.test.ts and the existing composition, hold and recovery tests still pass, and the hashtag is stored again, because the code-join case is still caught by the stored-type and deleted-marker checks below. If the broader rule is intended, packages/lexical-y/AGENTS.md asks for a DECISIONS.md row and a line in y.md's Limits, and the changeset wording ("a type its stored counterpart no longer has") would need to match. A hashtag case under a held alignment change would make a good extra regression test either way.
Nit: the re-read does not run transforms (packages/lexical-y/src/internal/Binding.ts:6780)
The comment here, the doc comment of $reshapesRestyledLine (HoldGuard.ts:309-310) and the description say the line is read again so the transforms run on what is stored, but the re-read runs with skipTransforms: true (guardedRead and queueReread). The code-join result is still right because storage already holds plain text there; "it is read again as stored and the hold ends" would describe it exactly.
The earlier note on HoldGuard.ts:279-289 (an unregistered stored type kept as the raw string, while Read#$lineFromMarker reads it as paragraph) still applies and is also optional.
37d605a to
d91d5a5
Compare
There was a problem hiding this comment.
This looks good to me. Storage now keeps the joined line's underline and per-word comment ids instead of code-highlight tokens, this revision also stores a NodeState value set on a kept token and an edit of another line in the update that ends the composition, and the new regression file covers gc on and off, both client orders and a fresh reader. Everything below is optional and non-blocking.
Optional: narrow the restyle test so it does not catch entity transforms (packages/lexical-y/src/internal/HoldGuard.ts:300-302)
$showsRestyled returns true for any held marker change, not only for a stored type that differs from the shown one, and $reshapesRestyledLine accepts any change of leaf node types. A hashtag that registerLexicalHashtag forms when a composition ends (Lexical skips transforms on the composed node, so aa #tag is split in the update that clears the composition key) is then left out of the write whenever a collaborator centered that line during the composition: $writeSkippedLine keeps its characters as stored because the hashtag node is new, and the re-read runs with skipTransforms. Every client and a fresh reader end with #tag as plain text in the centered paragraph until it is edited again, where main stores the hashtag; a held heading change, or none, behaves as on main. With these three lines removed, ComposeHoldRestyledLineTransform.test.ts and the existing composition, hold and recovery tests still pass and the hashtag is stored again, because the code-join case is still caught by the stored-type and deleted-marker checks below. If the broader rule is intended, packages/lexical-y/AGENTS.md asks for a DECISIONS.md row and a line in y.md's Limits, and the changeset's "a type its stored counterpart no longer has" would need to match.
Optional: draw the re-typing transform from the node catalog (packages/lexical-y/src/__tests__/unit/regressions/ComposeHoldRestyledLineTransform.test.ts)
packages/lexical-y/AGENTS.md asks tests to draw inputs from src/__tests__/catalog/, whose nodes.ts holds the TextNode subclasses entity transforms make (hashtag, mention, keyword, emoji). One case per subclass under a held alignment or heading change would pin the point above whichever way it is decided.
Nit: the re-read does not run transforms (packages/lexical-y/src/internal/Binding.ts:6780)
The comment here, the doc comment of $reshapesRestyledLine (HoldGuard.ts:340-341) and the description say the line is read again so that the transforms run on what is stored, but the re-read runs with skipTransforms: true (guardedRead and queueReread). The code-join result is still right because storage already holds plain text there; "it is read again as stored and the hold ends" would describe it exactly.
Nit: an unregistered stored type (packages/lexical-y/src/internal/HoldGuard.ts:312-320)
A stored type this client does not register stays the raw string here, while Read#$lineFromMarker reads such a marker as paragraph, so $showsRestyled returns true under any hold on such a line; the same fallback would match what the reader makes.
For context only: the rule applies when the update that ends the composition keeps the line's text. If that same update also changes the composed text, the highlighter's tokens are still stored on the joined paragraph, exactly as on main.
d91d5a5 to
a7e1c76
Compare
There was a problem hiding this comment.
This looks good to me. Storage now keeps the joined line's underline and per-word comment ids instead of code-highlight tokens, an edit of another line and a NodeState value set on a kept token in the update that ends the composition are still stored, and the regression file covers Prism and Shiki, gc on and off, both client orders and a fresh reader. Everything below is optional and non-blocking.
Optional: narrow the restyle test so it does not catch entity transforms (packages/lexical-y/src/internal/HoldGuard.ts:300-302)
$showsRestyled returns true for any held change of the line's marker attributes, not only for a stored type that differs from the shown one, and $reshapesRestyledLine accepts any change of leaf node types. A hashtag that registerLexicalHashtag forms when a composition ends (Lexical skips transforms on the composed node, so aa #tag is split in the update that clears the composition key) is then left out of the write whenever a collaborator centered or indented that line during the composition: $writeSkippedLine keeps its characters as stored because the hashtag node is new, and the re-read runs with skipTransforms. Every client and a fresh reader end with #tag as plain text until it is edited again, where main stores the hashtag; a held heading change, a join, or no held change behave as on main. With these three lines removed, the hashtag is stored again and the composition, hold and recovery tests, this PR's included, still pass, because the code-join case is still caught by the stored-type and deleted-marker checks below them. If the broader rule is intended, packages/lexical-y/AGENTS.md asks for a DECISIONS.md row and a line in y.md's Limits, and the changeset's "a type its stored counterpart no longer has" would need to match.
Optional: draw the re-typing transform from the node catalog (packages/lexical-y/src/__tests__/unit/regressions/ComposeHoldRestyledLineTransform.test.ts)
The Testing section of packages/lexical-y/AGENTS.md asks tests to draw inputs from src/__tests__/catalog/, whose nodes.ts holds the TextNode subclasses entity transforms make (hashtag, mention, keyword, emoji). One case per subclass under a held alignment, indent or heading change would pin the point above whichever way it is decided.
Nit: the re-read does not run transforms (packages/lexical-y/src/internal/Binding.ts:6780)
The comment here, the doc comment of $reshapesRestyledLine (HoldGuard.ts:340-341) and the description say the line is read again so that the transforms run on what is stored, but the re-read runs with skipTransforms: true. The code-join result is still right because storage already holds plain text there; "it is read again as stored and the hold ends" would describe it exactly.
Nit: an unregistered stored type (packages/lexical-y/src/internal/HoldGuard.ts:310-320)
A stored type this client does not register stays the raw string here, while Read#$lineFromMarker reads such a marker as paragraph, so $showsRestyled returns true under any hold on such a line; the same fallback would match what the reader makes.
a7e1c76 to
579f8bf
Compare
There was a problem hiding this comment.
This looks good. The regression test is thorough: it fails on main, passes here, and checks both peers and a fresh reader. A few optional, non-blocking suggestions:
- A held alignment change also drops other transforms' output (
packages/lexical-y/src/internal/HoldGuard.ts, lines 300-302).$showsRestyledreturns true for any held marker change, so the new rule also catches transforms that store correctly. For example, withregisterLexicalHashtag, A composes#tagin a paragraph while B centres that paragraph. When the composition ends, the hashtag transform makes aHashtagNode, the line is skipped and re-read without transforms, and every client converges on centred plain text, wheremainstores the hashtag. No text is lost, and the hashtag only comes back when that text is edited again. The code-block join is still caught by the stored-type and deleted-marker checks below these lines, and the new tests pass without them. If the broader rule is intended,packages/lexical-y/AGENTS.mdasks for aDECISIONS.mdrow and an entry in the Limits section ofpackages/lexical-website/docs/collaboration/y.md. - A composition that ends together with a text change is not covered (
HoldGuard.tsline 368: the composed line's text must be unchanged). Lexical can change the text in the update that ends the composition: its Firefox path runs$updateSelectedTextFromDOMand$onCompositionEndImplin one input update, and desktop WebKit'sinsertFromCompositionhandler clears the composition key and inserts the text in one update (packages/lexical/src/LexicalEvents.ts). In that shape (key cleared and text spliced in one update), code highlight nodes are still stored on the paragraph, as onmain. A test for it, or a note in the docs, would make the fix's scope clear. - Nits:
$showsRestyledcompares a stored line type this client does not register as its raw string (lines 315-320), while the reader turns such a line into aparagraph(Read.ts,$lineFromMarker). And the comments atBinding.tsline 6780 andHoldGuard.tslines 340-341 say transforms run on the re-read line, but the re-read usesskipTransforms: true.
ada3322 to
c33ccf7
Compare
|
The head is now c33ccf7. When a held composition ends, the line is read as stored and its transforms run again, and only changes that agree with what the composer's own update would have written are saved: per character and per attribute (node type, each format bit, each NodeState value), keyed by the stored character, so text is never written, other blocks are never touched, and deleted characters are skipped. The carry snapshot now counts an inline decorator as one character. y.md, the warning text and D114 describe the rule. Please run a full review of the current head. |
There was a problem hiding this comment.
This looks good to me. Narrowing the restyle check to a changed block type or a removed marker, covering the reordered-container and Firefox/WebKit composition-end cases, and adding D114 with its y.md Limits entry address the earlier threads. A few optional, non-blocking suggestions:
- A marker change in the update that ends the composition is dropped after a held join. The code is at
packages/lexical-y/src/internal/Write.tslines 719-726, and the premise is stated in the$writeSkippedLinecomment at lines 3252-3253. Join the code block into the paragraph before it. Then, in the update that ends the composition, callline.setFormat('center')orline.setIndent(1)on that line. Every client and a fresh reader end with an uncentred, unindented paragraph, while the same call in an update of its own is written. The warning message, theWarnings.tsJSDoc, the y.md warnings row and D114 all say the rest of the update is written. Either option closes the gap:- write the marker attributes the update changed on the shown line (format, indent, direction, element NodeState) from
$writeSkippedLine; - or name the limit in D114 and y.md's Limits, as
packages/lexical-y/AGENTS.mdasks for accepted limits.
- write the marker attributes the update changed on the shown line (format, indent, direction, element NodeState) from
- The changeset's
Verify:names no browser (.changeset/lexical-y-held-view-transform-write.md, line 7). Per y.md and D114, a composition that ends in the update inserting its text keeps the previous behavior: Firefox'sinputpath and desktop WebKit'sinsertFromCompositionboth do that. Naming a Chromium-based browser would make the check reproducible, since CONTRIBUTING.md asksVerify:to say what to test. converged()in the new regression test (ComposeHoldRestyledLineTransform.test.ts, lines 503-516) checks the views andpeer.errors. It does not check the harness'sexpectConvergedinvariants: noself-checkwarning and nocould not be writtenrecovery. Both hold for every cell today, and asserting them would stop a later change from passing these cells through a silent recovery.
c33ccf7 to
17fef22
Compare
|
The head is now 17fef22. Two fixes in the release after a held composition: (1) when a transform replaces the block during the re-run, the line that now holds its children is found and its result is compared with the record, so an agreeing entity is still written on the stored characters; (2) the release joins the undo step of the update that ended the composition whatever captureTimeout is, while that step is still on top of the undo stack. Please run a full review of the current head. |
17fef22 to
2bd8012
Compare
|
The head is now 2bd8012. When a transform replaces the block during the release and spreads its children over several lines, every line that update changed is now compared, and each stored character is found by its text in those lines, so an agreeing entity on characters that moved to another line is still written. What is written is still only the recorded value where the re-run agrees. Please run a full review of the current head. |
2bd8012 to
d92c091
Compare
|
The head is now d92c091. The text matching from the previous head is removed. When an app transform restructures the held line as its transforms run again (it replaces the block, or moves the line's text nodes into another line), nothing is saved for that line and it stays as stored; y.md, D114 and the commit message state this. A collaborator's split or join before the release is not a restructuring. Please run a full review of the current head. |
|
The head is now 1a9cd70: docs and tests only on top of d92c091 (the runtime is unchanged). The limit sentence now reads: "If an app transform restructures the held line or rewrites its text when its transforms run again (for example, one that converts, moves or upper-cases blocks of the converted type), what changed is kept as stored." Please run a full review of the current head. |
There was a problem hiding this comment.
This looks good to me: a held code-block join now keeps the paragraph's underline and comment marks on every peer and in a fresh reader, and the release path that re-runs transforms on the stored line is well covered (the new regression file fails 252 of its 480 cells on the merge base and passes them all here). The suggestions below are optional and non-blocking.
packages/lexical-y/src/internal/Binding.ts:6829-6831: an app'sstopCapturing()is overridden. WhenlastChange <= 0, which is exactly whatY.UndoManager#stopCapturing()leaves, the release setsum.lastChange = Date.now()to force the join, and Yjs then keeps the merge's time, so the author's next edit joins the composition's undo step as well. With an update listener callingbinding.undoManager.stopCapturing()as the composition ends and the author then typing in another line, one undo onmaintakes back only the typing; here it also takes back the bold and the hashtag from the update that ended the composition. Remembering thatlastChangewas<= 0and setting it back to0in thefinallykeeps both the join and the app's boundary; with that change all 480 cells still pass.packages/lexical-y/src/internal/Write.ts:719-726: a same-update alignment or indent on the joined line is dropped (the existing thread on line 724).$writeSkippedLinewrites only character formats and NodeState, sosetFormat('center')orsetIndent(1)in the update that ends the composition is lost after a held join, while the warning text, theWarnings.tsJSDoc, the y.md row and D114 say the rest of the update is written. Either write the marker attributes the update changed, or name this limit in D114 and y.md's Limits, aspackages/lexical-y/AGENTS.mdasks for an accepted limit..changeset/lexical-y-held-view-transform-write.md:7: name a browser inVerify:. The docs say Firefox'sinputpath and WebKit'sinsertFromCompositionkeep the old behaviour, so the paragraph as written shows the old result there; CONTRIBUTING.md asksVerify:to say what to test.ComposeHoldRestyledLineTransform.test.ts:504-517: assert the harness invariants inconverged(). AddingexpectConverged's no-self-check-warning and no-could not be writtenchecks still passes all 480 cells and would catch a later silent recovery.
| captureTimeout = um.captureTimeout; | ||
| um.captureTimeout = Number.POSITIVE_INFINITY; | ||
| if (um.lastChange <= 0) { | ||
| um.lastChange = Date.now(); |
There was a problem hiding this comment.
Optional, non-blocking: lastChange <= 0 is the state UndoManager#stopCapturing() leaves, and after this merge Yjs stores the merge's own time in lastChange, so an app's boundary made between the composition's end and the release is lost for the author's next edit too. In a probe (held heading conversion, the update ending the composition bolds the line, an update listener calls binding.undoManager.stopCapturing() once, then the author types in another line with captureTimeout 10000), main keeps the typing as its own undo step, while here one undo also takes back the bold and the hashtag. Keeping a flag here and setting um.lastChange = 0 again in the finally below keeps the join and the boundary; with that change all 480 cells of ComposeHoldRestyledLineTransform.test.ts still pass.
|
The head is now 5626d23. The record taken at the skip now holds only the attributes the composition-ending update changed on each character (as the composer saw them before that update), so the release writes only where the composer changed an attribute and the re-run agrees; an attribute the update did not change, such as a collaborator's bold the hold kept from showing, is never written. Please run a full review of the current head. |
|
The head is now e77b5e9: docs and one test on top of 5626d23 (the runtime is unchanged). y.md now also states that a style set on tokens a transform created, in the update that ends the composition, is not written, since a code highlighter colors its tokens through style in the same update. Please run a full review of the current head. |
There was a problem hiding this comment.
This looks good to me. With a held code-block join, the joined paragraph's words are no longer turned into code-highlight tokens, and the new regression file checks both peers and a fresh reader with GC on and off and in both client orders. Everything below is optional and non-blocking.
- Optional: a line attribute set in the update that ends the composition is dropped.
packages/lexical-y/src/internal/Write.ts:719-726takes the composed line out of the plan, and$writeSkippedLinewrites back only character formats and NodeState. Suppose a collaborator's heading conversion (or join) is held, and the update that ends the composition also callsline.setFormat('center'), or changes indent, direction or an element NodeState. Then no client stores the change, whilemainstores a centred heading with the hashtag. The warning message, its JSDoc inWarnings.ts, the y.md row and D114 all say the rest of the update is written. You could write the marker attributes the update changed (other than the type) onto the stored marker. Or you could name the limit in D114 and y.md's Limits and pin it with atest.fails, aspackages/lexical-y/AGENTS.mdasks for known failures. - Optional: the release overrides
UndoManager#stopCapturing().packages/lexical-y/src/internal/Binding.ts:6829-6830setslastChangeto the current time when it is0, and thefinallyrestores onlycaptureTimeout. If an app callsstopCapturing()between the composition's end and the release, the merge stores its own time inlastChange. The author's next edit withincaptureTimeoutthen joins the composition-end undo step, and one undo also takes back the bold and the hashtag. If you remember thatlastChangewas0and set it back to0in thefinally, the release still joins the step and the app's boundary holds. - Optional: name the browser in the changeset's
Verify:. y.md and D114 say Firefox and desktop WebKit end a composition in an update that changes the line's text, where the re-tokenization is still written as onmain. Following.changeset/lexical-y-held-view-transform-write.md:7in those browsers would show the old behavior. CONTRIBUTING.md asksVerify:to say what to test, so naming a Chromium-based browser would make the paragraph verifiable. A manual or collab-y browser check of the Firefox and Safari composition-end paths would also settle which shape each engine produces. - Optional: stronger convergence checks in the new tests.
converged()inComposeHoldRestyledLineTransform.test.ts:503-517checks the views andpeer.errors. Also asserting no self-check warning and no write recovery (the harness'sexpectConvergedinvariants) would keep a later change from passing these cells through a silent recovery.
The limits D114 already accepts (the Firefox and WebKit commit shape; set-valued and object NodeState, clears and styles on tokens a transform made) are documented, so they are not repeated here as requests.
There was a problem hiding this comment.
This looks good. A held composition's re-tokenization no longer lands on the paragraph or list item a collaborator made of the code block, and the new regression file shows that on both peers and a fresh reader. The suggestions below are optional and non-blocking.
-
The new decision row reuses
D114(packages/lexical-y/DECISIONS.md:148). Since the rebase,mainalready has aD114at line 52 ("A @y/y that fixes the loader's encoding problem is detected, not refused"), cited fromLoadFully.tsandYjsContract.ts. Renumbering this pull request's row and its three citations (Write.ts:3460,ComposeHoldRestyledLineTransform.test.ts:3526and:3599) toD115, the next free id, keeps the references unambiguous.packages/lexical-y/AGENTS.mdmakes these rows the record of an accepted limit. -
A join plus an appended code block in one collaborator update is not caught (
packages/lexical-y/src/internal/HoldGuard.ts:310).$showsRestyledreads the held line's stored marker. B can join the code block into the paragraph and append a new code block in the same update. That marker then keeps typecode, and A's ending update still stores highlight tokens on the paragraph, dropping its underline, as onmain. With the two edits in separate updates, the fix applies. This is no regression, but y.md's Limits says the re-tokenization "isn't written" once a collaborator changed the block's type. A sentence naming this shape in y.md and the decision row would keep that exact. -
The randomized hold lanes keep main's known-open rates.
packages/lexical-y/src/__tests__/unit/LaneFuzz.test.ts:106-107asks a fix that reduces a known-open class to lower itsper1000. Over seeds 100001-100500, this change roughly halves several classes; carryending-phase-code-highlight-outside-code, for example, falls from about 560 to about 220 per 1,000 histories. A class fails only past 1.5 times its recorded rate, so the nightly lanes would not notice this fix regressing until those entries are lowered.
Still open from earlier threads, unchanged at this head:
- An alignment set in the same update that ends the composition is dropped on every client (
Write.ts:724). - An app's
stopCapturing()right after that update is overridden, so the author's next edit joins that undo step (Binding.ts:6829-6830). - The changeset's
Verify:steps reproduce the fix only in a Chromium-based browser. CONTRIBUTING.md asksVerify:to say what to test, so naming the browser makes it checkable. convergedin the new test file does not check theself-checkor recovery warnings thatexpectConvergedchecks.
The Firefox/WebKit path, the decision row and y.md entry, and the reordered-container case raised earlier are now covered.
| if (unit.end.deleted) { | ||
| return true; | ||
| } | ||
| const attr = shownAttrs(unit.end, null)[TYPE_KEY]; |
There was a problem hiding this comment.
Optional: this reads the type of the held line's stored marker. B can join the code block into the paragraph before it and append a new code block in the same update. That marker then keeps type code, the rule does not fire, and A's ending update stores highlight tokens on the paragraph, dropping its underline, exactly as on main. With the join and the append as two updates, it fires. Not a regression, but y.md's Limits says the re-tokenization "isn't written" once a collaborator changed the block's type, so naming this shape there and in the decision row would keep it exact.
…ation of a held code line is not written onto the block a collaborator made of it
## Description
While the local editor composes, a collaborator's change to the line being
composed in is held back: the editor goes on showing the line as it was.
When the collaborator joins the code block being composed in into the line
before it (Backspace at its start), storage holds that line (a paragraph, a
list item) with the code's text, and the hold shows the block as code, with
that line's words in it as stored (plain text nodes, an underlined word,
words with comment marks). When the composition ends, the code highlighter
tokenizes the shown code line again: its tokens are code highlight nodes,
which keep no format and join the NodeState of the text they cover. The
binding wrote them, so storage got code highlight nodes in the paragraph or
list item: the underline was lost, comment marks spread to the neighbouring
words, on every client and a fresh reader.
What the highlighter makes there follows from what the editor shows, not
from what is stored. While a hold is on, where an update re-types the text
of the line composed in, keeping that text but putting some of its
characters in a node of another type (the highlighter's code highlight
nodes in place of text nodes, or a hashtag transform's node), and the
editor shows that line as a block its shared counterpart no longer is (the
shown node not an instance of the stored type's class, which a node
replacement's class extends, or its marker gone:
`HoldGuard#$reshapesRestyledLine`), that line is now not written as a line
(`Writer#skippedLine`), and the binding reports it (see below). A held
change of the line's alignment, indent or direction alone is no such
change: a transform that re-types the line there (a hashtag typed with an
input method) is written, as on main. Of what the update changed there,
only what it changed on the nodes it kept (and the parts split off one) is
written, as formats of their characters: a NodeState value the user or an
app sets on an existing token in the update that ends the composition is
stored, while the characters in nodes the update made (the highlighter's
tokens) keep what is stored, as do the line's marker and its text
(`Writer#$writeSkippedLine`). On a node the update made, a scalar NodeState
value that none of its characters had before the update (the line's text,
inline nodes such as an inline decorator, and line breaks, counted as the
binding stores them) is written too: a value the user or an app set in this
update, which a tokenizer carries onto its tokens (an app's tokenizer
through the public `Tokenizer` API). It is compared whatever layout each
class stores it in (a key a class reads flat, a top-level key of its JSON,
or nested; a key whose name holds U+001F that a StateConfig has whole is
that key, not a set's member), and written as the stored type's class reads
it (a field where it reads the key flat, else NodeState); an ordinary field
of the same name (a node's style, a property of its JSON) is left as it is.
A value some of its characters had before may have been spread over the
others by the transform (a token made of several nodes), and stays as
stored, as does a set-valued or object value, and a value whose name the
stored type's class reads as a set-valued state or one of its members (it
cannot be written there without changing the set); the node's type and
style always do. A format bit a character of such a node did not have
before the update is written too (bold the user applied in that update), as
main writes it; a bit the node no longer has stays as stored. The rest of
the update is written: an edit of another line in it (text the user types
elsewhere in the update that ends the composition, a paragraph an app
appends) is never refused for the re-typing. The line is then read again as
stored and the hold ends, as for an edit refused for the hold, in one read
(a read again of what an update did not write releases a hold that has
ended in it, `Binding#$rereadRefused`, unless updates are queued behind it,
which then commit on their own before the hold is released; a read that
fails is recovered before they run, so they are never dropped with it; the
self-check of that read compares only the containers it leaves current, not
one it replaced), so the editor shows what is stored. What the update
changed on each of the line's characters, as the editor showed it (what
main writes of it), is recorded by the character's stored id
(`Writer#heldResult`). Lexical's transforms then run again on the lines
holding those characters, as stored, in the author's normalization update,
in an update of its own (`YBinding#$normalize`); of what they make, an
attribute so recorded (its node type, a format bit, a NodeState value, a
field) is written only where the re-run gives it the same value, and no
other (one the hold kept from showing, such as a collaborator's bold, stays
as stored), as formats of the stored characters
(`Writer#$writeAgreedLine`), and everything else that normalization changed
is read again as stored. Where an app's transform restructured the line,
replacing it or moving a node that held one of its characters before the
transforms ran into another line, nothing is written for it
(`Writer#$movedOut`). Where a transform rewrote text, characters are
matched only before and after the rewritten parts, so anything between them
stays as stored. So all it writes is part of what main writes in the update
that ends the composition: never text, never another character, and nothing
where a collaborator deleted the line since (the block after it stays as
stored). It is written once, by the composing client, as part of its edit:
it joins the undo step of the update that ended the composition, whatever
the undo manager's captureTimeout is, while that step is the last one on
the composing client's undo stack (an edit of its own in between, such as
an app's update queued as the composition ends, leaves it a step of its
own). A hashtag or a link the update made, which the transform makes again
in the paragraph, heading, quote or list item a collaborator made of the
block (or in the line a collaborator joined it into), is written, as main
stores it; a code highlighter, which tokenizes only inside a code block,
makes nothing outside one; in a block a collaborator made a code block, its
tokens are not what the update made there, so what that collaborator stored
stays; and an app's transform that depends on the block (bold or capitals
in a heading) changes nothing the update did not. Only a transform re-types
a line so: an edit that changes the line's text (typing, a composition,
Enter, or the end of a composition in the update that inserts its text, as
Firefox's input and WebKit's `insertFromComposition` end one) or keeps the
type of every node holding its characters (a format applied to part of a
word, which splits its node) is written as before. Nor is an update that
also moves the line or a container around it (a slot of a component swapped
with another, or a container moved before another): it is decided as
before, refused for the hold where it endangers what the hold keeps, so a
structural write that stops part way never deletes untouched text.
While a composition is held and a collaborator has changed the type of the
block it's in, the highlighter's re-tokenization of that line isn't
written. A NodeState value set in the update that ends the composition is
written when the tokenizer carries it onto the new tokens; clearing a value
or a format on those tokens isn't written in that update. That holds for a
clear by the user and by an app's transform. A style set on those tokens in
that update isn't written either; a code highlighter colors its tokens
through style in the same update, so the two can't be told apart. A
set-valued or object NodeState change on those tokens isn't written in that
update either, and the stored value stays. So does a value whose name the
stored class reads as a set-valued state or one of its members. Extending a
value within one of those tokens, onto characters next to others of it that
had the value already, isn't written in that update either. When a held
composition ends, the line is read as stored and its transforms run again;
only changes that agree with what the composer's own update would have
written are saved. They join the undo step of the composer's update,
whatever `captureTimeout` is, unless an edit of the composer's own came in
between. If an app transform restructures the held line or rewrites its
text when its transforms run again (for example, one that converts, moves
or upper-cases blocks of the converted type), what changed is kept as
stored. When a collaborator turns the block into a code block, what it
stored there stays (its highlighter's tokens, or plain text where it runs
none), not an entity the composing editor had in its held view; the formats
and NodeState set in that update stay on plain text and follow the
highlighter on its tokens. When the update that ends the composition also
changes the line's text (as Firefox's input and WebKit's
`insertFromComposition` do, inserting the composed text in it), the
re-tokenization is written, as on main. The binding reports the skip with
`UNSUPPORTED_EDIT_WARNING` (`reason: 'other'`, `detailCode:
'held-line-retokenize'`), once per composition. A composition the browser
ends and starts again in one update (its composition events) is a new one.
One an app ends and starts again within one update, without composition
events, can't be told from one that goes on, so a skip in it isn't reported
again. Precisely, these limits apply to an update that, while a hold is on,
keeps the text of the line composed in but puts some of its characters in
nodes of another type, where the editor shows that line as a block its
shared counterpart no longer is (a shown node that is not an instance of
the stored type's class, as after a collaborator's change of the block's
type, or its marker gone, as after a join into the line before it), and
that moves neither the line nor a container around it.
A re-tokenization merges text of several nodes into one, which the hold's
check of an update takes for moved text, so an update that only re-types
the line would count as one that inserts characters. For such an update,
it now counts as one only where the document's text gains characters
(another line typed in, a paragraph appended, `HoldGuard#$gainsText`), or
where a remote change not read yet deletes text: a write of it that fails
part way is then recovered as on main, keeping what it wrote.
## Changeset
`.changeset/lexical-y-held-view-transform-write.md`: a patch for `@lexical/y`.
`packages/lexical-website/docs/collaboration/y.md`: the limit, in the
input method composition item of Limits, and the warning's row.
`packages/lexical-y/DECISIONS.md`: row D115 records the accepted limits.
## Test plan
`regressions/ComposeHoldRestyledLineTransform.test.ts` (gc off and on, both
client orders):
- A composes in a code block; B joins it into the line before it, a
paragraph or a list item holding an underlined word and two words with
comment marks of their own; A's composition ends. Every client and a fresh
reader show the line with the underline and each mark on its own word, and
no code highlight node outside code.
- What a user does there is written as before: text typed into the composed
text before the composition ends; a second composition, then Enter, after
it ends; a format applied to part of a word (which splits its node) while
a heading or alignment change of the line composed in is held. A rule
that refused every change of such a line's children that kept its text
dropped that format without a word: the type of each character's node is
what tells a re-typing apart.
- The update that ends the composition also edits another line: text
typed (`insertText`) or spliced at the start of another paragraph, a new
paragraph appended, the two in updates Lexical commits as one; and, as a
control, the typing in an update of its own. Every client and a fresh
reader show the edit, and the joined line as stored. Refusing the whole
update for the re-typing read the other line again too, and lost the
edit.
- In the update that ends the composition, a NodeState value is set on the
`let` token of the joined line, which the highlighter keeps: a string, a
set-valued one, and one an app's registered command sets; and, as a
control, the same in an update of its own. Every client and a fresh
reader show the value on `let` only, and no code highlight node outside
code. Leaving the whole line out of the write lost the value.
- The update that ends the composition types in another line; its write
fails right after that line is written, and every recovery fails where it
starts. Every client and a fresh reader keep the typing, as on main.
Counting the update as one that inserts no character rolled the typing
back.
- B's join is held together with B's change of the joined text's format
(the underline taken off a word), and A makes a new text node with an
explicit underline in another line, during the hold or in the update that
ends the composition, with Prism and with Shiki. Every client and a fresh
reader show the new node underlined and the joined line as stored, B's
change of its format included, with no code highlight node outside code.
- In the update that ends the composition, A sets a NodeState value (a
string, a boolean anchor as a comment's, and that anchor declared flat)
on the first word of the joined line, with Prism and with Shiki: where the
tokenizer carries the value onto the token it makes for that word, every
client and a fresh reader show the value on that word only; with the stock
tokenizers, which drop it in A's editor as on main, every client and a
fresh reader agree on the line as stored. Both with no code highlight node
outside code.
- The line is read as stored and the hold released in one read: an app's
edit queued as the composition ends (from an update listener, or made
right after in the same task) runs after that read and is written; text
the binding cannot store (a lone surrogate) typed into a line of another
container in the update that ends the composition is read again in the
same read (two containers read again); and a code block in a named slot
is read as stored with the slot's host.
- A read that fails once as the composition ends (reading the line again,
or reading what the hold held) is recovered, and an app's edit queued
from an update listener behind it is written on every client and a fresh
reader. Recovering in the update the edit was queued into dropped it.
- A component's two slots swapped in the update that ends a composition
held in one of them are refused, as on main, and keep the text of both.
Writing the swap left the other slot's text deleted.
- The re-typing left out of the write is reported once
(`UNSUPPORTED_EDIT_WARNING`, `'other'`, `'held-line-retokenize'`), with
Prism and with Shiki (which re-types the line twice), also in a
composition that goes on through a second hold, and not where an update
ends a composition without a held restyle, types in the line, splits a
node with a format, or the held change does not restyle it.
- A NodeState value named as an ordinary field (`style`), set on the held
line in the update that ends the composition and carried by the
tokenizer with the text's CSS style, is written, and the style is kept.
- In the update that ends the composition, a set-valued value the stored
text class reads flat (a member added, its member replaced, a member
removed) or an object value is set on the first word of the joined line,
and the tokenizer carries it onto the code token it makes, which reads it
nested, with Prism and with Shiki: every client and a fresh reader show
the stored value. A scalar value under a key whose name holds U+001F,
which the stored class reads flat, is written. A scalar value under a
name that the stored class reads as a member of its set-valued state,
which an app's highlight class has and its tokenizer sets on the token it
makes, stays as stored, and so does the set. Where the stored class has,
instead, a scalar named like a member of the key, which it does not read
as one, the value is written.
- The re-typing is reported again in a composition the browser ends and
starts again in one update (composition events dispatched in it).
- A container holding the composed line, moved before another in the update
that ends the composition, is decided as on main (the update moves
structure): every client and a fresh reader show main's result, with no
warning of a skipped re-typing, no self-check warning and no error. With
the hashtag plugin, A types a hashtag with an input method while B
changes the line's alignment, indent or direction: when the composition
ends, every client and a fresh reader store the hashtag node, as on main,
with no warning. A composition that ends in the update inserting its text
(as Firefox's input and WebKit's `insertFromComposition` end one) is
written with the highlighter's tokens, as on main.
- A collaborator makes the line A composes in a heading, a quote or a list
item while A types a hashtag or a URL with an input method, with the
hashtag or autolink transform on every client or on A only: when the
composition ends, every client and a fresh reader store the hashtag or
autolink node in the converted block, as on main. So do they where A
shows the paragraph through a node replacement (a factory that declares
no class, or a chain of two) and a collaborator makes it an ordinary
paragraph and centres it.
- In the update that ends the composition, A bolds the line while a
collaborator makes it a paragraph or a heading and the hashtag transform
makes a token of the composed text: every client and a fresh reader show
all of it bold, as on main; and one undo takes back that update together
with the transforms run again on the line.
- A collaborator makes the line a code block while A types a hashtag with
an input method, and A's update that ends the composition bolds the line
and sets a note on it, with Prism and with Shiki: where only A
highlights, every client and a fresh reader store plain text with the
bold and the note; where every client does, they store the collaborator's
highlighter's tokens with the note (code highlight nodes keep no format).
- B makes the line a heading and appends a code block with an underlined
word and a note, then deletes the heading, which A reads right after its
write of the update that ends the composition: every client and a fresh
reader show the code block as B stored it. Running the transforms on the
line after the deleted one tokenized the code block again, dropping the
underline and the note.
- B joins the line into the one before it and appends such a code block:
when the composition ends, the joined line gets the hashtag A's
composition made, and the code block stays as stored.
- In a line that starts with an inline decorator, bold or a note A sets on
the line in the update that ends the composition, while B makes the line
a heading, is written on the hashtag the transform makes, as on main. The
line's state before the update did not count the decorator as the binding
stores it, so neither was written there.
- An app's transform that sets bold or capitals on text in a heading,
registered on A only: when the composition ends in the line B made a
heading, every client and a fresh reader store the hashtag A's update
made and the rest of the line as stored, as on main. Writing what the
transforms made on the line as stored put the bold or the capitals on
text that update did not touch.
- During a hold of the line's alignment, a cleared note, a set and an
object value A sets on the line in the update that ends the composition,
which the hashtag transform carries onto its token, are written as on
main, with no warning.
- With captureTimeout 0 and 10000, and nothing, a collaborator's edit (read
right after A's write of the update that ends the composition) or an
app's edit queued as the composition ends in between, A's undo step
starting with that update: one undo takes back the update together with
the transforms run again on the line read as stored, as main takes back
that update; with captureTimeout 0, the app's edit, an undo step of its
own, leaves those transforms one too, and three undos restore the line.
Grouped by time alone, they were a second undo step at 0, and one undo
left the line bold.
- An app's transform that restructures the heading a collaborator made of
the held line as the transforms run again (makes it a quote or a code
block, splits its children over two quotes, moves its first part into the
next paragraph, wraps it after a token with the same text, or in brackets
after a long word): every client and a fresh reader keep the line as
stored. A hashtag that is the whole line, whose only text node the
transform replaces in place, is written, as on main.
- An app's transform that upper-cases text in a heading, on A only: in
`before #tag after`, the hashtag between the rewritten parts stays as
stored (plain `#tag`, the stored text unchanged); at the end of `before
#tag`, it is written, as on main.
- Every client's own transforms bold text in a heading (or set a note on
it) and make a heading a code block, so storage holds a bold code block
where A shows the plain paragraph it composes a hashtag in; A ends the
composition with no edit of its own: every client and a fresh reader keep
the bold (the note) on every character. Recording what the update made of
each character, rather than what it changed, wrote the held view's plain
format over it.
- In the update that ends the composition, A sets a style (green) on the
line, where B's held change made it a heading and set another style
(blue), with a transform on A that clears the style of text in a heading:
every client and a fresh reader show the text before `#tag` in A's style,
as on main, and the hashtag the transform makes in the stored style.
- Without a hold, the join keeps the paragraph's words; with a hold that
does not restyle the line (B types in the code line A composes in), the
highlighter's tokens at the end of the composition are written.
### Before
```
$ vitest --run --project unit regressions/ComposeHoldRestyledLineTransform
AssertionError: expected 'paragraph[hl:aa bb cc dd|let x = 1;]' not to contain 'hl:'
AssertionError: expected 'list[hl:aa bb cc dd|let x = 1;]' not to contain 'hl:'
AssertionError: expected 'paragraph[hl:aa bb cc dd|lzzet x = 1;]' to be 'paragraph[aa |bb/f8| cc/c5| dd/c6|lzz…'
AssertionError: expected 'paragraph[aaqq ] paragraph[bb cc ddle…' to be 'paragraph[aaqq ] paragraph[bb/f8| cc/…'
AssertionError: expected 'paragraph[TYPEDother ] paragraph[hl:b…' not to contain 'hl:'
AssertionError: expected 'paragraph[other ] paragraph[hl:before…' not to contain 'hl:'
AssertionError: expected 'paragraph[other |NEW/f8] paragraph[hl…' to be 'paragraph[other |NEW/f8] paragraph[be…'
Test Files 1 failed (1)
Tests 264 failed | 228 passed (492)
```
### After
```
$ vitest --run --project unit regressions/ComposeHoldRestyledLineTransform
Test Files 1 passed (1)
Tests 492 passed (492)
```
The @lexical/y and @lexical/yjs suites, gc off and on, the types and Flow:
```
$ LEXICAL_Y_GC=0 vitest run --project unit packages/lexical-y packages/lexical-yjs
Test Files 455 passed | 4 skipped (459)
Tests 24137 passed | 360 expected fail | 156 skipped (24653)
$ LEXICAL_Y_GC=1 vitest run --project unit packages/lexical-y packages/lexical-yjs
Test Files 455 passed | 4 skipped (459)
Tests 24137 passed | 360 expected fail | 156 skipped (24653)
$ pnpm run tsc
$ pnpm run flow
Found 0 errors
```
Files that went over a time or memory bound while the machine was loaded
were run again with four workers, and are counted from that run.
|
The head is now 3bcb258: since the rebase, main has its own D114, so this PR's DECISIONS.md row is renumbered D115, and its two code comments, its test comments and the commit message follow (docs and comments only). Please run a full review of the current head. |
There was a problem hiding this comment.
This looks good. Thanks for the thorough matrix. The fix keeps a held line's stored formats and comment marks when a collaborator joins or converts the block during an IME composition, and the new regression file fails on main and passes here. The suggestions below are optional and non-blocking:
- A marker change in the composition-ending update (
packages/lexical-y/src/internal/Write.ts:719-726, doc comment at:3252): when the line is skipped, only character formats and NodeState are written back, so an alignment, indent or direction change made on that line in the same update is dropped on every client. For example: a collaborator's heading conversion is held while#tagis composed, and ending the composition and callingline.setFormat('center')in one update stores an uncentred heading.mainstores it centred, and in an update of its own it is written here too. The warning text, theWarnings.tsJSDoc and the y.md row say the rest of the update is written. Either write the marker attributes the update changed on the shown line from$writeSkippedLine, or record the limit in D115 and y.md's Limits, aspackages/lexical-y/AGENTS.mdasks for accepted limits. - The changeset's
Verify:(.changeset/lexical-y-held-view-transform-write.md:7): Firefox and desktop Safari end a composition in the update that inserts its text, where the re-tokenization is still written as onmain(y.md, and the test atComposeHoldRestyledLineTransform.test.ts:3591). AGENTS.md asksVerify:to say what to test, so naming a Chromium-based browser makes it reproducible as written. - The
convergedtest helper (ComposeHoldRestyledLineTransform.test.ts:504-517): it could also assert noself-checkwarning and nocould not be writtenrecovery, as the harness'sexpectConvergeddoes. All cells pass with those checks added. - The y.md Limits wording (
packages/lexical-website/docs/collaboration/y.md:1313-1314): when a collaborator joins the code block and appends a new code block in the same update, the stored marker keeps typecodeand the re-tokenization is written as onmain. Naming that shape keeps the sentence exact.
Description
While the local editor composes, a collaborator's change to the line being
composed in is held back: the editor goes on showing the line as it was.
When the collaborator joins the code block being composed in into the line
before it (Backspace at its start), storage holds that line (a paragraph, a
list item) with the code's text, and the hold shows the block as code, with
that line's words in it as stored (plain text nodes, an underlined word,
words with comment marks). When the composition ends, the code highlighter
tokenizes the shown code line again: its tokens are code highlight nodes,
which keep no format and join the NodeState of the text they cover. The
binding wrote them, so storage got code highlight nodes in the paragraph or
list item: the underline was lost, comment marks spread to the neighbouring
words, on every client and a fresh reader.
What the highlighter makes there follows from what the editor shows, not
from what is stored. While a hold is on, where an update re-types the text
of the line composed in, keeping that text but putting some of its
characters in a node of another type (the highlighter's code highlight
nodes in place of text nodes, or a hashtag transform's node), and the
editor shows that line as a block its shared counterpart no longer is (the
shown node not an instance of the stored type's class, which a node
replacement's class extends, or its marker gone:
HoldGuard#$reshapesRestyledLine), that line is now not written as a line(
Writer#skippedLine), and the binding reports it (see below). A heldchange of the line's alignment, indent or direction alone is no such
change: a transform that re-types the line there (a hashtag typed with an
input method) is written, as on main. Of what the update changed there,
only what it changed on the nodes it kept (and the parts split off one) is
written, as formats of their characters: a NodeState value the user or an
app sets on an existing token in the update that ends the composition is
stored, while the characters in nodes the update made (the highlighter's
tokens) keep what is stored, as do the line's marker and its text
(
Writer#$writeSkippedLine). On a node the update made, a scalar NodeStatevalue that none of its characters had before the update (the line's text,
inline nodes such as an inline decorator, and line breaks, counted as the
binding stores them) is written too: a value the user or an app set in this
update, which a tokenizer carries onto its tokens (an app's tokenizer
through the public
TokenizerAPI). It is compared whatever layout eachclass stores it in (a key a class reads flat, a top-level key of its JSON,
or nested; a key whose name holds U+001F that a StateConfig has whole is
that key, not a set's member), and written as the stored type's class reads
it (a field where it reads the key flat, else NodeState); an ordinary field
of the same name (a node's style, a property of its JSON) is left as it is.
A value some of its characters had before may have been spread over the
others by the transform (a token made of several nodes), and stays as
stored, as does a set-valued or object value, and a value whose name the
stored type's class reads as a set-valued state or one of its members (it
cannot be written there without changing the set); the node's type and
style always do. A format bit a character of such a node did not have
before the update is written too (bold the user applied in that update), as
main writes it; a bit the node no longer has stays as stored. The rest of
the update is written: an edit of another line in it (text the user types
elsewhere in the update that ends the composition, a paragraph an app
appends) is never refused for the re-typing. The line is then read again as
stored and the hold ends, as for an edit refused for the hold, in one read
(a read again of what an update did not write releases a hold that has
ended in it,
Binding#$rereadRefused, unless updates are queued behind it,which then commit on their own before the hold is released; a read that
fails is recovered before they run, so they are never dropped with it; the
self-check of that read compares only the containers it leaves current, not
one it replaced), so the editor shows what is stored. What the update
changed on each of the line's characters, as the editor showed it (what
main writes of it), is recorded by the character's stored id
(
Writer#heldResult). Lexical's transforms then run again on the linesholding those characters, as stored, in the author's normalization update,
in an update of its own (
YBinding#$normalize); of what they make, anattribute so recorded (its node type, a format bit, a NodeState value, a
field) is written only where the re-run gives it the same value, and no
other (one the hold kept from showing, such as a collaborator's bold, stays
as stored), as formats of the stored characters
(
Writer#$writeAgreedLine), and everything else that normalization changedis read again as stored. Where an app's transform restructured the line,
replacing it or moving a node that held one of its characters before the
transforms ran into another line, nothing is written for it
(
Writer#$movedOut). Where a transform rewrote text, characters arematched only before and after the rewritten parts, so anything between them
stays as stored. So all it writes is part of what main writes in the update
that ends the composition: never text, never another character, and nothing
where a collaborator deleted the line since (the block after it stays as
stored). It is written once, by the composing client, as part of its edit:
it joins the undo step of the update that ended the composition, whatever
the undo manager's captureTimeout is, while that step is the last one on
the composing client's undo stack (an edit of its own in between, such as
an app's update queued as the composition ends, leaves it a step of its
own). A hashtag or a link the update made, which the transform makes again
in the paragraph, heading, quote or list item a collaborator made of the
block (or in the line a collaborator joined it into), is written, as main
stores it; a code highlighter, which tokenizes only inside a code block,
makes nothing outside one; in a block a collaborator made a code block, its
tokens are not what the update made there, so what that collaborator stored
stays; and an app's transform that depends on the block (bold or capitals
in a heading) changes nothing the update did not. Only a transform re-types
a line so: an edit that changes the line's text (typing, a composition,
Enter, or the end of a composition in the update that inserts its text, as
Firefox's input and WebKit's
insertFromCompositionend one) or keeps thetype of every node holding its characters (a format applied to part of a
word, which splits its node) is written as before. Nor is an update that
also moves the line or a container around it (a slot of a component swapped
with another, or a container moved before another): it is decided as
before, refused for the hold where it endangers what the hold keeps, so a
structural write that stops part way never deletes untouched text.
While a composition is held and a collaborator has changed the type of the
block it's in, the highlighter's re-tokenization of that line isn't
written. A NodeState value set in the update that ends the composition is
written when the tokenizer carries it onto the new tokens; clearing a value
or a format on those tokens isn't written in that update. That holds for a
clear by the user and by an app's transform. A style set on those tokens in
that update isn't written either; a code highlighter colors its tokens
through style in the same update, so the two can't be told apart. A
set-valued or object NodeState change on those tokens isn't written in that
update either, and the stored value stays. So does a value whose name the
stored class reads as a set-valued state or one of its members. Extending a
value within one of those tokens, onto characters next to others of it that
had the value already, isn't written in that update either. When a held
composition ends, the line is read as stored and its transforms run again;
only changes that agree with what the composer's own update would have
written are saved. They join the undo step of the composer's update,
whatever
captureTimeoutis, unless an edit of the composer's own came inbetween. If an app transform restructures the held line or rewrites its
text when its transforms run again (for example, one that converts, moves
or upper-cases blocks of the converted type), what changed is kept as
stored. When a collaborator turns the block into a code block, what it
stored there stays (its highlighter's tokens, or plain text where it runs
none), not an entity the composing editor had in its held view; the formats
and NodeState set in that update stay on plain text and follow the
highlighter on its tokens. When the update that ends the composition also
changes the line's text (as Firefox's input and WebKit's
insertFromCompositiondo, inserting the composed text in it), there-tokenization is written, as on main. The binding reports the skip with
UNSUPPORTED_EDIT_WARNING(reason: 'other',detailCode: 'held-line-retokenize'), once per composition. A composition the browserends and starts again in one update (its composition events) is a new one.
One an app ends and starts again within one update, without composition
events, can't be told from one that goes on, so a skip in it isn't reported
again. Precisely, these limits apply to an update that, while a hold is on,
keeps the text of the line composed in but puts some of its characters in
nodes of another type, where the editor shows that line as a block its
shared counterpart no longer is (a shown node that is not an instance of
the stored type's class, as after a collaborator's change of the block's
type, or its marker gone, as after a join into the line before it), and
that moves neither the line nor a container around it.
A re-tokenization merges text of several nodes into one, which the hold's
check of an update takes for moved text, so an update that only re-types
the line would count as one that inserts characters. For such an update,
it now counts as one only where the document's text gains characters
(another line typed in, a paragraph appended,
HoldGuard#$gainsText), orwhere a remote change not read yet deletes text: a write of it that fails
part way is then recovered as on main, keeping what it wrote.
Changeset
.changeset/lexical-y-held-view-transform-write.md: a patch for@lexical/y.packages/lexical-website/docs/collaboration/y.md: the limit, in theinput method composition item of Limits, and the warning's row.
packages/lexical-y/DECISIONS.md: row D115 records the accepted limits.Test plan
regressions/ComposeHoldRestyledLineTransform.test.ts(gc off and on, bothclient orders):
paragraph or a list item holding an underlined word and two words with
comment marks of their own; A's composition ends. Every client and a fresh
reader show the line with the underline and each mark on its own word, and
no code highlight node outside code.
text before the composition ends; a second composition, then Enter, after
it ends; a format applied to part of a word (which splits its node) while
a heading or alignment change of the line composed in is held. A rule
that refused every change of such a line's children that kept its text
dropped that format without a word: the type of each character's node is
what tells a re-typing apart.
typed (
insertText) or spliced at the start of another paragraph, a newparagraph appended, the two in updates Lexical commits as one; and, as a
control, the typing in an update of its own. Every client and a fresh
reader show the edit, and the joined line as stored. Refusing the whole
update for the re-typing read the other line again too, and lost the
edit.
lettoken of the joined line, which the highlighter keeps: a string, aset-valued one, and one an app's registered command sets; and, as a
control, the same in an update of its own. Every client and a fresh
reader show the value on
letonly, and no code highlight node outsidecode. Leaving the whole line out of the write lost the value.
fails right after that line is written, and every recovery fails where it
starts. Every client and a fresh reader keep the typing, as on main.
Counting the update as one that inserts no character rolled the typing
back.
(the underline taken off a word), and A makes a new text node with an
explicit underline in another line, during the hold or in the update that
ends the composition, with Prism and with Shiki. Every client and a fresh
reader show the new node underlined and the joined line as stored, B's
change of its format included, with no code highlight node outside code.
string, a boolean anchor as a comment's, and that anchor declared flat)
on the first word of the joined line, with Prism and with Shiki: where the
tokenizer carries the value onto the token it makes for that word, every
client and a fresh reader show the value on that word only; with the stock
tokenizers, which drop it in A's editor as on main, every client and a
fresh reader agree on the line as stored. Both with no code highlight node
outside code.
edit queued as the composition ends (from an update listener, or made
right after in the same task) runs after that read and is written; text
the binding cannot store (a lone surrogate) typed into a line of another
container in the update that ends the composition is read again in the
same read (two containers read again); and a code block in a named slot
is read as stored with the slot's host.
or reading what the hold held) is recovered, and an app's edit queued
from an update listener behind it is written on every client and a fresh
reader. Recovering in the update the edit was queued into dropped it.
held in one of them are refused, as on main, and keep the text of both.
Writing the swap left the other slot's text deleted.
(
UNSUPPORTED_EDIT_WARNING,'other','held-line-retokenize'), withPrism and with Shiki (which re-types the line twice), also in a
composition that goes on through a second hold, and not where an update
ends a composition without a held restyle, types in the line, splits a
node with a format, or the held change does not restyle it.
style), set on the heldline in the update that ends the composition and carried by the
tokenizer with the text's CSS style, is written, and the style is kept.
text class reads flat (a member added, its member replaced, a member
removed) or an object value is set on the first word of the joined line,
and the tokenizer carries it onto the code token it makes, which reads it
nested, with Prism and with Shiki: every client and a fresh reader show
the stored value. A scalar value under a key whose name holds U+001F,
which the stored class reads flat, is written. A scalar value under a
name that the stored class reads as a member of its set-valued state,
which an app's highlight class has and its tokenizer sets on the token it
makes, stays as stored, and so does the set. Where the stored class has,
instead, a scalar named like a member of the key, which it does not read
as one, the value is written.
starts again in one update (composition events dispatched in it).
that ends the composition, is decided as on main (the update moves
structure): every client and a fresh reader show main's result, with no
warning of a skipped re-typing, no self-check warning and no error. With
the hashtag plugin, A types a hashtag with an input method while B
changes the line's alignment, indent or direction: when the composition
ends, every client and a fresh reader store the hashtag node, as on main,
with no warning. A composition that ends in the update inserting its text
(as Firefox's input and WebKit's
insertFromCompositionend one) iswritten with the highlighter's tokens, as on main.
item while A types a hashtag or a URL with an input method, with the
hashtag or autolink transform on every client or on A only: when the
composition ends, every client and a fresh reader store the hashtag or
autolink node in the converted block, as on main. So do they where A
shows the paragraph through a node replacement (a factory that declares
no class, or a chain of two) and a collaborator makes it an ordinary
paragraph and centres it.
collaborator makes it a paragraph or a heading and the hashtag transform
makes a token of the composed text: every client and a fresh reader show
all of it bold, as on main; and one undo takes back that update together
with the transforms run again on the line.
an input method, and A's update that ends the composition bolds the line
and sets a note on it, with Prism and with Shiki: where only A
highlights, every client and a fresh reader store plain text with the
bold and the note; where every client does, they store the collaborator's
highlighter's tokens with the note (code highlight nodes keep no format).
word and a note, then deletes the heading, which A reads right after its
write of the update that ends the composition: every client and a fresh
reader show the code block as B stored it. Running the transforms on the
line after the deleted one tokenized the code block again, dropping the
underline and the note.
when the composition ends, the joined line gets the hashtag A's
composition made, and the code block stays as stored.
the line in the update that ends the composition, while B makes the line
a heading, is written on the hashtag the transform makes, as on main. The
line's state before the update did not count the decorator as the binding
stores it, so neither was written there.
registered on A only: when the composition ends in the line B made a
heading, every client and a fresh reader store the hashtag A's update
made and the rest of the line as stored, as on main. Writing what the
transforms made on the line as stored put the bold or the capitals on
text that update did not touch.
object value A sets on the line in the update that ends the composition,
which the hashtag transform carries onto its token, are written as on
main, with no warning.
right after A's write of the update that ends the composition) or an
app's edit queued as the composition ends in between, A's undo step
starting with that update: one undo takes back the update together with
the transforms run again on the line read as stored, as main takes back
that update; with captureTimeout 0, the app's edit, an undo step of its
own, leaves those transforms one too, and three undos restore the line.
Grouped by time alone, they were a second undo step at 0, and one undo
left the line bold.
the held line as the transforms run again (makes it a quote or a code
block, splits its children over two quotes, moves its first part into the
next paragraph, wraps it after a token with the same text, or in brackets
after a long word): every client and a fresh reader keep the line as
stored. A hashtag that is the whole line, whose only text node the
transform replaces in place, is written, as on main.
before #tag after, the hashtag between the rewritten parts stays asstored (plain
#tag, the stored text unchanged); at the end ofbefore #tag, it is written, as on main.it) and make a heading a code block, so storage holds a bold code block
where A shows the plain paragraph it composes a hashtag in; A ends the
composition with no edit of its own: every client and a fresh reader keep
the bold (the note) on every character. Recording what the update made of
each character, rather than what it changed, wrote the held view's plain
format over it.
line, where B's held change made it a heading and set another style
(blue), with a transform on A that clears the style of text in a heading:
every client and a fresh reader show the text before
#tagin A's style,as on main, and the hashtag the transform makes in the stored style.
does not restyle the line (B types in the code line A composes in), the
highlighter's tokens at the end of the composition are written.
Before
After
The @lexical/y and @lexical/yjs suites, gc off and on, the types and Flow:
Files that went over a time or memory bound while the machine was loaded
were run again with four workers, and are counted from that run.