Skip to content

[lexical] Feature: Replace LexicalEditor.readPending with editor.read(mode, fn) overload#8702

Merged
etrepum merged 1 commit into
facebook:mainfrom
etrepum:claude/wonderful-maxwell-qal8nu
Jun 15, 2026
Merged

[lexical] Feature: Replace LexicalEditor.readPending with editor.read(mode, fn) overload#8702
etrepum merged 1 commit into
facebook:mainfrom
etrepum:claude/wonderful-maxwell-qal8nu

Conversation

@etrepum

@etrepum etrepum commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Description

Remove LexicalEditor.readPending in favor of an overloaded read whose optional first argument is an EditorReadMode:

  • 'force-commit' (the default, equivalent to the previous single-argument read) flushes pending updates before reading the committed state.
  • 'pending' reads the pending state without flushing (the previous readPending behavior); editor.readPending(fn) becomes editor.read('pending', fn).
  • 'latest' reads the committed state without flushing, equivalent to editor.getEditorState().read(fn, {editor}).

Update the flow types (dropping the stale EditorReadOptions that had drifted from the implementation), export the new EditorReadMode type, and migrate the SelectBlockExtension call site and unit tests.

While this does remove an existing API, this shouldn't be considered a breaking change because readPending was added in #8532 which has not made it into a release yet (merged after 0.45.0).

Test plan

New unit tests

Remove `LexicalEditor.readPending` in favor of an overloaded `read` whose
optional first argument is an `EditorReadMode`:

- `'force-commit'` (the default, equivalent to the previous single-argument
  `read`) flushes pending updates before reading the committed state.
- `'pending'` reads the pending state without flushing (the previous
  `readPending` behavior); `editor.readPending(fn)` becomes
  `editor.read('pending', fn)`.
- `'latest'` reads the committed state without flushing, equivalent to
  `editor.getEditorState().read(fn, {editor})`.

Update the flow types (dropping the stale `EditorReadOptions` that had
drifted from the implementation), export the new `EditorReadMode` type, and
migrate the SelectBlockExtension call site and unit tests.
@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 Jun 15, 2026
@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Jun 15, 2026 6:02pm
lexical-playground Ready Ready Preview, Comment Jun 15, 2026 6:02pm

Request Review

@potatowagon potatowagon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed by Navi (Tater Thoughts Bobblehead) on behalf of @potatowagon.

Assessment: LGTM

Summary: Replaces LexicalEditor.readPending() with a unified editor.read(mode, fn) overload that accepts an EditorReadMode ('force-commit' | 'pending' | 'latest'). The single-arg form editor.read(fn) defaults to 'force-commit' (same as old behavior). This is a clean API simplification.

What I checked:

  • Logic correctness: The overload dispatch (args.length === 1) correctly differentiates single-arg vs two-arg calls. The mode branching is sound: 'force-commit' flushes then reads committed, 'pending' reads pending||committed without flush, 'latest' reads committed without flush.
  • Backward compatibility: editor.read(fn) still works exactly as before (defaults to 'force-commit' which calls $commitPendingUpdates). The old EditorReadOptions type is removed — this IS a breaking change for anyone using editor.read(fn, {pending: true}), but that was an internal/undocumented pattern.
  • www compat: The removed readPending method could break www callsites. One internal usage in SelectBlockExtension is already migrated in this PR. If www uses readPending elsewhere, those callsites need updating. The EditorReadOptions type removal may also break www if imported. Recommend checking www grep for readPending/EditorReadOptions.
  • Test coverage: Comprehensive — the test exercises all 3 modes, verifies pending vs committed state distinction, and confirms behavior after flush. Good.
  • Edge cases: 'latest' mode is new behavior (reads committed without flushing) — correctly equivalent to editor.getEditorState().read(fn, {editor}). The distinction from 'force-commit' is well-documented in JSDoc.
  • Flow types: Updated correctly with two overload signatures.
  • Tree-shaking: No impact (no new module-scope code).

Potential concern: This is a breaking change — readPending() is removed. If this lands before www is migrated, it will break the internal build. The author (etrepum) likely handles www sync, but flagging for visibility.

CI status: Core tests all green (unit 22.x+24.x, browser, integrity). E2e canary chromium still pending. CLA+Vercel pass.

Ready to approve once e2e passes and www readPending callsites are confirmed migrated.

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jun 15, 2026
@etrepum etrepum enabled auto-merge June 15, 2026 18:47
@levensta

Copy link
Copy Markdown
Contributor

It would also be helpful to include examples in the documentation of which mode is preferable for different situations

@etrepum etrepum added this pull request to the merge queue Jun 15, 2026
Merged via the queue into facebook:main with commit 4ea2e80 Jun 15, 2026
54 checks passed
etrepum pushed a commit to etrepum/lexical that referenced this pull request Jun 15, 2026
…ls to read('latest', ...)

facebook#8702 (now merged) added the `editor.read('latest', fn)` overload, equivalent to
`editor.getEditorState().read(fn, {editor})`. Port the two reads this PR
introduced to the new idiom: `mountSlotContainer` (was already `{editor}`, exact
equivalent) and ReviewExtension's mutation-listener nodeMap read (now also gets
the editor context, which is harmless here).

https://claude.ai/code/session_0125UE7Cv1mUaM82UH8N1nJX
@etrepum etrepum mentioned this pull request Jun 25, 2026
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

5 participants