Skip to content

Fix trigger reconcilation on nested read - #7724

Merged
zurfyx merged 1 commit into
mainfrom
fixnx-nested-read
Jul 24, 2025
Merged

zurfyx merged 1 commit into
mainfrom
fixnx-nested-read

Conversation

@zurfyx

@zurfyx zurfyx commented Jul 24, 2025 •

Copy link
Copy Markdown
Member

Problem

A combination of nested updates + reads can cause a missed reconcilation, consequently leading to further errors such as https://lexical.dev/docs/error?code=75&v=6 or mutating (should've been frozen) nodes.

For example:

  1. dispatchCommand(KEY_DOWN)
  2. (dispatch command triggers an update by command design)
  3. User triggers a function such as submit message that contains a combination of editor.read and editor.update
  4. editor.read flushes by design
  5. editor.update has no pendingEditorState as it has been flushed. Hence, reconcilation never happens.

Solution

We can either recreate the EditorState or ignore the flush sync behavior on read. Because we already support flushSync flag in nested updates this PR does the first.

Note for self

We can't just reuse the discrete functionality within update as in

read<T>(callbackFn: () => T): T {
    const pendingEditorState = this._pendingEditorState;
    if (pendingEditorState !== null) {
      this.update(() => {}, {discrete: true});
    }
    return this.getEditorState().read(callbackFn, {editor: this});
  }

This will trigger a (parent) update and dismiss the concept of queued updates.

@vercel

vercel Bot commented Jul 24, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2025 3:52pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2025 3:52pm

@facebook-github-bot facebook-github-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 Jul 24, 2025
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jul 24, 2025
@etrepum

etrepum commented Jul 24, 2025

Copy link
Copy Markdown
Collaborator

Related #7709

@zurfyx
zurfyx added this pull request to the merge queue Jul 24, 2025
Merged via the queue into main with commit d0aa48e Jul 24, 2025
@etrepum etrepum mentioned this pull request Aug 7, 2025
@zurfyx
zurfyx deleted the fixnx-nested-read branch December 18, 2025 20:16

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — 9e0fd25b Deployed Jul 24, 2025 by vercel[bot]
Preview – lexical — 9e0fd25b Deployed Jul 24, 2025 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. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants