Repository navigation
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.
etrepum
force-pushed
the
codex/fix-9179-selection-change
branch
from
September 24, 2026 15:17
7f1b3e6 to
53ba250
Compare
… 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.
etrepum
pushed a commit
that referenced
this pull request
Oct 6, 2026
…paces beside line breaks in Markdown table cells ## Description Fixes from a /code-review of the playground's `TABLE` Markdown transformer: - An empty row is written `| | |`, which `isTableRowDivider` also accepts, so an empty body row was read as a delimiter row: it was dropped and the row above it became a header, and a table with an empty header row stayed text. A delimiter row now needs a dash in every cell, as GFM requires. `isTableRowDivider` itself is unchanged. - An empty paragraph in a cell was lost: `a`, an empty paragraph and `b` exported as `a<br>b`, the same as two paragraphs. Each paragraph is now a line, so an empty one is an empty line (`a<br><br>b`), which reads back as a blank line between them. After a list or quote it adds a line beyond the one that ends the block. - Spaces next to a line break were trimmed on import as the cell's padding (`a ` then a break then `b` read back as `a` and `b`). The space or tab next to a break is now written as a character reference (`a  <br>b`). - A cell with more line breaks than a call can take arguments threw `RangeError: Maximum call stack size exceeded` from `splitText(...offsets)`, and reading one was quadratic. The text under a cell is now rebuilt in one pass and spliced in, and the decoder joins its lines once, so a 64,000-line cell reads in under a second instead of about ten. - Text between code marks that had no mark of its own (in a node between the start and end marks) wasn't made code. The upstream review asked that pipes after a run of backslashes be split by the parity of the run (`\|` escaped, `\\|` a separator, `\\\|` escaped). `splitTableRow` reads each backslash with the character after it, which gives exactly that; new tests cover those rows and `| a | \a | b |`. ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-playground/__tests__/unit/MarkdownTransformers.test.ts × keeps an empty body row that reads like a delimiter row 16ms × reads a table whose header cells are empty 9ms × keeps the line of an empty paragraph between paragraphs in a cell 3ms × keeps the line of an empty paragraph after a heading in a cell 2ms × keeps the line of an empty paragraph first in a cell 2ms × keeps the line of an empty paragraph last in a cell 2ms × keeps the line of an empty paragraph alone in a cell 2ms × keeps the line of an empty paragraph after a list in a cell 2ms × keeps the spaces beside a line break in "a \nb" 4ms × keeps the spaces beside a line break in "a\n b" 3ms × keeps the spaces beside a line break in "a\t\n\tb" 3ms × keeps the spaces beside a line break in "a \n \nb" 3ms × reads a cell with more line breaks than a call can take arguments 15468ms AssertionError: expected [ [ [ 'a' ], [ 'b' ] ], …(1) ] to deeply equal [ [ [ 'a' ], [ 'b' ] ], …(2) ] AssertionError: Root child must be a table AssertionError: expected '| a<br>b |' to be '| a<br><br>b |' // Object.is equality AssertionError: expected [ [ 'a\nb' ] ] to deeply equal [ [ 'a \nb' ] ] RangeError: Maximum call stack size exceeded ``` ### After ``` $ vitest run --project unit packages/lexical-playground Tests 504 passed (504) ``` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
that referenced
this pull request
Oct 7, 2026
…l and guard missing offsets ## Description - A line of only spaces right after a block in a cell (`<ul><li>a</li></ul>  <br>`) was dropped on import, since any whitespace there was taken as padding. Only whitespace written literally is dropped now. - Telling literal spaces from references sliced the source by a node's offsets without checking that they exist, so a tree whose positions have only lines and columns sliced the whole document and stopped trimming `a <br> b`. Without offsets, all edge spaces are taken as literal, as without a source. - Each line before a block in a cell is trimmed once instead of twice. ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastTableHtml.test.ts × keeps a line of only spaces after a block in a cell × trims the spaces around a <br> in a tree without offsets ``` ### After ``` $ vitest run --project unit packages/lexical-markdown packages/lexical-playground/__tests__/unit packages/lexical-code-core packages/lexical-react packages/lexical-mdast Tests 1628 passed (1628) $ vitest run --project browser packages/lexical-mdast dev-examples/mdast-editor Tests 44 passed (44) $ pnpm run tsc && pnpm run flow Found 0 errors ``` Only Chromium was available, so the browser tests did not run in Firefox or WebKit. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
that referenced
this pull request
Oct 7, 2026
…nd columns ## Description Telling the spaces a cell line was written with from those written as character references needs a node's offsets in the source. A tree whose positions have only lines and columns, as a tree transform may leave them, took every edge space as literal, so `a<br> b` read back as `a` and `b`. Offsets are now worked out from the line and column when a point has none. The three places that ended a line in `cellItems` are one helper again, and its doc comment states which whitespace after a block makes a line: anything but spaces and tabs written as they are, so a no-break space after a block, which GFM doesn't trim, is kept as a line too. ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastTableHtml.test.ts × reads "a<br> b" in a tree without offsets as ["a"," b"] Tests 1 failed | 23 passed (24) ``` ### After ``` $ vitest run --project unit packages/lexical-mdast Tests 252 passed (252) $ vitest run --project browser packages/lexical-mdast dev-examples/mdast-editor Tests 44 passed (44) ``` Only Chromium was available, so the browser tests did not run in Firefox or WebKit. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
that referenced
this pull request
Oct 8, 2026
…oes and pad code spans only for spaces ## Description - `unescapeText` read backslash escapes and character references in two passes, so an escaped `\A` came back as `A` instead of the text `A`. It now reads both in one pass. Export writes `\&` before text that would read as a reference, so text like ` ` round-trips. - A decimal reference with more than 7 digits (`�`) is not a reference in CommonMark and now stays text instead of becoming U+FFFD. - A code span was padded when it started and ended with any whitespace, but a reader strips only U+0020, so spans like a tab-wrapped `x` or a lone no-break space are now written without padding. ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-markdown/src/__tests__/unit/CodeSpanEscapes.test.ts × round-trips "\tx\t" bare × round-trips " " bare × reads "�" as the text "�" × reads "\\A" as the text "A" × round-trips text that reads as one ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 5 ⎯⎯⎯⎯⎯⎯⎯ Tests 5 failed | 13 passed (18) ``` The second line is the no-break space case, which the terminal shows as a space. ### After ``` $ vitest run --project unit packages/lexical-markdown/src/__tests__/unit/CodeSpanEscapes.test.ts Tests 18 passed (18) ``` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
that referenced
this pull request
Oct 8, 2026
## Description
A tree transform can leave points with only a line and column. The table extension worked out offsets itself with a module-level cache that kept the last source alive and miscounted a bare newline followed by another, while every other handler that reads the source by offset (heading style, list markers, code fences) fell back to its no-source behavior. The import (and the streaming parser) now fill in each missing offset once, after parsing, from the line and column, so every reader gets it and nothing is cached across imports.
## Test plan
### Before
```
$ vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastTableHtml.test.ts
× reads "h\n=\n\n\n""a<br> b" in a tree without offsets
AssertionError: expected '# h\n\n| a |\n| -----------…' to match /^h\n=+\n/
```
### After
```
$ vitest run --project unit packages/lexical-markdown packages/lexical-playground/__tests__/unit packages/lexical-code-core packages/lexical-react packages/lexical-mdast
Tests 1636 passed (1636)
$ vitest run --project browser packages/lexical-mdast dev-examples/mdast-editor
Tests 44 passed (44)
$ vitest run --project scripts-unit scripts/__tests__/unit/treeShakingSource.test.ts
Tests 342 passed (342)
$ pnpm run tsc && pnpm run flow
Found 0 errors
```
Only Chromium was available, so the browser tests did not run in Firefox or WebKit.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
that referenced
this pull request
Oct 18, 2026
…ts them ## Description `MdastTableExtension` trimmed spaces and tabs from the edges of every line of a cell, including a cell with no `<br>`, so spaces written as character references (` `), which GFM keeps, were dropped. Only the whitespace beside a `<br>` is trimmed now; the cell's own edges keep what the GFM parser left, as on main. ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts -t "references at the edges" × keeps spaces written as references at the edges of a cell 45ms AssertionError: expected 'b' to be ' b ' // Object.is equality Tests 1 failed | 113 skipped (114) ``` ### After ``` $ vitest run --project unit packages/lexical-mdast Tests 225 passed (225) ``` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.
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:
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:
Validation after the root-lifecycle follow-up:
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.