Skip to content

[lexical-website] Documentation Update: document the full update-listener payload and the cascade guard - #9227

Merged
etrepum merged 1 commit into
meta:mainfrom
potatowagon:docs-listeners-payload-and-cascade
Sep 25, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
potatowagon:docs-listeners-payload-and-cascade

Conversation

@potatowagon

Copy link
Copy Markdown
Contributor

Description

Two gaps in concepts/listeners.md:

  1. The update-listener payload is listed as three properties —
    editorState, prevEditorState, tags. UpdateListenerPayload has
    seven: dirtyElements, dirtyLeaves, mutatedNodes and
    normalizedNodes are also passed, and a listener that wants to react to
    what changed needs them.
  2. Waterfall updates are described as only a performance problem — "two
    DOM updates, when we likely could have done it in a single DOM update".
    There is also a hard guard: past 100 cascading updates without yielding to
    the event loop, the editor discards its entire pending update queue and
    warns. A listener that re-enqueues in a loop therefore loses queued work
    silently, which is not a performance characteristic. Nothing in the docs
    tree mentions it.

Descriptions are taken from the doc comments on the payload interface.

Test plan

Documentation-only change (markdown is excluded from prettier via
.prettierignore), so the check is that the documented payload matches the
type and that the guard exists.

Before

$ sed -n '29,31p' packages/lexical-website/docs/concepts/listeners.md
- `editorState` the latest updated Editor State
- `prevEditorState` the previous Editor State
- `tags` a Set of all tags that were passed to the update

$ grep -n "^  [a-zA-Z]*:" packages/lexical/src/LexicalEditor.ts | sed -n '/546/,/598/p'
$ sed -n '546,598p' packages/lexical/src/LexicalEditor.ts | grep -n "^  [a-z]"
7:  dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>;
12:  dirtyLeaves: Set<NodeKey>;
17:  editorState: EditorState;
29:  mutatedNodes: null | MutatedNodes;
38:  normalizedNodes: Set<NodeKey>;
42:  prevEditorState: EditorState;

