Skip to content

[lexical-text][lexical-playground] Revert: Text entity transforms settle between text nodes of other formats (#9686) - #9702

Merged
zurfyx merged 1 commit into
mainfrom
zurfyx/revert-9686
Nov 1, 2026
Merged

zurfyx merged 1 commit into
mainfrom
zurfyx/revert-9686

Conversation

@zurfyx

@zurfyx zurfyx commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Description

Reverts #9686 (squash 72b28f4a).

#9686 can turn a hashtag into plain text and drop its comment marks. Steps (plain Lexical with HashtagExtension, no collaboration): a list item starts with the hashtag #t5017z, which carries two comment marks; the paragraph before it is a pull-quote slot paragraph that ends with a tab. Backspace at the list item's start joins it onto that paragraph. On main after #9686 the hashtag becomes a plain text node and loses both marks (the next text node keeps its own mark). Before #9686 the hashtag and both marks stay.

The marks are lost in $replaceWithSimpleText, which does not carry NodeState when an entity becomes text (#9703, also on main before #9686); #9686 runs it in many more places. The re-land issue is #9704.

The loop #9686 fixes (#9637) needs keyword-style text entities (like the playground's "congrats"); shipped hashtags never hit it, so its exposure is low. Losing comment marks on text nobody touched is worse, so this restores the previous behaviour. A re-land waits for the root cause, a regression test for this join, and the usual downstream checks.

The revert's tree is identical to c7507578's (main right before #9686).

Test plan

  • Tree identical to c7507578, which passed: ci-check; all-package units with Yjs gc off and on; the default matrix and MATRIX_FULL (11 legacy cells only); golden corpora; repro sets.
  • The join reproduction (a snapshot of the editor state, plain Lexical + HashtagExtension) fails on 72b28f4a and passes on c7507578, with gc on and off.

…tle between text nodes of other formats (#9686)

This reverts commit 72b28f4.

#9686 can turn a hashtag into plain text and drop its comment marks when
a list item that starts with the hashtag is joined onto the paragraph
before it (backspace at the item's start, in a pull-quote slot paragraph
that ends with a tab). The previous main keeps the hashtag and its marks.
The loop #9686 fixes (#9637) needs keyword-style text entities; shipped
hashtags never hit it. Reverting restores main's behaviour; a re-land
waits for a root cause and a regression test for this join.
@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lexical Ready Ready Preview Nov 1, 2026 12:32pm UTC
lexical-playground Ready Ready Preview Nov 1, 2026 12:32pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 1, 2026
@meta-code-review

meta-code-review Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 1, 2026, 12:46 PM UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 1, 2026

Copy link
Copy Markdown
lexical

npm i https://pkg.pr.new/lexical@9702

@lexical/a11y

npm i https://pkg.pr.new/@lexical/a11y@9702

@lexical/clipboard

npm i https://pkg.pr.new/@lexical/clipboard@9702

@lexical/code

npm i https://pkg.pr.new/@lexical/code@9702

@lexical/code-core

npm i https://pkg.pr.new/@lexical/code-core@9702

@lexical/code-prism

npm i https://pkg.pr.new/@lexical/code-prism@9702

@lexical/code-shiki

npm i https://pkg.pr.new/@lexical/code-shiki@9702

@lexical/compiler

npm i https://pkg.pr.new/@lexical/compiler@9702

@lexical/devtools-core

npm i https://pkg.pr.new/@lexical/devtools-core@9702

@lexical/dragon

npm i https://pkg.pr.new/@lexical/dragon@9702

@lexical/eslint-plugin

npm i https://pkg.pr.new/@lexical/eslint-plugin@9702

@lexical/extension

npm i https://pkg.pr.new/@lexical/extension@9702

@lexical/fast-check

npm i https://pkg.pr.new/@lexical/fast-check@9702

@lexical/file

npm i https://pkg.pr.new/@lexical/file@9702

@lexical/hashtag

npm i https://pkg.pr.new/@lexical/hashtag@9702

@lexical/headless

npm i https://pkg.pr.new/@lexical/headless@9702

@lexical/history

npm i https://pkg.pr.new/@lexical/history@9702

@lexical/html

npm i https://pkg.pr.new/@lexical/html@9702

@lexical/internal

npm i https://pkg.pr.new/@lexical/internal@9702

@lexical/link

npm i https://pkg.pr.new/@lexical/link@9702

@lexical/list

npm i https://pkg.pr.new/@lexical/list@9702

@lexical/mark

npm i https://pkg.pr.new/@lexical/mark@9702

@lexical/markdown

npm i https://pkg.pr.new/@lexical/markdown@9702

@lexical/mdast

npm i https://pkg.pr.new/@lexical/mdast@9702

@lexical/offset

npm i https://pkg.pr.new/@lexical/offset@9702

@lexical/overflow

npm i https://pkg.pr.new/@lexical/overflow@9702

@lexical/plain-text

npm i https://pkg.pr.new/@lexical/plain-text@9702

@lexical/react

npm i https://pkg.pr.new/@lexical/react@9702

@lexical/rich-text

npm i https://pkg.pr.new/@lexical/rich-text@9702

@lexical/selection

npm i https://pkg.pr.new/@lexical/selection@9702

@lexical/table

npm i https://pkg.pr.new/@lexical/table@9702

@lexical/tailwind

npm i https://pkg.pr.new/@lexical/tailwind@9702

@lexical/text

npm i https://pkg.pr.new/@lexical/text@9702

@lexical/utils

npm i https://pkg.pr.new/@lexical/utils@9702

@lexical/y

npm i https://pkg.pr.new/@lexical/y@9702

@lexical/yjs

npm i https://pkg.pr.new/@lexical/yjs@9702

commit: f9ea110

@meta-code-review meta-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, thanks. The revert is exact (the head tree matches c7507578, main right before #9686) and CI is green. Restoring main's behaviour is the safer side of the trade-off the description lays out. A few optional, non-blocking follow-ups:

  1. Track the loops this reopens (packages/lexical-text/src/registerLexicalTextEntity.ts:81-85). #9686's merge closed #9637, so once this lands no open issue tracks it. The revert also brings back a second loop that the description does not mention. When createNode returns a token- or segmented-mode entity, any such entity with text after it in its node throws "One or more transforms are endlessly triggering additional transforms"; setting a paragraph to #a b is enough. Reopening #9637 with that case added would keep both loops in scope for the re-land.
  2. Use the skip-changeset label. The Changesets job asks for an @lexical/text changeset, but no release ever carried #9686, so deleting its pending changeset is the whole record. .changeset/README.md ("When a changeset is needed") points to the label for exactly this case.
  3. Share the join reproduction. AGENTS.md asks the Test plan for the real Before/After output. The editor-state snapshot that fails on 72b28f4a is not in the PR. Posting it on #9637 or a new issue would give the re-land's regression test a concrete target. Simple approximations did not reproduce the demotion on either side (a tab node or tab character before the hashtag, marks stored in NodeState, a backspace join).
  4. For the re-land: $replaceWithSimpleText (lines 52-60) copies format, style and detail but not NodeState. Any demotion, even a correct one, therefore drops marks stored in NodeState. Carrying NodeState over would stop a future wrong demotion from losing data.

$wasTurnedIntoText(prevSibling)
))
) {
if (prevMatch === null || getMode(prevSibling) !== 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional, non-blocking: with this branch back, a token- or segmented-mode entity followed by text in the same node is turned back into text on every pass and re-made from the merged text. Setting a paragraph to #a b, with a createNode that sets token mode, throws "One or more transforms are endlessly triggering additional transforms". #9686 fixed that loop as well, but the description mentions only keyword-style entities. Since #9637 was closed by #9686's merge, reopening it with this case added would keep both loops in scope for the re-land.

@zurfyx
zurfyx added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit a7d3f98 Nov 1, 2026
57 of 58 checks passed
zurfyx added a commit that referenced this pull request Nov 2, 2026
…ttle between text nodes of other formats (re-land of #9686)

This re-lands #9686, reverted by #9702 because it turns more entities back into text (every edit that leaves a hashtag after text in another format), and turning an entity into text dropped its NodeState (#9703): joining a block that starts with a commented hashtag onto text in another format lost the comment (#9704). #9712 fixes #9703 (entities keep their NodeState when they become text) and brings the loop breaker for token and segmented entities; this PR is #9686 on top of it, unchanged otherwise, plus #9704's case and the long-session join as tests. Review the second commit; the first is #9712.

`registerLexicalTextEntity` decides whether a match at the start of a text node is an entity in two places that disagreed:

- the node's own transform made the first match in its own text an entity, without the text node before it;
- the transform of a simple text node before it checks the entity that follows it with its own text in front, and turns it back into text when that is no match.

Take plain text between two text nodes of another format (bold `x`, `dogcat`, bold `y`) and type a space after `dog`. The first transform made `dog` an entity, the second undid it (`xdog` has no match), the nodes merged again, and so on until Lexical threw "One or more transforms are endlessly triggering additional transforms" and the edit was lost (#9637).

Now a match at the start of a node is left as text when the simple text node before it would turn it straight back into text, that is when the match's text after that node's text is no match (`getMatch(previousText + matchText) === null`, the check that node's transform makes). It is still made an entity when the first match of both nodes' text is this match, which a match that depends on the text after it can be (the entity `createNode` makes may then match on its own). Any match right after one left as text stays text too, as it does after a match next to another entity. The match is still found in the node's own text, so the entity's own transform agrees as before, and the extra check is one `getMatch` call (the first match is already computed), made only for a match at the start of a node after a simple text node.

Where that transform returned early, before its loop (its text has no match after the text node before it, or the first starts in that node), it never checked the entity after it, as its loop does. So typing a letter right before a hashtag that follows text in another format left the hashtag an entity (`b#tag`), which a fresh parse of the same text does not make. In that early return the transform now turns such an entity back into text unless the transforms would keep it there (below). A match left as text at the start of the next node stays text until that node is edited, as before.

Whether the transforms keep an entity right after a simple text node is one rule, used by both transforms and by the loop's check of the next node: the first match from that node's text on, passing the matches of its text (at most 8, as the loop passes over them; past that, nothing is changed), must start where the entity does, with the text after the entity in the node it was split from (the simple text node after it in the same format, style and detail), as the check that made it an entity found it; and that match must still hold with the text of any other text node after it, as the check that keeps a match at the end of a node from becoming an entity found it. So a match that needs the text after it (`/#[a-z]+(?= )/`) is kept where it was made, and text after it in another format, or a token node, does not keep an entity that a fresh parse would not make.

An entity's own transform, when the transforms no longer keep it after the simple text node before it (the text after it changed, say), marks that node dirty, once per node for each pending editor state (other entities' transforms may leave it dirty again), so it is turned back into text in the same update rather than at the next edit of the text before it.

A token or segmented entity with text after it in its node looped on `main`: the transform of that text turns it back into text, the text merges, and the transform makes it again. #9712 keeps such an entity the third time it comes back to be turned into text in one update, and this PR keeps that rule.

Each of these checks is a few `getMatch` calls, bounded by the 8 matches passed over, only on the paths above.

A matcher whose match does not hold on the entity's own text (`/dog(?=cat)/`, with `createNode` keeping the text) still loops, on plain text too, as on `main`: the entity's own transform turns it back into text every time. `registerLexicalTextEntity` needs an entity's text to be a match on its own. Two registrations whose entities end up touching can still loop through the rule that turns two adjacent entities into text (with a hashtag and a segmented upper-case matcher, `#xabDOG` loops on `main` from a fresh parse); with one registration, or matches that cannot touch, this does not arise. The source text of an entity is told by format, style and detail; NodeState is not compared (text keeps its NodeState when it becomes an entity, but `createNode` may give the entity its own).

No API is added or changed. Entities can differ from before only next to the boundary between a simple text node and the node after it, where one of the checks above was skipped or disagreed with the other.

Closes #9637
Closes #9704

`.changeset/lexical-text-entity-settle.md` (`@lexical/text`, patch, `[fix]`).

`registerLexicalTextEntitySettle.test.ts` (new, 41 tests): the issue's two cases and its controls; a later match in the node; a lookbehind-style matcher; a hashtag-like matcher after a formatted letter and a formatted space; two entities next to each other; `dogcat` between every pair of four formats and four neighbour texts, with four typed characters; IME composition; pasting formatted runs; bolding the text before an entity; typing a letter before an entity after text in another format; a matcher whose earlier match must end where the text ends; matchers that need the text after a match (with a match at the start of a node, after typing, and after removing the text after an entity), one with a `createNode` that upper-cases; text after an entity in another format; removing the text between an entity and a token after it; a token or segmented entity with text after it in its node (loops on `main`), and one after a match left as text, with the nodes each settles on; an update that fails not counting toward the next; two registrations, one making token or segmented entities, in both orders, with the nodes they settle on; text after an entity with another detail; an entity after a node with an earlier match; an entity checked again in a later update; one dirty node per keystroke in text before a formatted hashtag, with and without an earlier match in that text (so history merges typing, as on `main`); a match at the start of the next node that typing makes valid, made an entity when that node next changes; `createNode` factories that lower-case, upper-case or add text; and a bounded number of `getMatch` calls per keystroke in a long node before an entity, however long. Then, for three matchers, 2,000 random layouts each (override with `TEXT_ENTITY_SETTLE_SEEDS`):
- a fresh parse settles, and transforming every node again leaves it as it is;
- typing or deleting anywhere in text between two nodes of other formats (#9637's shape) settles on the entities a fresh parse of the result finds;
- sessions of 4 edits (typing or deleting anywhere, bolding a node) settle, and so does transforming every node again after each (a guard against new loops: these pass on `main` too).

`Hashtags.spec.mjs`: the playground's keywords, bold `x`, `congratscongrats`, bold `y`, and a space after the first `congrats` (the loop on `main`: it needs a later match that the next node turns back into text, which a hashtag cannot be, since text after a hashtag only extends it); and hashtags typed after a bold letter and between bold text, with the exact text.

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
 × bold "x" | "dogcat" | bold "y", a space after "dog": settles, no entity
 × bold "x" | "dogcat" | bold "dog", an emoji after "dog": settles, no entity
 × entity at the edges of a node, every format combination around it
 × IME composition between two formatted nodes settles, and so does its end
 × typing a letter before an entity after text in another format turns it back into text
 × a match at the start of a node that needs the text after it settles after a formatted node
 × an entity after a node with an earlier match is checked too
 × removing the text between an entity and a token after it turns the entity back into text
 × an entity is checked again in each update
 × typing that makes a match at the start of the next node one leaves it text until that node changes
 × a token or segmented entity with text after it in its node settles
 × two registrations, one making token or segmented entities, settle
 × keyword: 2000 random layouts parse, and parse again the same
 × keyword: 2000 random edits between two formatted nodes settle on a fresh parse
 × tag: 2000 random edits between two formatted nodes settle on a fresh parse
 × lookbehind: 2000 random layouts parse, and parse again the same
 × lookbehind: 2000 random edits between two formatted nodes settle on a fresh parse
+   "seed 231 [\"_😀gdo\",\"*cat dog\",\"docatdog \",\"_gdo!g\"]: Error: One or more transforms are endlessly triggering additional transforms. Ma",
+   "seed 956 [\"_😀\",\"cat \",\"*_y\"] [[\"text\",\"😀\",2],[\"test-keyword\",\"cat\",0],[\"text\",\" \",0],[\"text\",\"y\",3]] type \"d\" at 1:0: [[\"text\",\"😀\",2],[\"text\",\"d\",0],[\"test-keyword\",\"cat\",0],[\"text\",\" \",0],[\"text\",\"y\",3]] != [[\
      Tests  17 failed | 24 passed (41)
$ TEXT_ENTITY_SEED=30449 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/TextEntityEdits.test.ts   # and 41459
Error: One or more transforms are endlessly triggering additional transforms. May have encountered infinite recursion caused by transforms that have their preconditions too lose and/or conflict with each other.
```

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
      Tests  41 passed (41)
$ TEXT_ENTITY_SETTLE_SEEDS=60000 pnpm exec vitest run --project unit --testTimeout=0 packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
      Tests  41 passed (41)
$ TEXT_ENTITY_SEED=30449 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/TextEntityEdits.test.ts   # and 41459, the seeds that found #9637
      Tests  1 passed (1)
$ pnpm run ci-check
Found 0 errors
```

`TextEntityEdits.test.ts` also passes with `TEXT_ENTITY_SEEDS=25000`. The existing `@lexical/text` tests pass unchanged, including `registerLexicalTextEntityEquivalence.test.ts`, which compares the JSON, selection, mutations and keys after 300 random editing sessions with a copy of the helper before #9483.

`registerLexicalTextEntityJoin.test.ts` (new, 5 tests): #9704's repro (a list item starting with a commented hashtag joined onto italic text), the same join by backspace and by forward delete, the long-session shape (the block before ends with a tab, all with NodeState), and a hashtag with `MarkStateExtension` comment ids joined onto italic text. Without #9712 the first three lose the NodeState (as #9686 did); with #9712 alone the hashtag stays a hashtag, as on `main`; here it becomes text with its NodeState.

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntityJoin.test.ts
      Tests  5 passed (5)
```
zurfyx added a commit that referenced this pull request Nov 2, 2026
…ttle between text nodes of other formats (re-land of #9686)

This re-lands #9686, reverted by #9702 because it turns more entities back into text (every edit that leaves a hashtag after text in another format), and turning an entity into text dropped its NodeState (#9703): joining a block that starts with a commented hashtag onto text in another format lost the comment (#9704). #9712 fixes #9703 (entities keep their NodeState when they become text) and brings the loop breaker for token and segmented entities; this PR is #9686 on top of it, unchanged otherwise, plus #9704's case and the long-session join as tests. Review the second commit; the first is #9712.

`registerLexicalTextEntity` decides whether a match at the start of a text node is an entity in two places that disagreed:

- the node's own transform made the first match in its own text an entity, without the text node before it;
- the transform of a simple text node before it checks the entity that follows it with its own text in front, and turns it back into text when that is no match.

Take plain text between two text nodes of another format (bold `x`, `dogcat`, bold `y`) and type a space after `dog`. The first transform made `dog` an entity, the second undid it (`xdog` has no match), the nodes merged again, and so on until Lexical threw "One or more transforms are endlessly triggering additional transforms" and the edit was lost (#9637).

Now a match at the start of a node is left as text when the simple text node before it would turn it straight back into text, that is when the match's text after that node's text is no match (`getMatch(previousText + matchText) === null`, the check that node's transform makes). It is still made an entity when the first match of both nodes' text is this match, which a match that depends on the text after it can be (the entity `createNode` makes may then match on its own). Any match right after one left as text stays text too, as it does after a match next to another entity. The match is still found in the node's own text, so the entity's own transform agrees as before, and the extra check is one `getMatch` call (the first match is already computed), made only for a match at the start of a node after a simple text node.

Where that transform returned early, before its loop (its text has no match after the text node before it, or the first starts in that node), it never checked the entity after it, as its loop does. So typing a letter right before a hashtag that follows text in another format left the hashtag an entity (`b#tag`), which a fresh parse of the same text does not make. In that early return the transform now turns such an entity back into text unless the transforms would keep it there (below). A match left as text at the start of the next node stays text until that node is edited, as before.

Whether the transforms keep an entity right after a simple text node is one rule, used by both transforms and by the loop's check of the next node: the first match from that node's text on, passing the matches of its text (at most 8, as the loop passes over them; past that, nothing is changed), must start where the entity does, with the text after the entity in the node it was split from (the simple text node after it in the same format, style and detail), as the check that made it an entity found it; and that match must still hold with the text of any other text node after it, as the check that keeps a match at the end of a node from becoming an entity found it. So a match that needs the text after it (`/#[a-z]+(?= )/`) is kept where it was made, and text after it in another format, or a token node, does not keep an entity that a fresh parse would not make.

An entity's own transform, when the transforms no longer keep it after the simple text node before it (the text after it changed, say), marks that node dirty, once per node for each pending editor state (other entities' transforms may leave it dirty again), so it is turned back into text in the same update rather than at the next edit of the text before it.

A token or segmented entity with text after it in its node looped on `main`: the transform of that text turns it back into text, the text merges, and the transform makes it again. #9712 keeps such an entity the third time it comes back to be turned into text in one update, and this PR keeps that rule.

Two more changes come with the re-land, for orders of transforms that #9686 alone reached before the other checks:

- A normal-mode entity grows over the text after it (takes the characters its match extends into) only when it is an entity the transforms keep: not right after another text entity (the two are turned back into text by the rule for adjacent entities), and not after a simple text node that it is no entity after (`isEntityAfter`). Otherwise it is turned back into text first, rather than grown and then turned into text with the next node's characters, which then lost their format and NodeState (two hashtags next to each other before italic text, a `createNode` that changes the case).
- Two entities next to each other are turned back into text, as before, but when the same entity comes back to that a third time in one update it is kept (the same counter as the token breaker, counted apart): entities of two registrations that touch (a segmented `$B` next to a token `@x`) looped forever on `main`; now they settle, kept as they are.

Each of these checks is a few `getMatch` calls, bounded by the 8 matches passed over, only on the paths above.

A matcher whose match does not hold on the entity's own text (`/dog(?=cat)/`, with `createNode` keeping the text) still loops, on plain text too, as on `main`: the entity's own transform turns it back into text every time. `registerLexicalTextEntity` needs an entity's text to be a match on its own. Two registrations whose entities end up touching can still loop through the rule that turns two adjacent entities into text (with a hashtag and a segmented upper-case matcher, `#xabDOG` loops on `main` from a fresh parse); with one registration, or matches that cannot touch, this does not arise. The source text of an entity is told by format, style and detail; NodeState is not compared (text keeps its NodeState when it becomes an entity, but `createNode` may give the entity its own).

No API is added or changed. Entities can differ from before only next to the boundary between a simple text node and the node after it, where one of the checks above was skipped or disagreed with the other.

Closes #9637
Closes #9704

`.changeset/lexical-text-entity-settle.md` (`@lexical/text`, patch, `[fix]`).

`registerLexicalTextEntitySettle.test.ts` (new, 41 tests): the issue's two cases and its controls; a later match in the node; a lookbehind-style matcher; a hashtag-like matcher after a formatted letter and a formatted space; two entities next to each other; `dogcat` between every pair of four formats and four neighbour texts, with four typed characters; IME composition; pasting formatted runs; bolding the text before an entity; typing a letter before an entity after text in another format; a matcher whose earlier match must end where the text ends; matchers that need the text after a match (with a match at the start of a node, after typing, and after removing the text after an entity), one with a `createNode` that upper-cases; text after an entity in another format; removing the text between an entity and a token after it; a token or segmented entity with text after it in its node (loops on `main`), and one after a match left as text, with the nodes each settles on; an update that fails not counting toward the next; two registrations, one making token or segmented entities, in both orders, with the nodes they settle on; text after an entity with another detail; an entity after a node with an earlier match; an entity checked again in a later update; one dirty node per keystroke in text before a formatted hashtag, with and without an earlier match in that text (so history merges typing, as on `main`); a match at the start of the next node that typing makes valid, made an entity when that node next changes; `createNode` factories that lower-case, upper-case or add text; and a bounded number of `getMatch` calls per keystroke in a long node before an entity, however long. Then, for three matchers, 2,000 random layouts each (override with `TEXT_ENTITY_SETTLE_SEEDS`):
- a fresh parse settles, and transforming every node again leaves it as it is;
- typing or deleting anywhere in text between two nodes of other formats (#9637's shape) settles on the entities a fresh parse of the result finds;
- sessions of 4 edits (typing or deleting anywhere, bolding a node) settle, and so does transforming every node again after each (a guard against new loops: these pass on `main` too).

`Hashtags.spec.mjs`: the playground's keywords, bold `x`, `congratscongrats`, bold `y`, and a space after the first `congrats` (the loop on `main`: it needs a later match that the next node turns back into text, which a hashtag cannot be, since text after a hashtag only extends it); and hashtags typed after a bold letter and between bold text, with the exact text.

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
 × bold "x" | "dogcat" | bold "y", a space after "dog": settles, no entity
 × bold "x" | "dogcat" | bold "dog", an emoji after "dog": settles, no entity
 × entity at the edges of a node, every format combination around it
 × IME composition between two formatted nodes settles, and so does its end
 × typing a letter before an entity after text in another format turns it back into text
 × a match at the start of a node that needs the text after it settles after a formatted node
 × an entity after a node with an earlier match is checked too
 × removing the text between an entity and a token after it turns the entity back into text
 × an entity is checked again in each update
 × typing that makes a match at the start of the next node one leaves it text until that node changes
 × a token or segmented entity with text after it in its node settles
 × two registrations, one making token or segmented entities, settle
 × keyword: 2000 random layouts parse, and parse again the same
 × keyword: 2000 random edits between two formatted nodes settle on a fresh parse
 × tag: 2000 random edits between two formatted nodes settle on a fresh parse
 × lookbehind: 2000 random layouts parse, and parse again the same
 × lookbehind: 2000 random edits between two formatted nodes settle on a fresh parse
+   "seed 231 [\"_😀gdo\",\"*cat dog\",\"docatdog \",\"_gdo!g\"]: Error: One or more transforms are endlessly triggering additional transforms. Ma",
+   "seed 956 [\"_😀\",\"cat \",\"*_y\"] [[\"text\",\"😀\",2],[\"test-keyword\",\"cat\",0],[\"text\",\" \",0],[\"text\",\"y\",3]] type \"d\" at 1:0: [[\"text\",\"😀\",2],[\"text\",\"d\",0],[\"test-keyword\",\"cat\",0],[\"text\",\" \",0],[\"text\",\"y\",3]] != [[\
      Tests  17 failed | 24 passed (41)
$ TEXT_ENTITY_SEED=30449 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/TextEntityEdits.test.ts   # and 41459
Error: One or more transforms are endlessly triggering additional transforms. May have encountered infinite recursion caused by transforms that have their preconditions too lose and/or conflict with each other.
```

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
      Tests  41 passed (41)
$ TEXT_ENTITY_SETTLE_SEEDS=60000 pnpm exec vitest run --project unit --testTimeout=0 packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
      Tests  41 passed (41)
$ TEXT_ENTITY_SEED=30449 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/TextEntityEdits.test.ts   # and 41459, the seeds that found #9637
      Tests  1 passed (1)
$ pnpm run ci-check
Found 0 errors
```

`TextEntityEdits.test.ts` also passes with `TEXT_ENTITY_SEEDS=25000`. The existing `@lexical/text` tests pass unchanged, including `registerLexicalTextEntityEquivalence.test.ts`, which compares the JSON, selection, mutations and keys after 300 random editing sessions with a copy of the helper before #9483.

`registerLexicalTextEntityJoin.test.ts` (new, 7 tests): #9704's repro (a list item starting with a commented hashtag joined onto italic text), the same join by backspace and by forward delete, a block before that ends with a tab (all with NodeState), a hashtag with `MarkStateExtension` comment ids joined onto italic text, two hashtags turned into text before italic text with NodeState (the text keeps its format, NodeState and the selection), and typing before a hashtag that a segmented and a token entity follow (settles, with a bounded number of `getMatch` calls). With #9686 alone the first three lose the NodeState and the `MarkStateExtension` one loses its comment ids; with #9712 alone the hashtag stays a hashtag, as on `main`; here it becomes text and keeps them.

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntityJoin.test.ts
      Tests  7 passed (7)
```
zurfyx added a commit that referenced this pull request Nov 2, 2026
…ttle between text nodes of other formats (re-land of #9686)

This re-lands #9686, reverted by #9702 because it turns more entities back into text (every edit that leaves a hashtag after text in another format), and turning an entity into text dropped its NodeState (#9703): joining a block that starts with a commented hashtag onto text in another format lost the comment (#9704). #9712 fixes #9703 (entities keep their NodeState when they become text) and brings the loop breaker for token and segmented entities; this PR is #9686 on top of it, unchanged otherwise, plus #9704's case and the long-session join as tests. Review the second commit; the first is #9712.

`registerLexicalTextEntity` decides whether a match at the start of a text node is an entity in two places that disagreed:

- the node's own transform made the first match in its own text an entity, without the text node before it;
- the transform of a simple text node before it checks the entity that follows it with its own text in front, and turns it back into text when that is no match.

Take plain text between two text nodes of another format (bold `x`, `dogcat`, bold `y`) and type a space after `dog`. The first transform made `dog` an entity, the second undid it (`xdog` has no match), the nodes merged again, and so on until Lexical threw "One or more transforms are endlessly triggering additional transforms" and the edit was lost (#9637).

Now a match at the start of a node is left as text when the simple text node before it would turn it straight back into text, that is when the match's text after that node's text is no match (`getMatch(previousText + matchText) === null`, the check that node's transform makes). It is still made an entity when the first match of both nodes' text is this match, which a match that depends on the text after it can be (the entity `createNode` makes may then match on its own). Any match right after one left as text stays text too, as it does after a match next to another entity. The match is still found in the node's own text, so the entity's own transform agrees as before, and the extra check is one `getMatch` call (the first match is already computed), made only for a match at the start of a node after a simple text node.

Where that transform returned early, before its loop (its text has no match after the text node before it, or the first starts in that node), it never checked the entity after it, as its loop does. So typing a letter right before a hashtag that follows text in another format left the hashtag an entity (`b#tag`), which a fresh parse of the same text does not make. In that early return the transform now turns such an entity back into text unless the transforms would keep it there (below). A match left as text at the start of the next node stays text until that node is edited, as before.

Whether the transforms keep an entity right after a simple text node is one rule, used by both transforms and by the loop's check of the next node: the first match from that node's text on, passing the matches of its text (at most 8, as the loop passes over them; past that, nothing is changed), must start where the entity does, with the text after the entity in the node it was split from (the simple text node after it in the same format, style and detail), as the check that made it an entity found it; and that match must still hold with the text of any other text node after it, as the check that keeps a match at the end of a node from becoming an entity found it. So a match that needs the text after it (`/#[a-z]+(?= )/`) is kept where it was made, and text after it in another format, or a token node, does not keep an entity that a fresh parse would not make.

An entity's own transform, when the transforms no longer keep it after the simple text node before it (the text after it changed, say), marks that node dirty, once per node for each pending editor state (other entities' transforms may leave it dirty again), so it is turned back into text in the same update rather than at the next edit of the text before it.

A token or segmented entity with text after it in its node looped on `main`: the transform of that text turns it back into text, the text merges, and the transform makes it again. #9712 keeps such an entity the third time it comes back to be turned into text in one update, and this PR keeps that rule.

Two more changes come with the re-land, for orders of transforms that #9686 alone reached before the other checks:

- A normal-mode entity grows over the text after it (takes the characters its match extends into) only when it is an entity the transforms keep: not right after another text entity (the two are turned back into text by the rule for adjacent entities), and not after a simple text node that it is no entity after (`isEntityAfter`; when that cannot tell, after too many matches in the text before, it stays as it is without growing). Otherwise it is turned back into text first, rather than grown and then turned into text with the next node's characters, which then lost their format and NodeState (two hashtags next to each other before italic text, a `createNode` that changes the case).
- Two entities next to each other are turned back into text, as before, but when the same entity comes back to that a third time in one update it is kept (the same counter as the token breaker, counted apart): entities of two registrations that touch (a segmented `$B` next to a token `@x`) looped forever on `main`; now they settle, kept as they are.

Each of these checks is a few `getMatch` calls, bounded by the 8 matches passed over, only on the paths above.

A matcher whose match does not hold on the entity's own text (`/dog(?=cat)/`, with `createNode` keeping the text) still loops, on plain text too, as on `main`: the entity's own transform turns it back into text every time. `registerLexicalTextEntity` needs an entity's text to be a match on its own. Two registrations whose entities end up touching can still loop through the rule that turns two adjacent entities into text (with a hashtag and a segmented upper-case matcher, `#xabDOG` loops on `main` from a fresh parse); with one registration, or matches that cannot touch, this does not arise. The source text of an entity is told by format, style and detail; NodeState is not compared (text keeps its NodeState when it becomes an entity, but `createNode` may give the entity its own).

No API is added or changed. Entities can differ from before only next to the boundary between a simple text node and the node after it, where one of the checks above was skipped or disagreed with the other.

Closes #9637
Closes #9704

`.changeset/lexical-text-entity-settle.md` (`@lexical/text`, patch, `[fix]`).

`registerLexicalTextEntitySettle.test.ts` (new, 41 tests): the issue's two cases and its controls; a later match in the node; a lookbehind-style matcher; a hashtag-like matcher after a formatted letter and a formatted space; two entities next to each other; `dogcat` between every pair of four formats and four neighbour texts, with four typed characters; IME composition; pasting formatted runs; bolding the text before an entity; typing a letter before an entity after text in another format; a matcher whose earlier match must end where the text ends; matchers that need the text after a match (with a match at the start of a node, after typing, and after removing the text after an entity), one with a `createNode` that upper-cases; text after an entity in another format; removing the text between an entity and a token after it; a token or segmented entity with text after it in its node (loops on `main`), and one after a match left as text, with the nodes each settles on; an update that fails not counting toward the next; two registrations, one making token or segmented entities, in both orders, with the nodes they settle on; text after an entity with another detail; an entity after a node with an earlier match; an entity checked again in a later update; one dirty node per keystroke in text before a formatted hashtag, with and without an earlier match in that text (so history merges typing, as on `main`); a match at the start of the next node that typing makes valid, made an entity when that node next changes; `createNode` factories that lower-case, upper-case or add text; and a bounded number of `getMatch` calls per keystroke in a long node before an entity, however long. Then, for three matchers, 2,000 random layouts each (override with `TEXT_ENTITY_SETTLE_SEEDS`):
- a fresh parse settles, and transforming every node again leaves it as it is;
- typing or deleting anywhere in text between two nodes of other formats (#9637's shape) settles on the entities a fresh parse of the result finds;
- sessions of 4 edits (typing or deleting anywhere, bolding a node) settle, and so does transforming every node again after each (a guard against new loops: these pass on `main` too).

`Hashtags.spec.mjs`: the playground's keywords, bold `x`, `congratscongrats`, bold `y`, and a space after the first `congrats` (the loop on `main`: it needs a later match that the next node turns back into text, which a hashtag cannot be, since text after a hashtag only extends it); and hashtags typed after a bold letter and between bold text, with the exact text.

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
 × bold "x" | "dogcat" | bold "y", a space after "dog": settles, no entity
 × bold "x" | "dogcat" | bold "dog", an emoji after "dog": settles, no entity
 × entity at the edges of a node, every format combination around it
 × IME composition between two formatted nodes settles, and so does its end
 × typing a letter before an entity after text in another format turns it back into text
 × a match at the start of a node that needs the text after it settles after a formatted node
 × an entity after a node with an earlier match is checked too
 × removing the text between an entity and a token after it turns the entity back into text
 × an entity is checked again in each update
 × typing that makes a match at the start of the next node one leaves it text until that node changes
 × a token or segmented entity with text after it in its node settles
 × two registrations, one making token or segmented entities, settle
 × keyword: 2000 random layouts parse, and parse again the same
 × keyword: 2000 random edits between two formatted nodes settle on a fresh parse
 × tag: 2000 random edits between two formatted nodes settle on a fresh parse
 × lookbehind: 2000 random layouts parse, and parse again the same
 × lookbehind: 2000 random edits between two formatted nodes settle on a fresh parse
+   "seed 231 [\"_😀gdo\",\"*cat dog\",\"docatdog \",\"_gdo!g\"]: Error: One or more transforms are endlessly triggering additional transforms. Ma",
+   "seed 956 [\"_😀\",\"cat \",\"*_y\"] [[\"text\",\"😀\",2],[\"test-keyword\",\"cat\",0],[\"text\",\" \",0],[\"text\",\"y\",3]] type \"d\" at 1:0: [[\"text\",\"😀\",2],[\"text\",\"d\",0],[\"test-keyword\",\"cat\",0],[\"text\",\" \",0],[\"text\",\"y\",3]] != [[\
      Tests  17 failed | 24 passed (41)
$ TEXT_ENTITY_SEED=30449 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/TextEntityEdits.test.ts   # and 41459
Error: One or more transforms are endlessly triggering additional transforms. May have encountered infinite recursion caused by transforms that have their preconditions too lose and/or conflict with each other.
```

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
      Tests  41 passed (41)
$ TEXT_ENTITY_SETTLE_SEEDS=60000 pnpm exec vitest run --project unit --testTimeout=0 packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
      Tests  41 passed (41)
$ TEXT_ENTITY_SEED=30449 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/TextEntityEdits.test.ts   # and 41459, the seeds that found #9637
      Tests  1 passed (1)
$ pnpm run ci-check
Found 0 errors
```

`TextEntityEdits.test.ts` also passes with `TEXT_ENTITY_SEEDS=25000`. The existing `@lexical/text` tests pass unchanged, including `registerLexicalTextEntityEquivalence.test.ts`, which compares the JSON, selection, mutations and keys after 300 random editing sessions with a copy of the helper before #9483.

`packages/lexical-y/src/__tests__/unit/EntityUndoSpread.test.ts` (new, `test.fails`, #9716): two peers; a comment removed by one peer and both peers' undos leave the comment on every block after it. A `@lexical/y` bug (undo restores a mark opener without its closer), on `main` too with this test; this change reaches it more often because entities keep their comments. Pinned so it flips when #9716 is fixed.

`registerLexicalTextEntityJoin.test.ts` (new, 9 tests): #9704's repro (a list item starting with a commented hashtag joined onto italic text), the same join by backspace and by forward delete, a block before that ends with a tab (all with NodeState), a hashtag with `MarkStateExtension` comment ids joined onto italic text, two hashtags turned into text before italic text with NodeState (the text keeps its format, NodeState and the selection), typing before a hashtag that a segmented and a token entity follow (settles, with a bounded number of `getMatch` calls), and a hashtag after text with 7 and 8 earlier matches (the most `isEntityAfter` checks) that does not grow over the commented italic text after it. With #9686 alone the first three lose the NodeState and the `MarkStateExtension` one loses its comment ids; with #9712 alone the hashtag stays a hashtag, as on `main`; here it becomes text and keeps them.

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntityJoin.test.ts
      Tests  9 passed (9)
```
zurfyx added a commit that referenced this pull request Nov 2, 2026
…ttle between text nodes of other formats (re-land of #9686)

This re-lands #9686, reverted by #9702 because it turns more entities back into text (every edit that leaves a hashtag after text in another format), and turning an entity into text dropped its NodeState (#9703): joining a block that starts with a commented hashtag onto text in another format lost the comment (#9704). #9712 fixes #9703 (entities keep their NodeState when they become text) and brings the loop breaker for token and segmented entities; this PR is #9686 on top of it, unchanged otherwise, plus #9704's case and the long-session join as tests. Review the second commit; the first is #9712.

`registerLexicalTextEntity` decides whether a match at the start of a text node is an entity in two places that disagreed:

- the node's own transform made the first match in its own text an entity, without the text node before it;
- the transform of a simple text node before it checks the entity that follows it with its own text in front, and turns it back into text when that is no match.

Take plain text between two text nodes of another format (bold `x`, `dogcat`, bold `y`) and type a space after `dog`. The first transform made `dog` an entity, the second undid it (`xdog` has no match), the nodes merged again, and so on until Lexical threw "One or more transforms are endlessly triggering additional transforms" and the edit was lost (#9637).

Now a match at the start of a node is left as text when the simple text node before it would turn it straight back into text, that is when the match's text after that node's text is no match (`getMatch(previousText + matchText) === null`, the check that node's transform makes). It is still made an entity when the first match of both nodes' text is this match, which a match that depends on the text after it can be (the entity `createNode` makes may then match on its own). Any match right after one left as text stays text too, as it does after a match next to another entity. The match is still found in the node's own text, so the entity's own transform agrees as before, and the extra check is one `getMatch` call (the first match is already computed), made only for a match at the start of a node after a simple text node.

Where that transform returned early, before its loop (its text has no match after the text node before it, or the first starts in that node), it never checked the entity after it, as its loop does. So typing a letter right before a hashtag that follows text in another format left the hashtag an entity (`b#tag`), which a fresh parse of the same text does not make. In that early return the transform now turns such an entity back into text unless the transforms would keep it there (below). A match left as text at the start of the next node stays text until that node is edited, as before.

Whether the transforms keep an entity right after a simple text node is one rule, used by both transforms and by the loop's check of the next node: the first match from that node's text on, passing the matches of its text (at most 8, as the loop passes over them; past that, nothing is changed), must start where the entity does, with the text after the entity in the node it was split from (the simple text node after it in the same format, style and detail), as the check that made it an entity found it; and that match must still hold with the text of any other text node after it, as the check that keeps a match at the end of a node from becoming an entity found it. So a match that needs the text after it (`/#[a-z]+(?= )/`) is kept where it was made, and text after it in another format, or a token node, does not keep an entity that a fresh parse would not make.

An entity's own transform, when the transforms no longer keep it after the simple text node before it (the text after it changed, say), marks that node dirty, once per node for each pending editor state (other entities' transforms may leave it dirty again), so it is turned back into text in the same update rather than at the next edit of the text before it.

A token or segmented entity with text after it in its node looped on `main`: the transform of that text turns it back into text, the text merges, and the transform makes it again. #9712 keeps such an entity the third time it comes back to be turned into text in one update, and this PR keeps that rule.

Two more changes come with the re-land, for orders of transforms that #9686 alone reached before the other checks:

- A normal-mode entity grows over the text after it (takes the characters its match extends into) only when it is an entity the transforms keep: not right after another text entity (the two are turned back into text by the rule for adjacent entities), and not after a simple text node that it is no entity after (`isEntityAfter`; when that cannot tell, after too many matches in the text before, it stays as it is without growing, and the text after it is parsed as usual). Otherwise it is turned back into text first, rather than grown and then turned into text with the next node's characters, which then lost their format and NodeState (two hashtags next to each other before italic text, a `createNode` that changes the case).
- Two entities next to each other are turned back into text, as before, but when the same entity comes back to that a third time in one update it is kept (the same counter as the token breaker, counted apart): entities of two registrations that touch (a segmented `$B` next to a token `@x`) looped forever on `main`; now they settle, kept as they are.

Each of these checks is a few `getMatch` calls, bounded by the 8 matches passed over, only on the paths above.

A matcher whose match does not hold on the entity's own text (`/dog(?=cat)/`, with `createNode` keeping the text) still loops, on plain text too, as on `main`: the entity's own transform turns it back into text every time. `registerLexicalTextEntity` needs an entity's text to be a match on its own. Two registrations whose entities end up touching can still loop through the rule that turns two adjacent entities into text (with a hashtag and a segmented upper-case matcher, `#xabDOG` loops on `main` from a fresh parse); with one registration, or matches that cannot touch, this does not arise. The source text of an entity is told by format, style and detail; NodeState is not compared (text keeps its NodeState when it becomes an entity, but `createNode` may give the entity its own).

No API is added or changed. Entities can differ from before only next to the boundary between a simple text node and the node after it, where one of the checks above was skipped or disagreed with the other.

Closes #9637
Closes #9704

`.changeset/lexical-text-entity-settle.md` (`@lexical/text`, patch, `[fix]`).

`registerLexicalTextEntitySettle.test.ts` (new, 41 tests): the issue's two cases and its controls; a later match in the node; a lookbehind-style matcher; a hashtag-like matcher after a formatted letter and a formatted space; two entities next to each other; `dogcat` between every pair of four formats and four neighbour texts, with four typed characters; IME composition; pasting formatted runs; bolding the text before an entity; typing a letter before an entity after text in another format; a matcher whose earlier match must end where the text ends; matchers that need the text after a match (with a match at the start of a node, after typing, and after removing the text after an entity), one with a `createNode` that upper-cases; text after an entity in another format; removing the text between an entity and a token after it; a token or segmented entity with text after it in its node (loops on `main`), and one after a match left as text, with the nodes each settles on; an update that fails not counting toward the next; two registrations, one making token or segmented entities, in both orders, with the nodes they settle on; text after an entity with another detail; an entity after a node with an earlier match; an entity checked again in a later update; one dirty node per keystroke in text before a formatted hashtag, with and without an earlier match in that text (so history merges typing, as on `main`); a match at the start of the next node that typing makes valid, made an entity when that node next changes; `createNode` factories that lower-case, upper-case or add text; and a bounded number of `getMatch` calls per keystroke in a long node before an entity, however long. Then, for three matchers, 2,000 random layouts each (override with `TEXT_ENTITY_SETTLE_SEEDS`):
- a fresh parse settles, and transforming every node again leaves it as it is;
- typing or deleting anywhere in text between two nodes of other formats (#9637's shape) settles on the entities a fresh parse of the result finds;
- sessions of 4 edits (typing or deleting anywhere, bolding a node) settle, and so does transforming every node again after each (a guard against new loops: these pass on `main` too).

`Hashtags.spec.mjs`: the playground's keywords, bold `x`, `congratscongrats`, bold `y`, and a space after the first `congrats` (the loop on `main`: it needs a later match that the next node turns back into text, which a hashtag cannot be, since text after a hashtag only extends it); and hashtags typed after a bold letter and between bold text, with the exact text.

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
 × bold "x" | "dogcat" | bold "y", a space after "dog": settles, no entity
 × bold "x" | "dogcat" | bold "dog", an emoji after "dog": settles, no entity
 × entity at the edges of a node, every format combination around it
 × IME composition between two formatted nodes settles, and so does its end
 × typing a letter before an entity after text in another format turns it back into text
 × a match at the start of a node that needs the text after it settles after a formatted node
 × an entity after a node with an earlier match is checked too
 × removing the text between an entity and a token after it turns the entity back into text
 × an entity is checked again in each update
 × typing that makes a match at the start of the next node one leaves it text until that node changes
 × a token or segmented entity with text after it in its node settles
 × two registrations, one making token or segmented entities, settle
 × keyword: 2000 random layouts parse, and parse again the same
 × keyword: 2000 random edits between two formatted nodes settle on a fresh parse
 × tag: 2000 random edits between two formatted nodes settle on a fresh parse
 × lookbehind: 2000 random layouts parse, and parse again the same
 × lookbehind: 2000 random edits between two formatted nodes settle on a fresh parse
+   "seed 231 [\"_😀gdo\",\"*cat dog\",\"docatdog \",\"_gdo!g\"]: Error: One or more transforms are endlessly triggering additional transforms. Ma",
+   "seed 956 [\"_😀\",\"cat \",\"*_y\"] [[\"text\",\"😀\",2],[\"test-keyword\",\"cat\",0],[\"text\",\" \",0],[\"text\",\"y\",3]] type \"d\" at 1:0: [[\"text\",\"😀\",2],[\"text\",\"d\",0],[\"test-keyword\",\"cat\",0],[\"text\",\" \",0],[\"text\",\"y\",3]] != [[\
      Tests  17 failed | 24 passed (41)
$ TEXT_ENTITY_SEED=30449 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/TextEntityEdits.test.ts   # and 41459
Error: One or more transforms are endlessly triggering additional transforms. May have encountered infinite recursion caused by transforms that have their preconditions too lose and/or conflict with each other.
```

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
      Tests  41 passed (41)
$ TEXT_ENTITY_SETTLE_SEEDS=60000 pnpm exec vitest run --project unit --testTimeout=0 packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
      Tests  41 passed (41)
$ TEXT_ENTITY_SEED=30449 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/TextEntityEdits.test.ts   # and 41459, the seeds that found #9637
      Tests  1 passed (1)
$ pnpm run ci-check
Found 0 errors
```

`TextEntityEdits.test.ts` also passes with `TEXT_ENTITY_SEEDS=25000`. The existing `@lexical/text` tests pass unchanged, including `registerLexicalTextEntityEquivalence.test.ts`, which compares the JSON, selection, mutations and keys after 300 random editing sessions with a copy of the helper before #9483.

`packages/lexical-y/src/__tests__/unit/EntityUndoSpread.test.ts` (new, `test.fails`, #9716): two peers; a comment removed by one peer and both peers' undos leave the comment on every block after it. A `@lexical/y` bug (undo restores a mark opener without its closer), on `main` too with this test; this change reaches it more often because entities keep their comments. Pinned so it flips when #9716 is fixed.

`registerLexicalTextEntityJoin.test.ts` (new, 11 tests): #9704's repro (a list item starting with a commented hashtag joined onto italic text), the same join by backspace and by forward delete, a block before that ends with a tab (all with NodeState), a hashtag with `MarkStateExtension` comment ids joined onto italic text, two hashtags turned into text before italic text with NodeState (the text keeps its format, NodeState and the selection), typing before a hashtag that a segmented and a token entity follow (settles, with a bounded number of `getMatch` calls), and a hashtag after text with 7 and 8 earlier matches (the most `isEntityAfter` checks) that does not grow over the commented italic text after it, while a later hashtag in that text is still made. With #9686 alone the first three lose the NodeState and the `MarkStateExtension` one loses its comment ids; with #9712 alone the hashtag stays a hashtag, as on `main`; here it becomes text and keeps them.

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntityJoin.test.ts
      Tests  11 passed (11)
```
zurfyx added a commit that referenced this pull request Nov 2, 2026
…ttle between text nodes of other formats (re-land of #9686)

This re-lands #9686, reverted by #9702 because it turns more entities back into text (every edit that leaves a hashtag after text in another format), and turning an entity into text dropped its NodeState (#9703): joining a block that starts with a commented hashtag onto text in another format lost the comment (#9704). #9712 fixes #9703 (entities keep their NodeState when they become text) and brings the loop breaker for token and segmented entities; this PR is #9686 on top of it, unchanged otherwise, plus #9704's case and the long-session join as tests. Review the second commit; the first is #9712.

`registerLexicalTextEntity` decides whether a match at the start of a text node is an entity in two places that disagreed:

- the node's own transform made the first match in its own text an entity, without the text node before it;
- the transform of a simple text node before it checks the entity that follows it with its own text in front, and turns it back into text when that is no match.

Take plain text between two text nodes of another format (bold `x`, `dogcat`, bold `y`) and type a space after `dog`. The first transform made `dog` an entity, the second undid it (`xdog` has no match), the nodes merged again, and so on until Lexical threw "One or more transforms are endlessly triggering additional transforms" and the edit was lost (#9637).

Now a match at the start of a node is left as text when the simple text node before it would turn it straight back into text, that is when the match's text after that node's text is no match (`getMatch(previousText + matchText) === null`, the check that node's transform makes). It is still made an entity when the first match of both nodes' text is this match, which a match that depends on the text after it can be (the entity `createNode` makes may then match on its own). Any match right after one left as text stays text too, as it does after a match next to another entity. The match is still found in the node's own text, so the entity's own transform agrees as before, and the extra check is one `getMatch` call (the first match is already computed), made only for a match at the start of a node after a simple text node.

Where that transform returned early, before its loop (its text has no match after the text node before it, or the first starts in that node), it never checked the entity after it, as its loop does. So typing a letter right before a hashtag that follows text in another format left the hashtag an entity (`b#tag`), which a fresh parse of the same text does not make. In that early return the transform now turns such an entity back into text unless the transforms would keep it there (below). A match left as text at the start of the next node stays text until that node is edited, as before.

Whether the transforms keep an entity right after a simple text node is one rule, used by both transforms and by the loop's check of the next node: the first match from that node's text on, passing the matches of its text (at most 8, as the loop passes over them; past that, nothing is changed), must start where the entity does, with the text after the entity in the node it was split from (the simple text node after it in the same format, style and detail), as the check that made it an entity found it; and that match must still hold with the text of any other text node after it, as the check that keeps a match at the end of a node from becoming an entity found it. So a match that needs the text after it (`/#[a-z]+(?= )/`) is kept where it was made, and text after it in another format, or a token node, does not keep an entity that a fresh parse would not make.

An entity's own transform, when the transforms no longer keep it after the simple text node before it (the text after it changed, say), marks that node dirty, once per node for each pending editor state (other entities' transforms may leave it dirty again), so it is turned back into text in the same update rather than at the next edit of the text before it.

A token or segmented entity with text after it in its node looped on `main`: the transform of that text turns it back into text, the text merges, and the transform makes it again. #9712 keeps such an entity the third time it comes back to be turned into text in one update, and this PR keeps that rule.

Two more changes come with the re-land, for orders of transforms that #9686 alone reached before the other checks:

- A normal-mode entity grows over the text after it (takes the characters its match extends into) only when it is an entity the transforms keep: not right after another text entity (the two are turned back into text by the rule for adjacent entities), and not after a simple text node that it is no entity after (`isEntityAfter`; when that cannot tell, after too many matches in the text before, it stays as it is without growing, and the text after it is parsed as usual). Otherwise it is turned back into text first, rather than grown and then turned into text with the next node's characters, which then lost their format and NodeState (two hashtags next to each other before italic text, a `createNode` that changes the case).
- Two entities next to each other are turned back into text, as before, but when the same entity comes back to that a third time in one update it is kept (the same counter as the token breaker, counted apart): entities of two registrations that touch (a segmented `$B` next to a token `@x`) looped forever on `main`; now they settle, kept as they are.

Each of these checks is a few `getMatch` calls, bounded by the 8 matches passed over, only on the paths above.

A matcher whose match does not hold on the entity's own text (`/dog(?=cat)/`, with `createNode` keeping the text) still loops, on plain text too, as on `main`: the entity's own transform turns it back into text every time. `registerLexicalTextEntity` needs an entity's text to be a match on its own. Two registrations whose entities end up touching can still loop through the rule that turns two adjacent entities into text (with a hashtag and a segmented upper-case matcher, `#xabDOG` loops on `main` from a fresh parse); with one registration, or matches that cannot touch, this does not arise. The source text of an entity is told by format, style and detail; NodeState is not compared (text keeps its NodeState when it becomes an entity, but `createNode` may give the entity its own).

No API is added or changed. Entities can differ from before only next to the boundary between a simple text node and the node after it, where one of the checks above was skipped or disagreed with the other.

Closes #9637
Closes #9704

`.changeset/lexical-text-entity-settle.md` (`@lexical/text`, patch, `[fix]`).

`registerLexicalTextEntitySettle.test.ts` (new, 41 tests): the issue's two cases and its controls; a later match in the node; a lookbehind-style matcher; a hashtag-like matcher after a formatted letter and a formatted space; two entities next to each other; `dogcat` between every pair of four formats and four neighbour texts, with four typed characters; IME composition; pasting formatted runs; bolding the text before an entity; typing a letter before an entity after text in another format; a matcher whose earlier match must end where the text ends; matchers that need the text after a match (with a match at the start of a node, after typing, and after removing the text after an entity), one with a `createNode` that upper-cases; text after an entity in another format; removing the text between an entity and a token after it; a token or segmented entity with text after it in its node (loops on `main`), and one after a match left as text, with the nodes each settles on; an update that fails not counting toward the next; two registrations, one making token or segmented entities, in both orders, with the nodes they settle on; text after an entity with another detail; an entity after a node with an earlier match; an entity checked again in a later update; one dirty node per keystroke in text before a formatted hashtag, with and without an earlier match in that text (so history merges typing, as on `main`); a match at the start of the next node that typing makes valid, made an entity when that node next changes; `createNode` factories that lower-case, upper-case or add text; and a bounded number of `getMatch` calls per keystroke in a long node before an entity, however long. Then, for three matchers, 2,000 random layouts each (override with `TEXT_ENTITY_SETTLE_SEEDS`):
- a fresh parse settles, and transforming every node again leaves it as it is;
- typing or deleting anywhere in text between two nodes of other formats (#9637's shape) settles on the entities a fresh parse of the result finds;
- sessions of 4 edits (typing or deleting anywhere, bolding a node) settle, and so does transforming every node again after each (a guard against new loops: these pass on `main` too).

`Hashtags.spec.mjs`: the playground's keywords, bold `x`, `congratscongrats`, bold `y`, and a space after the first `congrats` (the loop on `main`: it needs a later match that the next node turns back into text, which a hashtag cannot be, since text after a hashtag only extends it); and hashtags typed after a bold letter and between bold text, with the exact text.

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
 × bold "x" | "dogcat" | bold "y", a space after "dog": settles, no entity
 × bold "x" | "dogcat" | bold "dog", an emoji after "dog": settles, no entity
 × entity at the edges of a node, every format combination around it
 × IME composition between two formatted nodes settles, and so does its end
 × typing a letter before an entity after text in another format turns it back into text
 × a match at the start of a node that needs the text after it settles after a formatted node
 × an entity after a node with an earlier match is checked too
 × removing the text between an entity and a token after it turns the entity back into text
 × an entity is checked again in each update
 × typing that makes a match at the start of the next node one leaves it text until that node changes
 × a token or segmented entity with text after it in its node settles
 × two registrations, one making token or segmented entities, settle
 × keyword: 2000 random layouts parse, and parse again the same
 × keyword: 2000 random edits between two formatted nodes settle on a fresh parse
 × tag: 2000 random edits between two formatted nodes settle on a fresh parse
 × lookbehind: 2000 random layouts parse, and parse again the same
 × lookbehind: 2000 random edits between two formatted nodes settle on a fresh parse
+   "seed 231 [\"_😀gdo\",\"*cat dog\",\"docatdog \",\"_gdo!g\"]: Error: One or more transforms are endlessly triggering additional transforms. Ma",
+   "seed 956 [\"_😀\",\"cat \",\"*_y\"] [[\"text\",\"😀\",2],[\"test-keyword\",\"cat\",0],[\"text\",\" \",0],[\"text\",\"y\",3]] type \"d\" at 1:0: [[\"text\",\"😀\",2],[\"text\",\"d\",0],[\"test-keyword\",\"cat\",0],[\"text\",\" \",0],[\"text\",\"y\",3]] != [[\
      Tests  17 failed | 24 passed (41)
$ TEXT_ENTITY_SEED=30449 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/TextEntityEdits.test.ts   # and 41459
Error: One or more transforms are endlessly triggering additional transforms. May have encountered infinite recursion caused by transforms that have their preconditions too lose and/or conflict with each other.
```

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
      Tests  41 passed (41)
$ TEXT_ENTITY_SETTLE_SEEDS=60000 pnpm exec vitest run --project unit --testTimeout=0 packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
      Tests  41 passed (41)
$ TEXT_ENTITY_SEED=30449 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/TextEntityEdits.test.ts   # and 41459, the seeds that found #9637
      Tests  1 passed (1)
$ pnpm run ci-check
Found 0 errors
```

`TextEntityEdits.test.ts` also passes with `TEXT_ENTITY_SEEDS=25000`. The existing `@lexical/text` tests pass unchanged, including `registerLexicalTextEntityEquivalence.test.ts`, which compares the JSON, selection, mutations and keys after 300 random editing sessions with a copy of the helper before #9483.

`packages/lexical-y/src/__tests__/unit/EntityUndoSpread.test.ts` (new, `test.fails`, #9716): two peers; a comment removed by one peer and both peers' undos leave the comment on every block after it. A `@lexical/y` bug (undo restores a mark opener without its closer), on `main` too with this test; this change reaches it more often because entities keep their comments. Pinned so it flips when #9716 is fixed.

`registerLexicalTextEntityJoin.test.ts` (new, 11 tests): #9704's repro (a list item starting with a commented hashtag joined onto italic text), the same join by backspace and by forward delete, a block before that ends with a tab (all with NodeState), a hashtag with `MarkStateExtension` comment ids joined onto italic text, two hashtags turned into text before italic text with NodeState (the text keeps its format, NodeState and the selection), typing before a hashtag that a segmented and a token entity follow (settles, with a bounded number of `getMatch` calls), and a hashtag after text with 7 and 8 earlier matches (the most `isEntityAfter` checks) that does not grow over the commented italic text after it, while a later hashtag in that text is still made. With #9686 alone the first three lose the NodeState and the `MarkStateExtension` one loses its comment ids; with #9712 alone the hashtag stays a hashtag, as on `main`; here it becomes text and keeps them.

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntityJoin.test.ts
      Tests  11 passed (11)
```
zurfyx added a commit that referenced this pull request Nov 2, 2026
…ttle between text nodes of other formats (re-land of #9686)

This re-lands #9686, reverted by #9702 because it turns more entities back into text (every edit that leaves a hashtag after text in another format), and turning an entity into text dropped its NodeState (#9703): joining a block that starts with a commented hashtag onto text in another format lost the comment (#9704). #9712 fixes #9703 (entities keep their NodeState when they become text) and brings the loop breaker for token and segmented entities; this PR is #9686 on top of it, unchanged otherwise, plus #9704's case and the long-session join as tests. Review the second commit; the first is #9712.

`registerLexicalTextEntity` decides whether a match at the start of a text node is an entity in two places that disagreed:

- the node's own transform made the first match in its own text an entity, without the text node before it;
- the transform of a simple text node before it checks the entity that follows it with its own text in front, and turns it back into text when that is no match.

Take plain text between two text nodes of another format (bold `x`, `dogcat`, bold `y`) and type a space after `dog`. The first transform made `dog` an entity, the second undid it (`xdog` has no match), the nodes merged again, and so on until Lexical threw "One or more transforms are endlessly triggering additional transforms" and the edit was lost (#9637).

Now a match at the start of a node is left as text when the simple text node before it would turn it straight back into text, that is when the match's text after that node's text is no match (`getMatch(previousText + matchText) === null`, the check that node's transform makes). It is still made an entity when the first match of both nodes' text is this match, which a match that depends on the text after it can be (the entity `createNode` makes may then match on its own). Any match right after one left as text stays text too, as it does after a match next to another entity. The match is still found in the node's own text, so the entity's own transform agrees as before, and the extra check is one `getMatch` call (the first match is already computed), made only for a match at the start of a node after a simple text node.

Where that transform returned early, before its loop (its text has no match after the text node before it, or the first starts in that node), it never checked the entity after it, as its loop does. So typing a letter right before a hashtag that follows text in another format left the hashtag an entity (`b#tag`), which a fresh parse of the same text does not make. In that early return the transform now turns such an entity back into text unless the transforms would keep it there (below). A match left as text at the start of the next node stays text until that node is edited, as before.

Whether the transforms keep an entity right after a simple text node is one rule, used by both transforms and by the loop's check of the next node: the first match from that node's text on, passing the matches of its text (at most 8, as the loop passes over them; past that, nothing is changed), must start where the entity does, with the text after the entity in the node it was split from (the simple text node after it in the same format, style and detail), as the check that made it an entity found it; and that match must still hold with the text of any other text node after it, as the check that keeps a match at the end of a node from becoming an entity found it. So a match that needs the text after it (`/#[a-z]+(?= )/`) is kept where it was made, and text after it in another format, or a token node, does not keep an entity that a fresh parse would not make.

An entity's own transform, when the transforms no longer keep it after the simple text node before it (the text after it changed, say), marks that node dirty, once per node for each pending editor state (other entities' transforms may leave it dirty again), so it is turned back into text in the same update rather than at the next edit of the text before it.

A token or segmented entity with text after it in its node looped on `main`: the transform of that text turns it back into text, the text merges, and the transform makes it again. #9712 keeps such an entity the third time it comes back to be turned into text in one update, and this PR keeps that rule.

Two more changes come with the re-land, for orders of transforms that #9686 alone reached before the other checks:

- A normal-mode entity grows over the text after it (takes the characters its match extends into) only when it is an entity the transforms keep: not right after another text entity (the two are turned back into text by the rule for adjacent entities), and not after a simple text node that it is no entity after (`isEntityAfter`; when that cannot tell, after too many matches in the text before, it stays as it is without growing, and the text after it is parsed as usual). Otherwise it is turned back into text first, rather than grown and then turned into text with the next node's characters, which then lost their format and NodeState (two hashtags next to each other before italic text, a `createNode` that changes the case).
- Two entities next to each other are turned back into text, as before, but when the same entity comes back to that a third time in one update it is kept (the same counter as the token breaker, counted apart): entities of two registrations that touch (a segmented `$B` next to a token `@x`) looped forever on `main`; now they settle, kept as they are.

Each of these checks is a few `getMatch` calls, bounded by the 8 matches passed over, only on the paths above.

A matcher whose match does not hold on the entity's own text (`/dog(?=cat)/`, with `createNode` keeping the text) still loops, on plain text too, as on `main`: the entity's own transform turns it back into text every time. `registerLexicalTextEntity` needs an entity's text to be a match on its own. Two registrations whose entities end up touching can still loop through the rule that turns two adjacent entities into text (with a hashtag and a segmented upper-case matcher, `#xabDOG` loops on `main` from a fresh parse); with one registration, or matches that cannot touch, this does not arise. The source text of an entity is told by format, style and detail; NodeState is not compared (text keeps its NodeState when it becomes an entity, but `createNode` may give the entity its own).

No API is added or changed. Entities can differ from before only next to the boundary between a simple text node and the node after it, where one of the checks above was skipped or disagreed with the other.

Closes #9637
Closes #9704

`.changeset/lexical-text-entity-settle.md` (`@lexical/text`, patch, `[fix]`).

`registerLexicalTextEntitySettle.test.ts` (new, 41 tests): the issue's two cases and its controls; a later match in the node; a lookbehind-style matcher; a hashtag-like matcher after a formatted letter and a formatted space; two entities next to each other; `dogcat` between every pair of four formats and four neighbour texts, with four typed characters; IME composition; pasting formatted runs; bolding the text before an entity; typing a letter before an entity after text in another format; a matcher whose earlier match must end where the text ends; matchers that need the text after a match (with a match at the start of a node, after typing, and after removing the text after an entity), one with a `createNode` that upper-cases; text after an entity in another format; removing the text between an entity and a token after it; a token or segmented entity with text after it in its node (loops on `main`), and one after a match left as text, with the nodes each settles on; an update that fails not counting toward the next; two registrations, one making token or segmented entities, in both orders, with the nodes they settle on; text after an entity with another detail; an entity after a node with an earlier match; an entity checked again in a later update; one dirty node per keystroke in text before a formatted hashtag, with and without an earlier match in that text (so history merges typing, as on `main`); a match at the start of the next node that typing makes valid, made an entity when that node next changes; `createNode` factories that lower-case, upper-case or add text; and a bounded number of `getMatch` calls per keystroke in a long node before an entity, however long. Then, for three matchers, 2,000 random layouts each (override with `TEXT_ENTITY_SETTLE_SEEDS`):
- a fresh parse settles, and transforming every node again leaves it as it is;
- typing or deleting anywhere in text between two nodes of other formats (#9637's shape) settles on the entities a fresh parse of the result finds;
- sessions of 4 edits (typing or deleting anywhere, bolding a node) settle, and so does transforming every node again after each (a guard against new loops: these pass on `main` too).

`Hashtags.spec.mjs`: the playground's keywords, bold `x`, `congratscongrats`, bold `y`, and a space after the first `congrats` (the loop on `main`: it needs a later match that the next node turns back into text, which a hashtag cannot be, since text after a hashtag only extends it); and hashtags typed after a bold letter and between bold text, with the exact text.

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
 × bold "x" | "dogcat" | bold "y", a space after "dog": settles, no entity
 × bold "x" | "dogcat" | bold "dog", an emoji after "dog": settles, no entity
 × entity at the edges of a node, every format combination around it
 × IME composition between two formatted nodes settles, and so does its end
 × typing a letter before an entity after text in another format turns it back into text
 × a match at the start of a node that needs the text after it settles after a formatted node
 × an entity after a node with an earlier match is checked too
 × removing the text between an entity and a token after it turns the entity back into text
 × an entity is checked again in each update
 × typing that makes a match at the start of the next node one leaves it text until that node changes
 × a token or segmented entity with text after it in its node settles
 × two registrations, one making token or segmented entities, settle
 × keyword: 2000 random layouts parse, and parse again the same
 × keyword: 2000 random edits between two formatted nodes settle on a fresh parse
 × tag: 2000 random edits between two formatted nodes settle on a fresh parse
 × lookbehind: 2000 random layouts parse, and parse again the same
 × lookbehind: 2000 random edits between two formatted nodes settle on a fresh parse
+   "seed 231 [\"_😀gdo\",\"*cat dog\",\"docatdog \",\"_gdo!g\"]: Error: One or more transforms are endlessly triggering additional transforms. Ma",
+   "seed 956 [\"_😀\",\"cat \",\"*_y\"] [[\"text\",\"😀\",2],[\"test-keyword\",\"cat\",0],[\"text\",\" \",0],[\"text\",\"y\",3]] type \"d\" at 1:0: [[\"text\",\"😀\",2],[\"text\",\"d\",0],[\"test-keyword\",\"cat\",0],[\"text\",\" \",0],[\"text\",\"y\",3]] != [[\
      Tests  17 failed | 24 passed (41)
$ TEXT_ENTITY_SEED=30449 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/TextEntityEdits.test.ts   # and 41459
Error: One or more transforms are endlessly triggering additional transforms. May have encountered infinite recursion caused by transforms that have their preconditions too lose and/or conflict with each other.
```

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
      Tests  41 passed (41)
$ TEXT_ENTITY_SETTLE_SEEDS=60000 pnpm exec vitest run --project unit --testTimeout=0 packages/lexical-text/src/__tests__/unit/registerLexicalTextEntitySettle.test.ts
      Tests  41 passed (41)
$ TEXT_ENTITY_SEED=30449 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/TextEntityEdits.test.ts   # and 41459, the seeds that found #9637
      Tests  1 passed (1)
$ pnpm run ci-check
Found 0 errors
```

`TextEntityEdits.test.ts` also passes with `TEXT_ENTITY_SEEDS=25000`. The existing `@lexical/text` tests pass unchanged, including `registerLexicalTextEntityEquivalence.test.ts`, which compares the JSON, selection, mutations and keys after 300 random editing sessions with a copy of the helper before #9483.

`packages/lexical-y/src/__tests__/unit/EntityUndoSpread.test.ts` (new, `test.fails`, #9716): two peers; a comment removed by one peer and both peers' undos leave the comment on every block after it. A `@lexical/y` bug (undo restores a mark opener without its closer), on `main` too with this test; this change reaches it more often because entities keep their comments. Pinned so it flips when #9716 is fixed.

`registerLexicalTextEntityJoin.test.ts` (new, 11 tests): #9704's repro (a list item starting with a commented hashtag joined onto italic text), the same join by backspace and by forward delete, a block before that ends with a tab (all with NodeState), a hashtag with `MarkStateExtension` comment ids joined onto italic text, two hashtags turned into text before italic text with NodeState (the text keeps its format, NodeState and the selection), typing before a hashtag that a segmented and a token entity follow (settles, with a bounded number of `getMatch` calls), and a hashtag after text with 7 and 8 earlier matches (the most `isEntityAfter` checks) that does not grow over the commented italic text after it, while a later hashtag in that text is still made. With #9686 alone the first three lose the NodeState and the `MarkStateExtension` one loses its comment ids; with #9712 alone the hashtag stays a hashtag, as on `main`; here it becomes text and keeps them.

```
$ pnpm exec vitest run --project unit packages/lexical-text/src/__tests__/unit/registerLexicalTextEntityJoin.test.ts
      Tests  11 passed (11)
```

This branch was successfully deployed

2 active deployments
Preview – lexical — f9ea110a Deployed Nov 1, 2026 by vercel[bot]
Preview – lexical-playground — f9ea110a Deployed Nov 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant