Skip to content

[lexical] Bug Fix: Avoid read-only warnings for commit-time focus commands - #9230

Merged
etrepum merged 2 commits into
meta:mainfrom
etrepum:codex/fix-9221-focus-readonly-warning
Sep 24, 2026
Merged

etrepum merged 2 commits into
meta:mainfrom
etrepum:codex/fix-9221-focus-readonly-warning

Conversation

@etrepum

@etrepum etrepum commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Description

DOM selection synchronization can synchronously dispatch FOCUS_COMMAND while the committing editor state is frozen. updateEditorSync currently warns even when application code has not entered a read context.

Suppress the development warning for the commit's implicit read-only context. Explicit reads still warn, including reads entered by application callbacks during a commit. Command listeners continue to run in a fresh writable update with the existing synchronous dispatch timing.

Add browser regressions for editor.focus(), selecting into an unfocused editor, and refocusing an existing selection, with both mutating and non-mutating listeners. Also cover an explicit read entered from a native focus callback during commit.

Closes #9221

Test plan

New browser test with a mock to track that the warning is not issued during focus events fired synchronously while committing an update.

…mands

## Description

DOM selection synchronization can synchronously dispatch FOCUS_COMMAND while
the committing editor state is frozen. updateEditorSync currently warns even
when application code has not entered a read context.

Suppress the development warning for the commit's implicit read-only context.
Explicit reads still warn, including reads entered by application callbacks
during a commit. Command listeners continue to run in a fresh writable update
with the existing synchronous dispatch timing.

Add browser regressions for editor.focus(), selecting into an unfocused editor,
and refocusing an existing selection, with both mutating and non-mutating
listeners. Also cover an explicit read entered from a native focus callback
during commit.

Closes meta#9221

## Test plan

### Before

On main at 6fdbffa, with the new tests:

`pnpm run test-browser packages/lexical/src/__tests__/browser/Issue9221FocusReadOnlyWarning.test.ts`

```text
AssertionError: expected "Mock" to not be called at all, but actually been called 1 times
 Test Files  1 failed (1)
      Tests  6 failed | 1 passed (7)
```

### After

The same browser command passes separately with VITEST_BROWSER set to chromium,
firefox, and webkit (21 passing cases total):

```text
 Test Files  1 passed (1)
      Tests  7 passed (7)
```

Firefox used MOZ_DISABLE_CONTENT_SANDBOX=1. WebKit used locally extracted
liblzo2/libGLESv2 libraries via LD_LIBRARY_PATH and
PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=1 because its ldconfig-based check
does not detect the locally supplied libGLESv2. All browsers ran on Linux;
macOS and Windows were not exercised.

`pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx packages/lexical/src/__tests__/unit/LexicalEditorListener.test.ts`

```text
 Test Files  2 passed (2)
      Tests  103 passed (103)
```

`pnpm run tsc`, ESLint on the changed files, and `git diff --check` exit 0.
Prettier on the changed files:

```text
Checking formatting...
All matched files use Prettier code style!
```

The supplemental `pnpm exec tsc --noEmit -p tsconfig.test.json` exits 2 with
seven errors in unchanged benchmark files (none in the new test), including:

```text
packages/lexical/src/__bench__/dom/editorCycle.bench.ts(10,9): error TS2724: '"vitest"' has no exported member named 'bench'. Did you mean 'Bench'?
packages/lexical/src/__bench__/dom/editorOperations.bench.ts(136,15): error TS2740: Type 'LexicalNode' is missing the following properties from type 'ParagraphNode': extractWithChild, insertNewAfter, collapseAtStart, __first, and 57 more.
```
@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 24, 2026 7:25pm UTC
lexical-playground Ready Ready Preview Sep 24, 2026 7:25pm 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
@etrepum
etrepum added this pull request to the merge queue Sep 24, 2026
Merged via the queue into meta:main with commit c23a367 Sep 24, 2026
50 checks passed
@etrepum etrepum mentioned this pull request Sep 28, 2026
piotrlewalski added a commit to piotrlewalski/remdo that referenced this pull request Oct 13, 2026
meta/lexical#9230 (c23a367) fixed the commit-time updateEditorSync
warning after 0.51.0 shipped. Apply its condition, which still warns inside
an explicit editor.read(), and track dropping the patch on the first
release that contains it instead of the upstream-report backlog item.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

This branch was successfully deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: updateEditorSync read-only warning fires for FOCUS_COMMAND dispatched by Lexical's own DOM selection update during commit

2 participants