$ grep -rni "cascade" packages/lexical-website/docs/ | wc -l
0
$ grep -n "_cascadeCount++" packages/lexical/src/LexicalUpdates.ts
1026:  if (editor._cascadeCount++ > 99) {

After

$ sed -n '29,42p' packages/lexical-website/docs/concepts/listeners.md
- `editorState` the latest updated Editor State
- `prevEditorState` the previous Editor State
- `tags` a Set of all tags that were passed to the update
- `dirtyElements` a Map of the NodeKeys of ElementNodes that were marked
  dirty, to a boolean that is true when the node was intentionally mutated
- `dirtyLeaves` a Set of the NodeKeys of all dirty nodes that are not
  ElementNodes
- `mutatedNodes` a Map of LexicalNode constructors to a
  `Map<NodeKey, NodeMutation>`, or null when no DOM was mutated. Only
  populated when at least one MutationListener is registered
- `normalizedNodes` (advanced) the keys of TextNode descendants that were
  merged with a sibling by normalization

$ grep -n "cascade budget" packages/lexical-website/docs/concepts/listeners.md
57:The editor keeps a cascade budget: once a run of updates re-enqueues more

The queue-clearing behaviour and the macrotask reset that keeps bounded
activity from reaching the limit are
packages/lexical/src/LexicalUpdates.ts:991-1040; the payload fields and
their descriptions are packages/lexical/src/LexicalEditor.ts:546-598.

@vercel

vercel Bot commented Sep 24, 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 Sep 25, 2026 3:46am UTC
lexical-playground Ready Ready Preview Sep 25, 2026 3:46am 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 Sep 24, 2026
Comment on lines +32 to +49
- `dirtyElements` a Map of the NodeKeys of ElementNodes that were marked
dirty, to a boolean that is true when the node was intentionally mutated
- `dirtyLeaves` a Set of the NodeKeys of all dirty nodes that are not
ElementNodes
- `mutatedNodes` a Map of LexicalNode constructors to a
`Map<NodeKey, NodeMutation>`, or null when no DOM was mutated. Only
populated when at least one MutationListener is registered
- `normalizedNodes` (advanced) the keys of TextNode descendants that were
merged with a sibling by normalization
- `dirtyElements` a Map of the NodeKeys of ElementNodes that were marked
dirty, to a boolean that is true when the node was intentionally mutated
- `dirtyLeaves` a Set of the NodeKeys of all dirty nodes that are not
ElementNodes
- `mutatedNodes` a Map of LexicalNode constructors to a
`Map<NodeKey, NodeMutation>`, or null when no DOM was mutated. Only
populated when at least one MutationListener is registered
- `normalizedNodes` (advanced) the keys of TextNode descendants that were
merged with a sibling by normalization

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There are duplicate bullet points in here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — thank you. That was a bug in how I generated the branch: the edit script ran twice over the same working tree, so each insertion landed twice. Force-pushed a rebuilt branch from main; the diff is now a single clean insertion (9 bullet lines + the cascade paragraph, no repeats).

Comment on lines +78 to +83
A listener that re-enqueues work without a stop condition is worse than slow.
The editor keeps a cascade budget: once a run of updates re-enqueues more
than 100 times without yielding to the event loop, it discards the entire
pending update queue and warns. Bounded activity never reaches the limit —
the budget is reset from a macrotask, which a genuine runaway starves — but a
true loop silently loses whatever else was queued.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is also a duplicate of the above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same cause as above — fixed in the force-push. Both the bullet list and the cascade paragraph now appear exactly once.

…ener payload and the cascade guard

## Description

Two gaps in `concepts/listeners.md`:

1. **The update-listener payload is listed as three properties** —
   `editorState`, `prevEditorState`, `tags`. `UpdateListenerPayload` has
   seven: `dirtyElements`, `dirtyLeaves`, `mutatedNodes` and
   `normalizedNodes` are also passed, and a listener that wants to react to
   *what* changed needs them.
2. **Waterfall updates are described as only a performance problem** — "two
   DOM updates, when we likely could have done it in a single DOM update".
   There is also a hard guard: past 100 cascading updates without yielding to
   the event loop, the editor discards its entire pending update queue and
   warns. A listener that re-enqueues in a loop therefore loses queued work
   silently, which is not a performance characteristic. Nothing in the docs
   tree mentions it.

Descriptions are taken from the doc comments on the payload interface.

## Test plan

Documentation-only change (markdown is excluded from prettier via
`.prettierignore`), so the check is that the documented payload matches the
type and that the guard exists.

### Before

```
$ sed -n '29,31p' packages/lexical-website/docs/concepts/listeners.md
- `editorState` the latest updated Editor State
- `prevEditorState` the previous Editor State
- `tags` a Set of all tags that were passed to the update

$ grep -n "^  [a-zA-Z]*:" packages/lexical/src/LexicalEditor.ts | sed -n '/546/,/598/p'
$ sed -n '546,598p' packages/lexical/src/LexicalEditor.ts | grep -n "^  [a-z]"
7:  dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>;
12:  dirtyLeaves: Set<NodeKey>;
17:  editorState: EditorState;
29:  mutatedNodes: null | MutatedNodes;
38:  normalizedNodes: Set<NodeKey>;
42:  prevEditorState: EditorState;

$ grep -rni "cascade" packages/lexical-website/docs/ | wc -l
0
$ grep -n "_cascadeCount++" packages/lexical/src/LexicalUpdates.ts
1026:  if (editor._cascadeCount++ > 99) {
```

### After

```
$ sed -n '29,42p' packages/lexical-website/docs/concepts/listeners.md
- `editorState` the latest updated Editor State
- `prevEditorState` the previous Editor State
- `tags` a Set of all tags that were passed to the update
- `dirtyElements` a Map of the NodeKeys of ElementNodes that were marked
  dirty, to a boolean that is true when the node was intentionally mutated
- `dirtyLeaves` a Set of the NodeKeys of all dirty nodes that are not
  ElementNodes
- `mutatedNodes` a Map of LexicalNode constructors to a
  `Map<NodeKey, NodeMutation>`, or null when no DOM was mutated. Only
  populated when at least one MutationListener is registered
- `normalizedNodes` (advanced) the keys of TextNode descendants that were
  merged with a sibling by normalization

$ grep -n "cascade budget" packages/lexical-website/docs/concepts/listeners.md
57:The editor keeps a cascade budget: once a run of updates re-enqueues more
```

The queue-clearing behaviour and the macrotask reset that keeps bounded
activity from reaching the limit are
`packages/lexical/src/LexicalUpdates.ts:991-1040`; the payload fields and
their descriptions are `packages/lexical/src/LexicalEditor.ts:546-598`.
@etrepum
etrepum added this pull request to the merge queue Sep 25, 2026
Merged via the queue into meta:main with commit 5c08636 Sep 25, 2026
50 checks passed
@etrepum etrepum mentioned this pull request Sep 28, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 53b05bc7 Deployed Sep 25, 2026 by vercel[bot]
Preview – lexical-playground — 53b05bc7 Deployed Sep 25, 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.

2 participants