Repository navigation
[lexical][lexical-table][lexical-playground][lexical-website] Breaking Change: Standardize selection notification timing - #9219
Merged
Conversation
…: Standardize selection notification timing
## Description
SELECTION_CHANGE_COMMAND can be missed when native selectionchange events are suppressed or coalesced, including deletion inside a text node. Detect changes in the pending editor state and notify before reconciliation, independently of DOM events.
Use one pre-reconciliation contract for native, programmatic, and non-range selections. Listeners see the pending selection and the actual previous committed selection, and their edits and transforms join the same commit. Deduplicate unchanged selections while retaining native dirty-selection workarounds and the connected-root requirement for automatic range/null notifications.
Migrate DOM-dependent table and playground handlers to $onUpdate, with read('latest') when reading reconciled model state. Table normalization uses model nodes, so newly created tables and cells can be selected in the same update. Register the table observer's selection-command handler only while a root exists, with cleanup on removal and replacement.
Bound non-converging selection listeners without rolling back the user's edit: commit the pending state before reporting through onWarn. Document the notification timing and DOM availability contract, including migration guidance for third-party DOM-reading handlers.
Closes meta#9179
## Test plan
### Before
Recorded during development against f836ea1, before the notification-limit and DOM-consumer fixes:
```
pnpm run test-unit LexicalSelectionChangeCommand -t 'caps notifications|node selections notify'
Test Files 1 failed (1)
Tests 5 failed | 21 skipped (26)
FONTCONFIG_PATH=/etc/fonts pnpm run test-browser --config vitest.local.config.mts --no-file-parallelism SelectionToolbarTiming
AssertionError: expected Set{ …(2) } to deeply equal Set{ 'CHANGEDline twoline three' }
Test Files 1 failed (1)
Tests 1 failed (1)
```
The toolbar measured both old and new DOM during one programmatic text/selection update.
### After
Full validation at e956c97, before the small root-lifecycle and configuration follow-ups:
```
pnpm run test-unit
Test Files 349 passed (349)
Tests 8559 passed | 1 skipped (8560)
FONTCONFIG_PATH=/etc/fonts pnpm run test-browser --config vitest.local.config.mts --no-file-parallelism packages/lexical/src/__tests__/browser packages/lexical-table/src/__tests__/browser packages/lexical-playground/src/__tests__/browser packages/lexical-react/src/__tests__/browser
Test Files 23 passed (23)
Tests 152 passed | 1 skipped (153)
```
Validation after the root-lifecycle follow-up:
```
pnpm run test-unit LexicalTableSelectionHelpers LexicalTableExtension LexicalSelectionChangeCommand
Test Files 3 passed (3)
Tests 60 passed (60)
FONTCONFIG_PATH=/etc/fonts pnpm run test-browser --config vitest.local.config.mts --no-file-parallelism packages/lexical-table/src/__tests__/browser
Test Files 4 passed (4)
Tests 14 passed (14)
```
The final configuration cleanup also passes SelectionToolbarTiming (1 passed), without the dependency-resolution warning. TypeScript and ESLint passed; Prettier reported: `All matched files use Prettier code style!`
Coverage includes deletion and replacement typing, notification deduplication, previous-selection semantics, listener edits and transforms, undo merging with onUpdate/$onUpdate, newly inserted tables/cells, table escape handling, root lifecycle, and non-converging listeners.
Browser validation used Chromium on Linux with a temporary local executable configuration. Firefox, WebKit, and other operating systems were not exercised. This squash preserves the final tree exactly; tests were not rerun for the history-only change.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
… main ## Description Merge facebook/lexical main at 6fdbffa into the selection-change branch without rebasing. Firefox can leave the test editor as document.activeElement while its iframe has no focus, so keyboard input never reaches the editor. Explicitly focus the iframe immediately before keyboard input in the deletion and selection-command tests. Drain setup mutations before the nested shadow-editor attribution test changes the native selection. Otherwise the outer editor's pending MutationObserver update imports WebKit's host-retargeted selection and emits a separate notification. Keep the zero-outer-notifications assertion and also assert that the outer editor's selection remains null. Define tableScrollableWrapper in the browser test themes to remove the table configuration warnings. ## Test plan ### Before `VITEST_BROWSER=firefox pnpm run test-browser` ```text Test Files 1 failed | 28 passed | 1 skipped (30) Tests 24 failed | 167 passed | 4 skipped (195) ``` `VITEST_BROWSER=webkit pnpm run test-browser ShadowRootSelection -t 'attributes to the inner'` ```text AssertionError: expected 1 to be +0 // Object.is equality Test Files 1 failed (1) Tests 1 failed | 30 skipped (31) ``` ### After `VITEST_BROWSER=chromium,firefox,webkit pnpm run test-browser` ```text Test Files 89 passed | 1 skipped (90) Tests 578 passed | 7 skipped (585) ``` TypeScript, ESLint, Prettier, and git diff --check passed. All browser runs above were on Linux; macOS and Windows are left to CI.
…lection notifications ## Description Selection listeners now schedule DOM work with $onUpdate. While those callbacks are still waiting, history's CAN_UNDO_COMMAND listeners can start an otherwise empty update that inherits the callbacks. Its extra commit resets typing-history coalescing, making undo remove one character at a time and breaking markdown and composition undo. Detach the current commit's callbacks before invoking commit listeners, and preserve callbacks belonging to updates created by those listeners. Keep the existing deferral when an outer update forces an early commit. Extend the undo-merging regression to include a toolbar's history listener and selection-listener callbacks. Verify that a command dispatched during commit retains its own callback and observes its reconciled DOM. Merge upstream main through 3085cb2, including its documentation updates. ## Test plan ### Before pnpm test-unit LexicalSelectionChangeCommand Tests 2 failed | 24 passed (26) AssertionError: expected 'abc' to be '' pnpm test-e2e-chromium 1055-fast-typing-undo --workers=1 --retries=0 1 failed - <br data-lexical-managed-linebreak="true" /> + <span data-lexical-text="true">hell</span> ### After pnpm test-unit LexicalSelectionChangeCommand Test Files 1 passed (1) Tests 28 passed (28) pnpm test-unit LexicalEditor LexicalUpdateTags LexicalHistory LexicalSelectionChangeCommand LexicalTable Test Files 17 passed (17) Tests 344 passed (344) pnpm test-e2e-chromium History.spec.mjs Markdown.spec.mjs 1055-fast-typing-undo --workers=4 --retries=0 62 passed (1.3m) VITEST_BROWSER=chromium,webkit pnpm test-browser Test Files 60 passed (60) Tests 387 passed | 3 skipped (390) VITEST_BROWSER=firefox pnpm test-browser --config vitest.firefox-local.config.mts Test Files 29 passed | 1 skipped (30) Tests 191 passed | 4 skipped (195) ESLint, Prettier and the source TypeScript check pass. Browser runs used the cached Playwright binaries and local WebKit libraries. macOS and Windows were not exercised locally. Firefox used a temporary launch configuration for the container; the repository configuration is unchanged.
… synchronization ## Description Post-commit table synchronization cleared a prepared pointerdown anchor when the browser moved its native caret into the clicked cell. Subsequent pointer moves then began the table selection from the wrong cell, breaking drag selection and horizontal auto-scrolling. Clear observer state only when removing an active table highlight. Preserve the prepared drag anchor while the model still has a range selection. Add a browser regression covering pointerdown, the intervening caret update, and the resulting drag selection. ## Test plan ### Before `VITEST_BROWSER=chromium pnpm test-browser TableSelectionBeforeCommit` - 1 failed, 5 passed: the new regression loses its pointerdown anchor. `pnpm test-e2e-firefox Tables.spec.mjs --config playwright.firefox-local.config.mjs --grep 'meta#7245|meta#7153' --workers=1 --retries=0` - 2 failed: drag selection meta#7245 and scrollable-table auto-scroll meta#7153. ### After - Both reported E2E cases pass in Firefox, Chromium, and WebKit. - Related table drag, deselection, and range-selection E2E checks: 40 passed, 2 expected Firefox skips across the three browsers. - `VITEST_BROWSER=chromium,firefox,webkit pnpm test-browser --config vitest.table-local.config.mts packages/lexical-table`: 42 passed, 3 skipped. - `pnpm test-unit LexicalTable --maxWorkers=2`: 182 passed. - ESLint and Prettier passed for both changed files. Validation ran on Linux. Temporary local launch configurations accommodated the container's Firefox sandbox and WebKit libraries; repository test configurations are unchanged. macOS and Windows were not tested locally.
## Description
The new table-drag regression test indexed optional rows and cells without checking that they exist, causing the root TypeScript check to fail. Use optional row access and assert that both cells exist before dispatching pointer events and checking the resulting selection.
## Test plan
### Before
`pnpm exec tsc -p tsconfig.json` exited with code 2:
```
packages/lexical-table/src/__tests__/browser/TableSelectionBeforeCommit.test.ts(174,22): error TS2532: Object is possibly 'undefined'.
packages/lexical-table/src/__tests__/browser/TableSelectionBeforeCommit.test.ts(175,21): error TS2532: Object is possibly 'undefined'.
packages/lexical-table/src/__tests__/browser/TableSelectionBeforeCommit.test.ts(183,3): error TS18048: 'anchorCell' is possibly 'undefined'.
packages/lexical-table/src/__tests__/browser/TableSelectionBeforeCommit.test.ts(192,42): error TS18048: 'anchorCell' is possibly 'undefined'.
packages/lexical-table/src/__tests__/browser/TableSelectionBeforeCommit.test.ts(196,16): error TS18048: 'focusCell' is possibly 'undefined'.
packages/lexical-table/src/__tests__/browser/TableSelectionBeforeCommit.test.ts(197,3): error TS18048: 'focusCell' is possibly 'undefined'.
packages/lexical-table/src/__tests__/browser/TableSelectionBeforeCommit.test.ts(208,44): error TS18048: 'anchorCell' is possibly 'undefined'.
packages/lexical-table/src/__tests__/browser/TableSelectionBeforeCommit.test.ts(209,43): error TS18048: 'focusCell' is possibly 'undefined'.
packages/lexical-table/src/__tests__/browser/TableSelectionBeforeCommit.test.ts(212,3): error TS18048: 'focusCell' is possibly 'undefined'.
```
### After
`pnpm exec tsc -p tsconfig.json` produced no diagnostics; captured exit status:
```
TypeScript exit code: 0
```
`VITEST_BROWSER=chromium,firefox,webkit pnpm test-browser --config vitest.table-types-local.config.mts TableSelectionBeforeCommit`:
```
Test Files 3 passed (3)
Tests 18 passed (18)
```
ESLint exited with code 0 for the changed file. Prettier reported:
```
Checking formatting...
All matched files use Prettier code style!
```
Tested on Linux with Chromium, Firefox, and WebKit. A temporary launch configuration accommodated the container's Firefox sandbox, and local shared libraries supported WebKit. Repository test configurations are unchanged. macOS and Windows were not tested locally.
etrepum
marked this pull request as ready for review
September 24, 2026 20:37
etrepum
requested review from
acywatson,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
September 24, 2026 20:37
…election listeners ## Description Selection notification error recovery was copying the pending node map and update bookkeeping on every notification. That made ordinary caret changes unnecessarily expensive and introduced a separate rollback contract for command listeners. Remove the checkpoint and recovery helper. Automatic selection notifications extend the pending update directly and use its existing error handling, just like an explicit command dispatch. A throwing listener can abort the whole pending update; there is no separate transaction for listener mutations. The reconciler retains the update's original structural write history without needing to reconstruct it. Update the error-handling documentation and tests to match this contract. Keep the replacement/reordering regressions and the independent table selection fixes. ## Test plan ### Before Run the revised selection tests against the previous implementation: ```text pnpm exec vitest run --project unit packages/lexical/src/__tests__/unit/LexicalSelectionChangeCommand.test.ts Tests 3 failed | 38 passed (41) Expected: "original" Received: "edited!" ``` ### After ```text pnpm exec vitest run --project unit packages/lexical/src/__tests__/unit/LexicalSelectionChangeCommand.test.ts Tests 41 passed (41) pnpm exec vitest run --project unit Test Files 340 passed (340) Tests 5628 passed | 1 skipped (5629) pnpm exec vitest run --project scripts-unit Test Files 14 passed (14) Tests 3001 passed (3001) VITEST_BROWSER=chromium,firefox,webkit PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=1 pnpm exec vitest run --config vitest.regression-local.config.mts --project browser Test Files 89 passed | 1 skipped (90) Tests 590 passed | 7 skipped (597) pnpm exec tsc -p tsconfig.json Exit code: 0 pnpm exec prettier --check <three changed files> All matched files use Prettier code style! pnpm exec eslint <two changed TypeScript files> Exit code: 0 git diff --check Exit code: 0 ``` Rebuilt with `pnpm build-playground-dev`, then ran all nine recently reported E2E failures plus the two earlier table-drag cases with `pnpm exec playwright test --config playwright.regression-local.config.mjs --project <browser> --workers=2 --retries=0 <11 test selectors>` against the built playground: ```text chromium: 11 passed (15.0s) firefox: 11 passed (24.5s) webkit: 11 passed (22.5s) ``` The temporary local configs disable the unsupported Firefox content sandbox. Local checks ran on Linux; complete platform/editor-mode E2E coverage is being checked through GitHub CI. No changelog was edited.
## Description Remove the manually added Unreleased entry from this branch. CHANGELOG.md now matches the PR base exactly; the breaking-change explanation and migration guidance remain in the PR description and selection documentation. ## Test plan ### Before The PR file diff reported: ```text CHANGELOG.md: 11 additions, 0 deletions ``` ### After ```text git hash-object CHANGELOG.md 06e9a98 PR base CHANGELOG.md blob from the GitHub Git tree API: 06e9a98 git diff --check Exit code: 0 ``` No runtime code changed in this commit.
…evtools] Bug Fix: Restore selection notification bookkeeping after rollback
## Description
A selection notification recorded in an update that later aborts can cause a false notification during recovery and suppress a later retry. Restore the notification baseline to the committed selection in the existing error-recovery path. Throwing listeners retain ordinary update-abort semantics.
Add createError to @lexical/internal and teach the error-message transform to preserve its expression context while extracting production codes. Both recoverable update warnings can now construct coded errors for onWarn without throwing and catching an invariant. Share production message construction with the existing throwing formatter.
Clarify the breaking-change scope: native range notifications already ran inside an update; newly notified programmatic changes and pre-reconciliation non-range notifications need migration. Document inherited collaboration/history tags and test deferred local listener edits with both Yjs bindings after remote changes and undo. Do not change tag semantics or introduce listener-specific rollback snapshots.
## Test plan
### Before
With the new rollback regressions and the original recovery path:
```text
$ pnpm exec vitest run --project unit LexicalSelectionChangeCommand
Test Files 1 failed (1)
Tests 4 failed | 41 passed (45)
```
An inline content-edit version of the collaboration regression reproduced divergence between peers for remote changes and undo in both Yjs bindings:
```text
$ pnpm exec vitest run --project unit CollaborationSelectionChange
Test Files 1 failed (1)
Tests 4 failed (4)
```
### After
The collaboration test uses the documented deferred local update; it does not assert that edits made inside a tagged commit synchronize.
```text
$ pnpm exec vitest run --project unit --project scripts-unit --maxWorkers=2
Test Files 356 passed (356)
Tests 8678 passed | 1 skipped (8679)
$ pnpm exec tsc -p tsconfig.json
$ pnpm exec tsc -p tsconfig.scripts.json
$ pnpm flow
Running Flow...
Found 0 errors
$ pnpm build
$ pnpm build-prod
$ pnpm build-types
```
All commands above exited successfully. Formatting, ESLint on changed source/test files, and git diff --check pass. The test TypeScript configuration passes with benchmark files excluded. The unfiltered tsconfig.test.json still reports seven errors in unchanged benchmark files, 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'?
```
Local Chromium/Firefox/WebKit browser validation could not start because the browser binaries were missing; Playwright's download failed:
```text
Error: browserType.launch: Executable doesn't exist at /root/.cache/ms-playwright/chromium_headless_shell-1234/chrome-headless-shell-linux64/chrome-headless-shell
Error: Failed to download Chrome for Testing 151.0.7922.34 (playwright chromium v1234), caused by
Error: Download failure, code=1
```
Browser and E2E validation for this commit is left to CI. No manual CHANGELOG or error-code-map edits.
…oded error transforms safe for bundled output
## Description
The new createError transform emitted calls back to its source helper. Bundling restored that function's name, so the playground's second Babel pass treated an already formatted template literal as a source message and failed with Unsupported type TemplateLiteral. Package-only builds did not exercise this downstream pass.
Emit a separate createDevError runtime helper for development and uncoded production messages. Restrict source rewrites to the default import from @lexical/internal/createError or its .js alias, honoring aliases and lexical shadowing. Unrelated createError functions are no longer rewritten.
Add a regression that transforms real helper sources, bundles them with Rollup, and applies the transform again. Cover aliased imports, unrelated functions, and shadowed imports. Document the encoded namespace argument in production cascade-warning messages for telemetry consumers.
## Test plan
### Before
```text
$ pnpm build-playground-dev
Error: packages/lexical/dist/Lexical.dev.js: Unsupported type TemplateLiteral
[ELIFECYCLE] Command failed with exit code 1.
$ pnpm exec vitest run --project scripts-unit scripts/error-codes/__tests__/unit/transform-error-messages.test.ts
Test Files 1 failed (1)
Tests 2 failed | 12 passed (14)
```
The first error above abbreviates the local checkout prefix. Both bundling regression cases failed with Unsupported type TemplateLiteral before the fix.
### After
```text
$ pnpm exec vitest run --project unit --project scripts-unit scripts/error-codes/__tests__/unit/transform-error-messages.test.ts packages/lexical-internal/src/__tests__/unit/createError.test.ts packages/lexical/src/__tests__/unit/LexicalSelectionChangeCommand.test.ts
Test Files 3 passed (3)
Tests 67 passed (67)
$ pnpm build-playground-dev
✓ built in 15.81s
$ pnpm run --filter lexical-playground build-vercel
✓ built in 20.37s
$ pnpm build-playground-prod
✓ built in 44.13s
$ pnpm build-types
$ pnpm exec tsc -p tsconfig.json
$ pnpm exec tsc -p tsconfig.scripts.json
$ pnpm flow
Running Flow...
Found 0 errors
```
All commands above exited successfully. ESLint, Prettier, and git diff --check pass for the changed files. Browser/E2E runs remain in CI because the local Playwright binaries are unavailable. No changes to CHANGELOG.md or scripts/error-codes/codes.json.
zurfyx
approved these changes
Sep 25, 2026
ibastawisi
added a commit
to ibastawisi/lexical
that referenced
this pull request
Sep 27, 2026
## Description Brings the branch up to date with main. The only conflict is in `PagesExtension.ts`, where main (meta#9219) wrapped the old page-node `SELECTION_CHANGE_COMMAND` observer in `$onUpdate`. This branch deletes that handler along with the page-node model, so the branch's version is kept. `ToolbarPlugin` merges cleanly and keeps meta#9219's `$onUpdate` form. `scripts/error-codes/codes.json` is main's version unchanged. ## Test plan ### After ``` $ git diff upstream/main --quiet -- scripts/error-codes/codes.json && echo identical identical $ node_modules/.bin/tsc -p ./ --noEmit (no output) ``` Co-Authored-By: Claude Opus 5.5 <[email protected]>
ibastawisi
added a commit
to ibastawisi/lexical
that referenced
this pull request
Sep 27, 2026
…s from review
## Description
Addresses the Codex and Claude findings in the latest review of this PR, on
top of the merge with main.
Headers and footers (`HeaderFooterSession`):
- **Loading another document wrote the open header into it.** Tearing the
session down committed the live editor unconditionally, over whatever the
new document stored. Each nested editor now tracks whether the user edited
it (`dirty`) and the stored content those edits were made against
(`baseline`); a write-back happens only for real edits and only while the
document still holds the baseline, so an outside change (another
document, a collaborator, undo) wins.
- **Opening a header without editing changed the document.** The live page
number ("2" on page 2) was written back, adding an undo step and a collab
broadcast. Bookkeeping updates (loading, showing live numbers) are tagged
and never mark the editor dirty, and counters are stored with their `#` /
`##` placeholders whichever page they were edited from.
- **An edit to one variant closed the session of another.** External changes
are now compared per variant against that editor's baseline; only the
changed variant reloads, and only its session closes.
- **Escape in a header's typeahead closed the header.** The header's Escape
handler moves to `COMMAND_PRIORITY_BEFORE_EDITOR`: after an open component
picker, emoji or mention menu (LOW), before rich text's own blur.
- **The toolbar kept targeting a hidden header after a non-Escape close**
(read-only mode, the page setup dialog, `CLOSE_PAGE_SLOT_COMMAND`, a
reload). Every close now hands the active editor back to the document.
Since meta#9219 the core notifies `SELECTION_CHANGE_COMMAND` as a selection
commits, including the losing editor's selection becoming null, which can
arrive after the other editor's announcement; the hand-over (both on open
and close) clears the losing editor's selection and announces the winner
only after that update has committed. This also fixes the two header
stories the merge with meta#9219 broke (block type after a click into header
text; the Insert menu following the header).
- **Removing a page detached its open header.** `PagesLayout` now tells the
slot provider before removing a page's slots (`releaseSlot`), and the
session closes a live editor in one.
Page layer:
- **Zoom stayed stale after a window drag.** The settle guard dropped queued
zoom writes while `zoom` already held the new value. Zoom is recorded only
when written, and a viewport resize resets the guard like any outside
input.
- **Wrong realm.** `instanceof HTMLElement` / `Element` checks and global
`requestAnimationFrame`, `ResizeObserver`, `MutationObserver` and
`performance` are replaced by `isHTMLElement` / `isDOMNode` and the owner
window (`PagesLayout.win`), so an editor inside an iframe paginates.
- **Printing right after an edit printed the previous layout.** `beforeprint`
flushes the layout first.
- **Column layouts collapsed to zero width at a page boundary.** The layout
grid joins the table wrapper and code block in refusing to be narrowed
beside a band, and is capped to the page height like them.
- **Blank soft lines landed in the page margins.** Like an empty paragraph,
a line holding only a line break has no width and fits beside a band in
every engine; no style on the `<br>` changes that in WebKit or Firefox. A
block holding such a line (consecutive, leading or trailing soft breaks)
becomes a formatting context of its own while it does, so it moves whole,
capped to the page height.
Elsewhere:
- **Formatted page counters imported as plain text.** The import rules match
any element carrying the counter attribute (a bold counter exports as
`<strong>`), and take the format the core inline-format rule computes.
- **The block format menu showed in sticky notes.** Block types are offered
only when the active editor registers their nodes, and the menu is hidden
in plain-text editors.
Keyboard shortcuts working inside image captions and sticky notes (font
size, alignment, case) is intended: they bubble from any nested editor and
apply to the editor that received the key.
## Test plan
### Before
The new regression tests, run on the merge with main before these changes:
```
$ node_modules/.bin/vitest run --project unit packages/lexical-playground/src/__tests__/unit/PagesHeaderFooter.test.ts packages/lexical-playground/src/__tests__/unit/PagesPrint.test.ts
× prints the latest layout even before its next frame
× keeps counter formatting through HTML export and import
FAIL PagesHeaderFooter.test.ts > page counter nodes > keeps counter formatting through HTML export and import
AssertionError: expected undefined to be true // Object.is equality
FAIL PagesPrint.test.ts > registerPrintHandlers > prints the latest layout even before its next frame
AssertionError: expected '816px' to be '1056px' // Object.is equality
Tests 2 failed | 18 passed (20)
$ node_modules/.bin/vitest run --project browser packages/lexical-playground/src/__tests__/browser/PagesLayout.test.ts packages/lexical-playground/src/__tests__/browser/PagesHeaderFooter.test.ts
× opening and closing a slot without editing leaves the document alone
× an edit to another variant leaves the open slot alone
× loading another document does not write the open slot into it
× removing the page of the open slot closes it
× keeps the zoom in step with a continuous resize
× paginates an editor whose root lives in an iframe
FAIL ... > opening and closing a slot without editing leaves the document alone
AssertionError: expected '{"root":{"children":[{"children":[{"d…' to be '{"root":{"children":[{"children":[{"d…' // Object.is equality
FAIL ... > an edit to another variant leaves the open slot alone
AssertionError: expected null to deeply equal { kind: 'header', pageIndex: 1, …(1) }
FAIL ... > loading another document does not write the open slot into it
AssertionError: expected '{"root":{"children":[{"children":[{"d…' to contain 'New header'
Received: "{"root":{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Old header edited", ...
FAIL ... > removing the page of the open slot closes it
AssertionError: expected { kind: 'header', pageIndex: 2, …(1) } to be null
FAIL ... > keeps the zoom in step with a continuous resize
AssertionError: expected 0.657197 to be close to 0.962121, received difference is 0.304924, but expected 0.000005
FAIL ... > paginates an editor whose root lives in an iframe
Error: PagesLayout: the editor root must have a parent element
$ E2E_BROWSER=chromium node_modules/.bin/playwright test --project=chromium --retries=0 packages/lexical-playground/__tests__/e2e/Pages.spec.mjs
1) Pages › Formats the block type right after a click into header text
Expected: "Hi there"
- waiting for locator('.Pages__slotContent--live > blockquote')
2) Pages › The Insert menu offers only what the active editor supports
Expected value: "Page Number"
Received array: ["Horizontal Rule", "Page Break", "Image", "GIF", "Excalidraw", "Table", "Poll", "Columns Layout", "Equation", "Sticky Note", …]
3) Pages › Escape in a header closes the component picker, not the header
Expected: 1
Received: 0
> 903 | await expect(page.locator(LIVE_SLOT)).toHaveCount(1);
4) Pages › Closing a header without Escape hands the toolbar back to the document
Expected value: "Page Break"
Received array: ["Horizontal Rule", "Page Number", "Page Count", "Image", "GIF", "Excalidraw", "Table", "Poll", "Columns Layout", "Equation", …]
5) Pages › A column layout that crosses a page boundary moves whole to the next page
Expected: <= 3
Received: 5
6) Pages › Soft line breaks never land in the page margins
Expected: 0
Received: 5
7) Pages › Sticky notes get no block format menu
Expected: 0
Received: 1
7 failed
12 passed
```
(1 and 2 are the stories the merge with meta#9219 broke; 3 to 7 are new.)
### After
```
$ node_modules/.bin/vitest run --project unit packages/lexical-playground
Test Files 36 passed (36)
Tests 409 passed (409)
$ node_modules/.bin/vitest run --project browser packages/lexical-playground/src/__tests__/browser
Test Files 6 passed (6)
Tests 32 passed (32)
$ VITEST_BROWSER=webkit,firefox node_modules/.bin/vitest run --project browser packages/lexical-playground/src/__tests__/browser
Test Files 12 passed (12)
Tests 64 passed (64)
$ E2E_BROWSER=chromium node_modules/.bin/playwright test --project=chromium --retries=0 packages/lexical-playground/__tests__/e2e/Pages.spec.mjs packages/lexical-playground/__tests__/e2e/HTML.spec.mjs
23 passed (12.9s)
$ E2E_BROWSER=firefox node_modules/.bin/playwright test --project=firefox --retries=0 packages/lexical-playground/__tests__/e2e/Pages.spec.mjs packages/lexical-playground/__tests__/e2e/HTML.spec.mjs
23 passed (16.9s)
$ E2E_BROWSER=webkit node_modules/.bin/playwright test --project=webkit --retries=0 packages/lexical-playground/__tests__/e2e/Pages.spec.mjs packages/lexical-playground/__tests__/e2e/HTML.spec.mjs
23 passed (15.4s)
$ node_modules/.bin/tsc -p ./ --noEmit
(no output)
$ E2E_BROWSER=chromium node_modules/.bin/playwright test --project=chromium --retries=1 --reporter=line
22 skipped
881 passed (6.7m)
```
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
This was referenced Sep 29, 2026
Merged
AlessioGr
added a commit
to payloadcms/payload
that referenced
this pull request
Sep 30, 2026
…18397) _Written with AI_ Upgrades `lexical` and every installed `@lexical/*` package from `0.50.0` to `0.52.0` for Payload 4.x (`main`), and pinned `tsx` dependencies from `4.22.4` to `4.23.15`. Removes the native-loader workaround no longer needed with the new tsx version. Also fixes duplicate image uploads triggered by repeated node transforms in Lexical 0.52. CI fixes update the keyboard-navigation expectation and correct an existing auth-test parameter error that blocked integration tests. Fixes #17757 3.x counterpart: #18398. ## Why this fixes the CLI failure With Payload 3.90.1 on Node 22.22.0, importing a config that included `lexicalEditor()` could leave CLI startup pending before the config or target script was evaluated. The process then exited 0 with no output and left a pending PostgreSQL migration unapplied. Previously, Payload started the CLI with `void start()`, and an unresolved promise alone does not keep Node's event loop alive. Lexical 0.50's Node entry points select their build with top-level `await import(...)`, which is probably what caused it. Lexical has shipped ESM-only packages since **0.51**, using static imports instead of those asynchronous Node wrappers. Upgrading to 0.52 fixes this issue. Also removes the `module.registerHooks = undefined` workaround for #16949. tsx 4.23.15 [excludes bare built-ins from namespace inheritance](privatenumber/tsx@38e1588), following its [Node 24 `tsImport` bridge fix](privatenumber/tsx@6e5236b). ## CLI exit codes CLI startup is now awaited at the top level in all three loader paths: tsx, SWC, and disabled transpilation. If an import never settles and Node runs out of work, Node reports an unsettled top-level await and exits 13. Successful commands still exit 0, and command-specific failure codes are preserved. ## Breaking changes Rich-text data keeps its existing format. No database migration is needed. Payload's built-in features have been updated, but your own TypeScript code or custom features may need changes: - **Generic types:** `SerializedEditorState<T>`, `SerializedElementNode<T>`, and `SerializedRootNode<T>` no longer accept `<T>`. Remove it if the base node type is enough, or use Payload's `TypedEditorState<T>` for documents with your own node types. Without `<T>`, children are still `SerializedLexicalNode[]`. - **Export types:** `ReturnType<Node['exportJSON']>` can now make fields such as `version` and `url` optional. Use the node's explicit serialized type, such as `SerializedLinkNode`, when you need the full format. Normal `node.exportJSON()` calls still return full JSON. - **Selection listeners:** `SELECTION_CHANGE_COMMAND` now fires before the DOM is updated. If your custom listener reads the DOM, defer that work with `$onUpdate(() => editor.read('latest', callback))`. - **Saved node references:** If you keep a node reference across an editor update, call `node.getLatest().exportJSON()` to export its current values. The type changes also affect imports through `@payloadcms/richtext-lexical/lexical` and its subpaths. Payload's `TypedEditorState<T>` and its own serialized node types keep their generic APIs for this upgrade. Keep importing Lexical through Payload's re-exports; do not install a separate Lexical version. See the [custom feature documentation](https://payloadcms.com/docs/rich-text/custom-features). The table below also lists removed APIs that may affect custom features. `LexicalComposer` is deprecated but still available. ## Breaking changes and Payload migrations Reviewed [0.51.0](https://github.com/facebook/lexical/releases/tag/v0.51.0) and [0.52.0](https://github.com/facebook/lexical/releases/tag/v0.52.0), including the serialization declarations. **Yes** means Payload code needed adaptation; **No** means no Payload migration was required. | Release | Breaking change | Required migration in Payload | Changes made | | ------- | --------------- | ----------------------------- | ------------ | | 0.51 | [npm packages are ESM only](meta/lexical#9127); older CommonJS consumers must use dynamic imports. | No | Payload already uses ESM. This removes the asynchronous Lexical wrapper involved in the CLI reproducer. | | 0.51 | [Serialization schemas and compact export](meta/lexical#8602) add `exportJSON` overloads and remove the `SerializedEditorState`, `SerializedElementNode`, and `SerializedRootNode` generics. `ReturnType` can now infer compact, partial JSON. | Yes | Infer the full-format overload for node hooks, validation and population while preserving custom nodes' literal `type` discriminants. Update `hasText` to the non-generic editor-state type. | | 0.51 | [`exportJSON` can serialize a retained instance without calling `getLatest()`](meta/lexical#8602). | No | Audited Payload's clipboard and Markdown call sites: they serialize nodes obtained from the current selection/tree, without an intervening mutation. Custom callers holding stale references should use `node.getLatest().exportJSON()`. | | 0.51 | [Deprecated Prism re-exports are removed from `@lexical/code`](meta/lexical#9141). | No | Payload does not consume the removed exports. | | 0.52 | [`SELECTION_CHANGE_COMMAND` runs before DOM reconciliation](meta/lexical#9219), including node and table selections. | Yes | Defer link popup, inline toolbar and decorator DOM work with `$onUpdate` and `editor.read('latest', ...)`. Keep nested decorator updates with their own editor. The table menu already defers DOM reads. | | 0.52 | [Default HTML export honors `DOMRenderExtension` `$createDOM` overrides](meta/lexical#9231). | No | Payload does not configure these extension overrides; existing converter tests pass. | | 0.52 | [`LexicalNode.getCommonAncestor` is removed](meta/lexical#9238). | No | No Payload call sites. Custom consumers can use `$getCommonAncestor`, accounting for its different handling of non-element nodes. | React package entry points were compared against 0.50.0; no Payload proxy exports need adding or removing. ## Previous Lexical upgrades - [#18149](#18149) — 0.48.0 → 0.50.0 - [#17554](#17554) — 0.45.0 → 0.48.0 - [#17064](#17064) — 0.41.0 → 0.45.0
zurfyx
added a commit
that referenced
this pull request
Oct 15, 2026
… deprecations into CHANGELOG.md, add an Upgrading page
## Description
CHANGELOG.md only has flat commit lists, so someone upgrading from an older
version cannot find what broke, or how to migrate, without reading every
GitHub release. The new changeset-based release format fixes this for
future versions; this makes it work from older versions too.
- For every version from v0.23.0 to v0.52.0, CHANGELOG.md now starts with
`### Breaking changes` and `### Deprecations` in the new format (76
breaking changes, 12 deprecations), each with packages, a PR link,
`Detect:` and `Migration:` text. The entries come from a verified
inventory of those releases and are reused with light editing; a runtime
only change says what to test. The existing lines are kept, unchanged,
under `### All changes`. A short preamble says how to read the file.
- `docs/upgrading.md` ("Upgrading" in the sidebar) is a short page: upgrade
all packages together, then read CHANGELOG.md between your version and the
target (also at `node_modules/lexical/CHANGELOG.md`), or print just that
range with `pnpm run changelog:range`.
- The repository CHANGELOG.md test now checks that every v0.52.0 breaking
entry has a PR and a Migration section.
## Test plan
### Before
```
$ pnpm run changelog:range -- --from 0.45.0 --breaking
No breaking changes or deprecations after 0.45.0.
```
### After
```
$ git diff --numstat HEAD~1 -- CHANGELOG.md
1213 0 CHANGELOG.md
```
(insertions only: no existing line changed)
```
$ pnpm run changelog:range -- --from 0.45.0 --breaking | grep '^## \|^### '
## v0.46.0 (2026-06-25)
### Breaking changes
### Deprecations
## v0.47.0 (2026-07-10)
### Breaking changes
## v0.49.0 (2026-07-29)
### Breaking changes
### Deprecations
## v0.50.0 (2026-09-02)
### Breaking changes
### Deprecations
## v0.51.0 (2026-09-17)
### Breaking changes
### Deprecations
## v0.52.0 (2026-09-27)
### Breaking changes
### Deprecations
$ pnpm run changelog:range -- --from 0.51.0 --breaking | sed -n '1,8p'
## v0.52.0 (2026-09-27)
### Breaking changes
- **lexical, @lexical/table**: `SELECTION_CHANGE_COMMAND` runs before reconciliation ([#9219](#9219))
The command runs inside the pending update, before DOM
reconciliation, including automatic `NodeSelection` / `TableSelection`
$ pnpm run test-unit scripts/__tests__/unit/changelog.test.ts scripts/__tests__/unit/changesets.test.ts
✓ |scripts-unit| scripts/__tests__/unit/changesets.test.ts (20 tests) 19ms
✓ |scripts-unit| scripts/__tests__/unit/changelog.test.ts (17 tests) 2166ms
Tests 37 passed (37)
$ pnpm -C packages/lexical-website run docusaurus build
...
[SUCCESS] Generated static files in "build".
```
A script check confirmed every PR referenced by the inventory appears in
CHANGELOG.md, every backfilled breaking entry has a PR and a Migration
section, and every deprecation has a Replacement.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Breaking change
SELECTION_CHANGE_COMMANDnow consistently runs before DOM reconciliation, inside the pending writable update. Previously, some automatic non-range selection notifications, includingNodeSelectionandTableSelection, ran after reconciliation.Handlers must account for the new contract:
$getSelection()returns the pending selection;$getPreviousSelection()returns the selection from the last committed editor state.selectionchangeevents. Unchanged selections are deduplicated, except for retained native dirty-selection notifications.Migration
Keep model-only selection handling in the command listener. Move DOM-dependent work, including element lookup, focus checks, and floating UI positioning, into
$onUpdate, and read the reconciled model state inside that callback:Import
$onUpdatefromlexical. Read selection and nodes inside the deferred callback instead of capturing mutable pending objects. UseregisterUpdateListenerwhen the UI must respond to every commit, including content-only changes.SKIP_DOM_SELECTION_TAGcontinues to deliberately leave the browser selection unsynchronized.Description
SELECTION_CHANGE_COMMANDcan be missed when nativeselectionchangeevents are suppressed or coalesced, including deletion inside a text node. Detect changes in the pending editor state and notify before reconciliation, independently of DOM events.Use one pre-reconciliation contract for native, programmatic, and non-range selections. Listeners see the pending selection and the actual previous committed selection, and their edits and transforms join the same commit. Deduplicate unchanged selections while retaining native dirty-selection workarounds and the connected-root requirement for automatic range/null notifications.
Migrate DOM-dependent table and playground handlers to $onUpdate, with read('latest') when reading reconciled model state. Table normalization uses model nodes, so newly created tables and cells can be selected in the same update. Register the table observer's selection-command handler only while a root exists, with cleanup on removal and replacement.
Bound non-converging selection listeners without rolling back the user's edit: commit the pending state before reporting through onWarn. Document the notification timing and DOM availability contract, including migration guidance for third-party DOM-reading handlers.
Closes #9179
Closes #9214
Test plan
New browser unit tests to cover functionality. Coverage includes deletion and replacement typing, notification deduplication, previous-selection semantics, listener edits and transforms, undo merging with onUpdate/$onUpdate, newly inserted tables/cells, table escape handling, root lifecycle, and non-converging listeners.