Skip to content

[lexical][lexical-extension][lexical-list][lexical-markdown][lexical-mdast][lexical-selection][lexical-utils][lexical-website][lexical-y] Feature: Treat a node that declares children: 'block' as a block container for structural commands under NodeStructureExtension - #9590

Merged
zurfyx merged 10 commits into
mainfrom
zurfyx/structure-block-containers
Oct 30, 2026

Conversation

@zurfyx

@zurfyx zurfyx commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Description

Structural commands decide where to stop by $isRootOrShadowRoot. A container that holds blocks but is not a shadow root (a callout, a box) is treated as one more block, so in it:

$setBlocksType, indent and outdent, and $removeList already act in place in any container.

This adds one rule, where node structure is enforced (NodeStructureExtension, registerNodeStructure, or any @lexical/y binding): a class that declares children: 'block' is a block container, like the root and shadow roots, for those commands. A new core helper, $isBlockContainer(node) (@experimental node-structure), is the root, a shadow root, or, where structure is enforced, a block element whose class declares children: 'block'. The commands above use it instead of $isRootOrShadowRoot for the "where to stop" decision. A declared container is not a selection boundary: select-all, the arrow keys, and Backspace or Delete at its edges keep isShadowRoot()'s meaning and are unchanged.

Classes that declare nothing, and editors that do not enforce structure, behave as before, with one fix for a list that silently disappears (#9570): where structure is enforced, $insertList in a box that also holds a block a list item cannot hold (a quote, another box) used to wrap the whole box in a list item, which the normalization emptied and dropped. Now the box stays, and the paragraph (or heading, or quote) holding the selected text becomes a list in place, inside the box.

Closes #9570

How each command behaves today, and with this change

Every cell is a case in BlockContainers.test.ts (start: p("before") / CONTAINER(p("abc") p("def")) / p("after"), caret in abc). "Box" declares nothing, "declared box" declares children: 'block', both are not shadow roots. Columns show NodeStructureExtension on; without it, only the box column's list conversion differs (noted).

Command Box (declares nothing) Declared box: main → this PR Shadow root Nested (box in box / declared in declared / shadow in shadow)
$insertList box replaced by the list, its paragraphs joined into one item (without the extension: one item holding the paragraphs) same as box → paragraph converted in place in place box: outer box dropped and no list (#9570) → in place; declared: same → in place; shadow: in place
Enter in an empty last list item never leaves the list (adds another item) same → leaves the list, new paragraph in the box leaves the list as for one level
$removeList in place in place in place in place
$setBlocksType (heading, quote, code) in place in place in place in place
$wrapNodes (deprecated) paragraph moved out of the box same → wrapped in place in place as for one level
Indent, outdent in place in place in place in place
insertNodes of two paragraphs mid-text flattened into one line same → split into paragraphs split as for one level
$insertNodeToNearestRoot (horizontal rule) box split in two around it same → inserted inside the box inside as for one level
Backspace at the box's start first paragraph joins the block before the box unchanged (not a boundary) blocked as for one level
Backspace after the box, Delete at its end next paragraph joins the box's last one unchanged (not a boundary) blocked as for one level
Markdown # , - nothing happens same → converts converts as for one level

A named slot holding a shadow root behaves as a shadow root in every row; a bare block in a slot (one block, no siblings) leaves the commands it has cases for as no-ops, unchanged, and a declared container used as a slot value behaves as a declared container.

With @lexical/y, a collaborator's typing in a paragraph that becomes a list inside a declared box is kept (the paragraph is converted in place); in a box that declares nothing the box is replaced by the list, a move, and the typing is lost (both cases in packages/lexical-y/src/__tests__/unit/BlockContainers.test.ts).

What isShadowRoot() keeps

A shadow root is also an editing boundary: $selectAll is scoped to it, getTopLevelElement stops at it, and Backspace and Delete do not cross its edges (rows above). A declared container gets none of that, only the structural rule, so a callout's paragraphs still join with the blocks around it. That matches ProseMirror, which separates the two: a node's content expression (content: "block+") decides what it holds and where structural commands act, and isolating separately marks nodes whose sides "regular editing operations, like backspacing or lifting, won't cross" (its example is a table cell). wrapInList wraps the blockRange around the innermost textblock(s), in their shared ancestor, so it never replaces a container that holds the range.

Decisions

  1. Only where structure is enforced. The declaration counts only where node structure is enforced: NodeStructureExtension (unless disabled), registerNodeStructure, or any @lexical/y binding, which always enforces it (so disabled: true does not turn the rule off in a collab editor). An editor that does not enforce it (a headless editor running the same command) keeps today's behavior, and the docs' "on their own they change nothing at runtime" stays true.
  2. Only children: 'block', and it is not a shadow root. The two are separate facts. children: 'block' says what a node holds (any blocks); isShadowRoot() also makes the node a hard editing edge (select-all scope, Backspace and Delete stop at it). A table cell is both. A callout holds blocks without a hard edge, so its paragraphs still join the blocks around it. A class that lists specific children (ListNode lists ListItemNode, a table its rows) is structure, not a free-form holder, so it is not a container. This matches ProseMirror, where a content expression of block+ (a blockquote) holds any blocks and list_item+ (a list) holds only items, while isolating is a separate flag for hard edges.
  3. Joins at the edges stay as they are. Backspace at the start of a callout's first paragraph joins it to the block before the callout, as for any element. A class that wants a hard edge is a shadow root.
  4. The list fallback for classes that declare nothing stays (only where structure is enforced). When $insertList would wrap a box that also holds a block a list item cannot hold (a quote, another box), the box stays and the paragraph (or heading, or quote) holding the selected text becomes a list in place, inside the box, instead of the list being dropped. Decided for each box before anything is converted, so every selected block of one box is treated alike.
  5. Left out on purpose: $splitNode (one playground caller), typing at an element point in a container, the decorator line navigation (selection-level, keeping the shadow root meaning), the playground toolbar's $findTopLevelElement, and the deprecated $wrapNodes with a block decorator selected directly in a container (it moves the container's blocks, at the root and in shadow roots too, as on main).

Fixes from review (second commit)

Two independent reviews (one per model family) traced every changed site and proved the substitutions equivalent for classes that declare nothing. Their confirmed findings are fixed, each with a test: $insertList no longer replaces the container of a selected block decorator, nor an empty container a range passes over (also for shadow roots, where main did); $setBlocksType and $wrapNodes leave an empty declared container in place (keeping its named slots); the fallback in decision 4 no longer acts at two levels in one command; $isBlockContainer no longer throws outside an active editor and is false for an inline subclass; the docs say "where structure is enforced" and note rootMode: 'root'. A formatted paragraph converted in a declared container keeps a collaborator's typing too (new @lexical/y case).

A fresh re-review re-ran every finding (all fixed or documented) and found two more, fixed in the third commit: $insertList decides which nodes it keeps before converting any (an empty quote converted first made its box look convertible), and INTERNAL_$isBlock stays as on main (excluding declared containers there stopped a shadow root from getting its paragraph back when its only, empty, declared child was deleted); $setBlocksType skips a declared container itself instead.

The Meta code-review bot's items are in the fifth commit: $setBlocksType with the caret in an empty declared container puts the new block in it (like $insertList and $wrapNodes), the Flow guard is implies node is ElementNode, the @lexical/mdast shortcuts have test rows, and the rootMode JSDoc names $insertNodeToNearestRootAtCaret. Its second review (approved, optional suggestions) is in the sixth commit: $setBlocksType keeps a range that starts in an empty declared container, a new block put into an empty container does not take the container's indent and format, and the fixes that reach editors without the extension ($wrapNodes in an empty root, which threw, or an empty shadow root; $insertList around shadow roots) are pinned with and without it.

Its third review found a regression, fixed in edd6967: where structure is enforced, a paragraph holding the character limit's OverflowNode was taken for a box holding a block (OverflowNode.isInline() is false), so $insertList split it. The check now uses the normalization's own notion of inline content (INTERNAL_isInlineContent, internal), with cases for the overflow in a paragraph, alone in a paragraph, and in a box that holds a quote. main is merged in (dee6f34, 0caffb6); #9588's StructuralCommands cells that waited for this change are plain tests.

Changeset

.changeset/structure-block-containers.md ([feature], with a Verify: paragraph).

Test plan

BlockContainers.test.ts in @lexical/extension runs 20 commands (list conversion collapsed and over a range, Enter in an empty list item, $removeList, heading, quote and code conversion, $wrapNodes, indent, outdent, insertNodes with blocks and with a heading, $insertNodeToNearestRoot in the middle and at the end, Backspace at the container's start and after it, Delete at its end, the # and - shortcuts) in 9 contexts (root, a box that declares nothing, a declared box, a shadow root, each nested in its own kind, a named slot holding a shadow root or a bare block), with and without NodeStructureExtension, in a DOM editor, plus $isBlockContainer (absent, disabled and enforced extension) and the #9570 repro. BlockContainers.test.ts in @lexical/y checks that a collaborator's typing in a paragraph turned into a list inside a declared container survives.

Before

The test files of this PR run against main's sources (git checkout be5afea -- <the changed source files>):

$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts
     × insertList-collapsed in declared (NodeStructureExtension: true)
Expected: "dbox(list[bullet](li("abc")) p("def"))"
Received: "list[bullet](li("abc" br "def"))"
      Tests  62 failed | 337 passed (399)

$ pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/BlockContainers.test.ts
     × paragraph -> list in a declared container ‖ type in it keeps the text (1,2)
      Tests  6 failed | 2 passed (8)

After

At head 0caffb6 (main merged):

$ pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/matrix/StructuralCommands.test.ts packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts packages/lexical-y/src/__tests__/unit/BlockContainers.test.ts
      Tests  1107 passed (1107)
$ pnpm exec vitest run --project unit packages/lexical/src packages/lexical-extension packages/lexical-list packages/lexical-selection packages/lexical-mdast packages/lexical-markdown packages/lexical-utils packages/lexical-overflow
      Tests  5145 passed | 4 skipped (5149)
$ pnpm exec vitest run --project unit packages/lexical-y
      Tests  11644 passed | 69 expected fail | 2 skipped (11715)
$ LEXICAL_Y_BLOCK_ID=1 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/BlockContainers.test.ts
      Tests  8 passed (8)

$ pnpm run ci-check
Found 0 errors

Unit suites of every touched package and their dependents (at the first commit; CI's full unit, browser, integrity and e2e canary jobs also passed at 20fd498 and a57da6a):

$ pnpm exec vitest run --project unit packages/lexical-list packages/lexical-selection packages/lexical-markdown packages/lexical-mdast packages/lexical-utils packages/lexical-extension packages/lexical-rich-text packages/lexical-table packages/lexical-clipboard packages/lexical/src packages/lexical-playground/__tests__/unit packages/lexical-html packages/lexical-react
 Test Files  318 passed | 1 skipped (319)
      Tests  6177 passed | 1 skipped (6178)
$ pnpm exec vitest run --project unit packages/lexical-y packages/lexical-yjs
 Test Files  166 passed | 2 skipped (168)
      Tests  7487 passed | 46 expected fail | 4 skipped (7537)

Not run: browser and E2E suites (no playground node declares children: 'block', so the playground behaves as before).

…mdast][lexical-selection][lexical-utils][lexical-website][lexical-y] Feature: Treat a node that declares children: 'block' as a block container for structural commands under NodeStructureExtension

## Description

Structural commands decide where to stop by `$isRootOrShadowRoot`. A container that holds blocks but is not a shadow root (a callout, a box) is treated as one more block, so in it:

- `$insertList` replaces the whole container with the list (its fields are lost), and in a box inside a box, with `NodeStructureExtension`, it drops the outer box and makes no list at all (#9570);
- Enter in an empty last list item never leaves the list;
- `$wrapNodes` moves the paragraph out of the container;
- pasting several paragraphs (`insertNodes`) flattens them into one line;
- `$insertNodeToNearestRoot` (a horizontal rule, a table) splits the container in two;
- the markdown block shortcuts (`# `, `- `) do nothing.

`$setBlocksType`, indent and outdent, and `$removeList` already act in place in any container.

This adds one rule, enforced by `NodeStructureExtension`: a class that declares `children: 'block'` is a block container, like the root and shadow roots, for those commands. A new core helper, `$isBlockContainer(node)` (`@experimental node-structure`), is the root, a shadow root, or, where the extension is registered and enabled, an element whose class declares `children: 'block'`. The commands above use it instead of `$isRootOrShadowRoot` for the "where to stop" decision. A declared container is not a selection boundary: select-all, the arrow keys, and Backspace or Delete at its edges keep `isShadowRoot()`'s meaning and are unchanged.

Classes that declare nothing, and editors without the extension (or with it disabled), behave as before. The one exception is a fix for a list that silently disappears: with the extension, when the selected text sits in a block a list item cannot hold (a box inside a box, a quote inside a box), `$insertList` converts that block in place instead of wrapping the outer container in a list item that the normalization then empties and removes.

Closes #9570

## Changeset

`.changeset/structure-block-containers.md` (`[feature]`, with a `Verify:` paragraph).

## Test plan

`BlockContainers.test.ts` in `@lexical/extension` runs 20 commands (list conversion collapsed and over a range, Enter in an empty list item, `$removeList`, heading, quote and code conversion, `$wrapNodes`, indent, outdent, `insertNodes` with blocks and with a heading, `$insertNodeToNearestRoot` in the middle and at the end, Backspace at the container's start and after it, Delete at its end, the `# ` and `- ` shortcuts) in 9 contexts (root, a box that declares nothing, a declared box, a shadow root, each nested in its own kind, a named slot holding a shadow root or a bare block), with and without `NodeStructureExtension`, in a DOM editor, plus `$isBlockContainer` (absent, disabled and enforced extension) and the #9570 repro. `BlockContainers.test.ts` in `@lexical/y` checks that a collaborator's typing in a paragraph turned into a list inside a declared container survives.

### Before

```
$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts
     × insertList-collapsed in declared (NodeStructureExtension: true)
Expected: "dbox(list[bullet](li("abc")) p("def"))"
Received: "list[bullet](li("abc" br "def"))"
      Tests  28 failed | 328 passed (356)

$ pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/BlockContainers.test.ts
     × paragraph -> list in a declared container ‖ type in it keeps the text (1,2)
     × paragraph -> list in a declared container ‖ type in it keeps the text (2,1)
      Tests  2 failed | 2 passed (4)
```

### After

```
$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts
      Tests  357 passed (357)

$ pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/BlockContainers.test.ts
      Tests  4 passed (4)
$ LEXICAL_Y_BLOCK_ID=1 pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/BlockContainers.test.ts
      Tests  4 passed (4)

$ pnpm run ci-check
Found 0 errors
```

Unit suites of every touched package and their dependents:

```
$ pnpm exec vitest run --project unit packages/lexical-list packages/lexical-selection packages/lexical-markdown packages/lexical-mdast packages/lexical-utils packages/lexical-extension packages/lexical-rich-text packages/lexical-table packages/lexical-clipboard packages/lexical/src packages/lexical-playground/__tests__/unit packages/lexical-html packages/lexical-react
 Test Files  318 passed | 1 skipped (319)
      Tests  6177 passed | 1 skipped (6178)
$ pnpm exec vitest run --project unit packages/lexical-y packages/lexical-yjs
 Test Files  166 passed | 2 skipped (168)
      Tests  7487 passed | 46 expected fail | 4 skipped (7537)
```

Not run: browser and E2E suites (no playground node declares `children: 'block'`, so the playground behaves as before).
@vercel

vercel Bot commented Oct 30, 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 Oct 30, 2026 8:53pm UTC
lexical-playground Ready Ready Preview Oct 30, 2026 8:53pm 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 Oct 30, 2026
@meta-code-review

meta-code-review Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 30, 2026, 9:18 PM UTC

@pkg-pr-new

pkg-pr-new Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
lexical

npm i https://pkg.pr.new/lexical@9590

@lexical/a11y

npm i https://pkg.pr.new/@lexical/a11y@9590

@lexical/clipboard

npm i https://pkg.pr.new/@lexical/clipboard@9590

@lexical/code

npm i https://pkg.pr.new/@lexical/code@9590

@lexical/code-core

npm i https://pkg.pr.new/@lexical/code-core@9590

@lexical/code-prism

npm i https://pkg.pr.new/@lexical/code-prism@9590

@lexical/code-shiki

npm i https://pkg.pr.new/@lexical/code-shiki@9590

@lexical/compiler

npm i https://pkg.pr.new/@lexical/compiler@9590

@lexical/devtools-core

npm i https://pkg.pr.new/@lexical/devtools-core@9590

@lexical/dragon

npm i https://pkg.pr.new/@lexical/dragon@9590

@lexical/eslint-plugin

npm i https://pkg.pr.new/@lexical/eslint-plugin@9590

@lexical/extension

npm i https://pkg.pr.new/@lexical/extension@9590

@lexical/fast-check

npm i https://pkg.pr.new/@lexical/fast-check@9590

@lexical/file

npm i https://pkg.pr.new/@lexical/file@9590

@lexical/hashtag

npm i https://pkg.pr.new/@lexical/hashtag@9590

@lexical/headless

npm i https://pkg.pr.new/@lexical/headless@9590

@lexical/history

npm i https://pkg.pr.new/@lexical/history@9590

@lexical/html

npm i https://pkg.pr.new/@lexical/html@9590

@lexical/internal

npm i https://pkg.pr.new/@lexical/internal@9590

@lexical/link

npm i https://pkg.pr.new/@lexical/link@9590

@lexical/list

npm i https://pkg.pr.new/@lexical/list@9590

@lexical/mark

npm i https://pkg.pr.new/@lexical/mark@9590

@lexical/markdown

npm i https://pkg.pr.new/@lexical/markdown@9590

@lexical/mdast

npm i https://pkg.pr.new/@lexical/mdast@9590

@lexical/offset

npm i https://pkg.pr.new/@lexical/offset@9590

@lexical/overflow

npm i https://pkg.pr.new/@lexical/overflow@9590

@lexical/plain-text

npm i https://pkg.pr.new/@lexical/plain-text@9590

@lexical/react

npm i https://pkg.pr.new/@lexical/react@9590

@lexical/rich-text

npm i https://pkg.pr.new/@lexical/rich-text@9590

@lexical/selection

npm i https://pkg.pr.new/@lexical/selection@9590

@lexical/table

npm i https://pkg.pr.new/@lexical/table@9590

@lexical/tailwind

npm i https://pkg.pr.new/@lexical/tailwind@9590

@lexical/text

npm i https://pkg.pr.new/@lexical/text@9590

@lexical/utils

npm i https://pkg.pr.new/@lexical/utils@9590

@lexical/y

npm i https://pkg.pr.new/@lexical/y@9590

@lexical/yjs

npm i https://pkg.pr.new/@lexical/yjs@9590

commit: 0caffb6

…-website][lexical-y] Bug Fix: Keep block containers through empty containers, selected decorators, slots and mixed selections

## Description

Fixes from the review of the block container rule:

- `$insertList` no longer replaces the container of a selected block decorator (a horizontal rule selected in a callout or a shadow root), nor an empty container (shadow root or declared) that a range passes over, and `$setBlocksType` leaves an empty declared container in place (`INTERNAL_$isBlock` now excludes every block container).
- `$wrapNodes` on an empty container puts the new block inside it instead of replacing it (and the container's named slots with it), and treats a declared container used as a named-slot value like a shadow-root value.
- The `$insertList` fallback for classes that declare nothing now decides once per command whether the top node can become a list item (it holds only inline content, plain paragraphs and lists). Before, a range over `box(quote, paragraph)` converted the quote in place and then replaced the box, nesting the new list.
- `$isBlockContainer` returns false for an inline element that inherits `children: 'block'`, and for a declared class outside an active editor (a bare `editorState.read()`) instead of throwing.
- Docs and changeset: the rule applies wherever node structure is enforced, which includes every `@lexical/y` binding (so `NodeStructureExtension {disabled: true}` does not turn it off there); `rootMode: 'root'` still splits containers.

## Test plan

### Before

```
$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts
     × a horizontal rule selected in a declared box: $insertList (NodeStructureExtension)
Expected: "dbox(p("abc") horizontalrule())"
Received: "list[bullet](li("abc")) / horizontalrule()"
     × a range over a horizontal rule in a declared box: $insertList (NodeStructureExtension)
Expected: "dbox(list[bullet](li("abc")) horizontalrule() list[bullet](li("def")))"
Received: "list[bullet](li(list[bullet](li("abc")))) / horizontalrule() / list[bullet](li("def"))"
     × a range over a quote and a paragraph in a box that declares nothing: $insertList (NodeStructureExtension)
Expected: "box(list[bullet](li("y") li("x")))"
Received: "list[bullet](li(list[bullet](li("y"))) li("x"))"
     × with no active editor, a declared box is not a container
Error: Unable to find an active editor.
      Tests  12 failed | 363 passed (375)
```

### After

```
$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts packages/lexical-selection
      Tests  728 passed (728)
$ pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/BlockContainers.test.ts
      Tests  8 passed (8)
$ pnpm run ci-check
Found 0 errors
```

The full unit suites run in CI: the Mac running them locally was at a load average near 100, where the y and markdown timing tests time out on main and on this branch alike (the five y timing tests pass alone on both, in the same times).
…: Decide which nodes $insertList keeps before converting any, and keep INTERNAL_$isBlock as on main

## Description

Fixes from the second review round:

- `$insertList` decides, for every node it might convert in one command, whether that node is kept (it holds a block a list item cannot hold) before converting anything. The empty-element branch converted an empty quote first, after which its box looked convertible and was replaced, with its named slots.
- `INTERNAL_$isBlock` is back to main's definition. Excluding declared containers there also stopped `$restoreEmptyContainerParagraph` from putting a paragraph back in a shadow root whose only child, an empty declared container, was deleted. `$setBlocksType` now skips a declared container itself instead.

## Test plan

### Before

```
$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts -t "empty quote and a paragraph|only, empty, declared"
     × an empty quote and a paragraph of a box that declares nothing, node selected: $insertList (NodeStructureExtension)
Expected: "box{aside:p("slot")}(list[bullet](li() li("x")))"
Received: "list[bullet](li(list[bullet](li())) li("x"))"
     × removing the only, empty, declared box of a shadow root (NodeStructureExtension)
Expected: "sbox(p())"
Received: "sbox()"
      Tests  2 failed | 375 skipped (377)
```

### After

```
$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts packages/lexical-y/src/__tests__/unit/BlockContainers.test.ts packages/lexical-list packages/lexical-selection
      Tests  906 passed (906)
$ pnpm run ci-check
Found 0 errors
```

@meta-code-review meta-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The behaviour matrix in BlockContainers.test.ts holds up: its cases fail on main (52 of 385) and pass on this branch. For classes that declare nothing, and for editors that do not enforce node structure, the substitutions behave as on main, apart from the documented shadow-root fixes in $insertList and $wrapNodes. Below are a few suggestions, then the open design questions restated for maintainers.

Suggestions

  1. Flow guard (packages/lexical/flow/Lexical.js.flow:2410-2412). ): node is ElementNode; is a two-sided type guard, so in the false branch Flow removes ElementNode from the type. The TypeScript signature does the opposite: its brand narrows without excluding. With flow-bin 0.333, if (!$isBlockContainer(node)) node.notAMethod() on an ElementNode type-checks. AGENTS.md asks that types stay maintained for both TypeScript and Flow. ): implies node is ElementNode;, the form this file already uses for $isExtendableTextPointCaret, matches the TypeScript behaviour.
  2. $setBlocksType in an empty declared container (packages/lexical-selection/src/range-selection.ts:194). With the caret in an empty children: 'block' container, $setBlocksType now does nothing, while $insertList and $wrapNodes create the new block inside the container. That is no worse than main, which replaced the container. Appending the created block there would make the three commands agree.
  3. A test for the @lexical/mdast shortcuts (packages/lexical-mdast/src/MdastShortcuts.ts:280, :305). BlockContainers.test.ts only registers @lexical/markdown's shortcuts, so this change is untested. The mdast shortcuts do convert inside a declared container on this branch; one row with MdastShortcutsExtension would keep it that way.
  4. Small fixes. The $isBlockContainer JSDoc (packages/lexical/src/LexicalStructure.ts:1842) attaches rootMode: 'root' to $insertNodeToNearestRoot, which takes no options; the option belongs to $insertNodeToNearestRootAtCaret. The Test plan's pasted counts (357 and 4 tests) predate the third commit; the files now run 377 and 8 cases. AGENTS.md asks for the real After output.

Open questions for maintainers

  • Should a children: 'block' declaration count only where node structure is enforced (NodeStructureExtension, registerNodeStructure, every @lexical/y binding)? Then the same class keeps today's behaviour in an editor without the extension.
  • Should the $insertList fallback for classes that declare nothing ship as the default wherever structure is enforced? It keeps box(h p) but still replaces box(p p) with one list item, and it changes list conversion in every @lexical/y editor.

Comment thread packages/lexical/flow/Lexical.js.flow Outdated

declare export function $isBlockContainer(
node: ?LexicalNode,
): node is ElementNode;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Flow treats node is ElementNode as a two-sided guard, so the false branch removes ElementNode from node's type. With flow-bin 0.333, if (!$isBlockContainer(el)) el.notAMethod() type-checks for an el: ElementNode. The TypeScript brand exists to avoid exactly that. Suggest ): implies node is ElementNode;, which is how $isExtendableTextPointCaret is declared in this file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 8a7471f: ): implies node is ElementNode;, as for $isExtendableTextPointCaret.

if ($getSlotHost(prevNode) !== null) {
// An empty block container (a declared one: roots and shadow roots are
// never in the map) is not a block to convert.
if ($getSlotHost(prevNode) !== null || $isBlockContainer(prevNode)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

With the caret in an empty declared container, this skip turns $setBlocksType into a no-op, while $insertList and $wrapNodes (lines 274-277) put the new block inside the container. Consider appending the created element to the empty container here, so the three commands agree.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 8a7471f: with the selection in an empty declared container, $setBlocksType now appends the new block to it and selects it, as $insertList and $wrapNodes do. A range that only passes over an empty container still leaves it as it is, matching $insertList. Covered by "the caret in an empty declared box: $setBlocksType" and "an empty declared box in a range: $setBlocksType".

return (
$isParagraphNode(node) &&
$isRootOrShadowRoot(node.getParent()) &&
$isBlockContainer(node.getParent()) &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No case in BlockContainers.test.ts reaches this path: the test only registers @lexical/markdown's shortcuts. It does work on this branch: # , - , - [ ] and > convert inside a declared container under NodeStructureExtension. A row with MdastShortcutsExtension would guard it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added in 8a7471f: "@lexical/mdast shortcuts in block containers" types # , - and > with MdastShortcutsExtension in a declared box (with and without the extension), a box that declares nothing, a shadow root and the root.

*
* The commands that convert, wrap, split or insert blocks (`$insertList`,
* Enter in an empty list item, `$wrapNodes`, `insertNodes`,
* `$insertNodeToNearestRoot` unless given `rootMode: 'root'`, the markdown

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: $insertNodeToNearestRoot(node) takes no options; rootMode: 'root' belongs to $insertNodeToNearestRootAtCaret.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 8a7471f: the JSDoc lists $insertNodeToNearestRoot and $insertNodeToNearestRootAtCaret, and ties rootMode: \x27root\x27 to the latter.

…t $insertList does in a box that holds a block a list item cannot hold

## Description

Rewords the `$insertList` fallback for containers that declare nothing in the code comments, the changeset, the node structure docs and the `@lexical/y` Moves limit: where node structure is enforced, in a box that also holds a block a list item cannot hold (a quote, another box), the box stays and the paragraph (or heading, or quote) holding the selected text becomes a list in place, inside the box, instead of the list being dropped. No behavior change.

## Test plan

### Before

Wording only.

### After

```
$ pnpm exec prettier --check .changeset/structure-block-containers.md packages/lexical-list/src/formatList.ts packages/lexical-website/docs/collaboration/y.md packages/lexical-website/docs/serialization/serialization.md
All matched files use Prettier code style!
$ pnpm run check-changesets
Changeset check passed: 32 pending changeset(s) valid.
$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts
      Tests  377 passed (377)
```
…ksType's new block in an empty declared container, and address the review bot

## Description

From the Meta code-review bot on this PR:

- `$setBlocksType` with the caret in an empty `children: 'block'` container now puts the new block in it, as `$insertList` and `$wrapNodes` do (it was a no-op; main replaced the container). A range that only passes over an empty container still leaves it as it is.
- The Flow declaration of `$isBlockContainer` uses `implies node is ElementNode`, so the false branch keeps `ElementNode`, as the TypeScript brand does.
- `BlockContainers.test.ts` covers the `@lexical/mdast` shortcuts (`# `, `- `, `> `) in declared, plain and shadow containers.
- The `$isBlockContainer` JSDoc attaches `rootMode: 'root'` to `$insertNodeToNearestRootAtCaret`, which takes it.

## Test plan

### Before

```
$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts -t "caret in an empty declared box"
Expected: "p("before") / dbox(h()) / p("after")"
Received: "p("before") / dbox() / p("after")"
      Tests  1 failed | 384 skipped (385)
```

### After

```
$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts packages/lexical-selection
      Tests  738 passed (738)
$ pnpm run ci-check
Found 0 errors
```
@zurfyx

zurfyx commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Replies to the review summary (the inline items are answered in their threads, all fixed in 8a7471f):

  • Test plan counts: updated in the description to the real output at 8a7471f (385 and 8 cases; 50 and 6 of them fail against main's sources).
  • Open questions: both decided, see "Decisions" in the description. The declaration counts only where node structure is enforced. The $insertList fallback for classes that declare nothing stays wherever structure is enforced, @lexical/y included. That box(p p) is still replaced by one list item is intended: a box holding only paragraphs keeps today's behavior, and a box that should stay declares children: 'block'. The fallback only applies when a list item could not hold what the box holds (box(h p), box(quote p), a box in a box): there the box stays, and the paragraph (or heading, or quote) holding the selected text becomes a list in place, inside the box, instead of the list being dropped (Bug: [lexical-list] $insertList on a paragraph inside a nested container drops the outer container and makes no list when NodeStructureExtension runs #9570).

zurfyx added a commit that referenced this pull request Oct 30, 2026
… containers

## Description

The catalog contracts read, sync and export documents holding block containers, but never ran the structural commands in them, so a change to where those commands act (#9590) was not covered. `StructuralCommands.test.ts` adds the cells: list conversion of each type (bullet, number, check), Enter in an empty last list item, pasting two paragraphs mid-text (`insertNodes`), a horizontal rule at the nearest root (`$insertNodeToNearestRoot`), and the markdown shortcuts `# `, `- ` and `> `, in the root, a container that declares nothing, one that declares `children: 'block'`, a shadow root, each nested in one of its own kind, and a shadow root held in a named slot of a block decorator; in an unbound editor with `NodeStructureExtension` and in an editor bound with `@lexical/y` (which always enforces structure): 144 cells.

Each cell's expected outcome comes from a model of the rule, checked with predicates on the result rather than another tree's output: where structure is enforced, the command acts inside a shadow root or a class declaring `children: 'block'` (the list is in the container next to the other paragraph, Enter leaves the list for a new paragraph in the container, the pasted paragraphs stay apart in it, the rule is inside it, the shortcut converts in it, and the container count does not change), while a container that declares nothing is one more block; and a list conversion in a box inside a box acts in place (#9570).

On main, the 42 cells where main does not follow the rule yet are `test.fails` naming #9590: every command in a declared container and in a declared container inside one (36), and list conversion in a box inside a box (6).

## Test plan

```
pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/matrix/StructuralCommands.test.ts
pnpm run ci-check
```

### Before

New cells. Without the `test.fails` marks, on main `04e899d`:

```
      Tests  42 failed | 102 passed (144)
```

### After

On main `04e899d`:

```
      Tests  102 passed | 42 expected fail (144)
```

With #9590 (`8a7471f`), every cell follows the rule; the 42 marked cells pass:

```
      Tests  42 failed | 102 passed (144)    (the 42 are "Expect test to fail")
```

```
$ pnpm run ci-check
Found 0 errors
```
zurfyx added a commit that referenced this pull request Oct 30, 2026
…e, slot and edge, and drop the expected failures #9578 fixed

## Description

The structural command cells (`StructuralCommands.test.ts`) now cover the rest of the rule table of #9590:

- Commands: also `$wrapNodes` (wrapping in a quote), the `---` and ```` ``` ```` shortcuts (typed into an empty paragraph; `---` with the horizontal rule shortcut apps add), and the edge rows, Backspace at the start of a container's first block and Delete at the end of its last block.
- Contexts: also the downstream component's undeclared slot (its slot value is a shadow root) and a slot host's declared slot (the pull quote's `quote` slot holding a shadow root container).
- Bind modes: unbound with `NodeStructureExtension`, and bound with `@lexical/y` in each mode the catalog binds (`binding`, `extension`, `extension-then-sync`) and with a full reconcile after the command. A read-only document takes no commands, so it is not a mode here.

14 commands × 10 contexts × 5 modes = 700 cells. The model is the same: structural commands act inside a shadow root or a class declaring `children: 'block'`, and a container that declares nothing is one more block; only a shadow root is an editing edge, so Backspace and Delete cross the edges of every other container (on main and with #9590). On main the 135 cells where main does not follow the rule yet are `test.fails` naming #9590: every structural command in a declared container and in a declared container inside one (120), and list conversion in a box inside a box (15). Every cell also asserts that the editor reported no error.

#9578 merged, so the 4 ownership scan cells marked for it (a token or segmented node written right before another client's, all three writes undone) pass on main; they are plain tests again.

## Test plan

```
pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/matrix
pnpm run ci-check
```

### Before

Without the `test.fails` marks, on main `c514ea7`:

```
 ❯ packages/lexical-y/src/__tests__/unit/matrix/StructuralCommands.test.ts (700 tests | 135 failed)
```

### After

On main `c514ea7`:

```
 ✓ packages/lexical-y/src/__tests__/unit/matrix/StructuralCommands.test.ts (700 tests)
 Test Files  14 passed (14)
      Tests  2964 passed | 144 expected fail (3108)
```

On main with #9590, every structural command cell follows the rule; the 135 marked cells pass:

```
      Tests  135 failed | 565 passed (700)    (the 135 are "Expect test to fail")
```

```
$ pnpm run ci-check
Found 0 errors
```
zurfyx added a commit that referenced this pull request Oct 30, 2026
…tructural edge rows

## Description

Review found that the Backspace and Delete rows of `StructuralCommands.test.ts` counted any result other than the exact blocked shape as joining across the edge, so a Backspace that deleted the paragraph instead of joining it would pass. Each edge row now checks every paragraph of the document: blocked means every paragraph is as it was and the one at the edge is still in the container; joined means the two paragraphs at the edge became one (`beforeabc` for Backspace, `defafter` for Delete) and the others are as they were. Any other result fails with the paragraphs it left.

## Test plan

```
pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/matrix/StructuralCommands.test.ts
pnpm run ci-check
```

### Before

The edge rows passed for a Backspace that deletes the paragraph at the edge (paragraphs `["before", "def", "after"]`).

### After

That result now fails (`paragraphs ["before","def","after"]`). On main `c514ea7`:

```
      Tests  565 passed | 135 expected fail (700)
```

On main with #9590:

```
      Tests  135 failed | 565 passed (700)    (the 135 are "Expect test to fail"; no edge row among them)
```

```
$ pnpm run ci-check
Found 0 errors
```

@meta-code-review meta-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks good to me. Treating a class that declares children: 'block' as a block container only where node structure is enforced keeps every other editor on today's behavior, and the command-by-context matrix in packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts makes each difference from main easy to check. The suggestions below are optional and non-blocking.

Optional suggestions

  1. Keep the range in $setBlocksType when it starts in an empty declared container (packages/lexical-selection/src/range-selection.ts:197-201). With NodeStructureExtension, p("before") / dbox() / p("after") and a range from the empty box to after, a heading conversion gives dbox(h()) / h("after"), but element.selectStart() collapses the selection into the box's new heading. Calling selectStart() only for a collapsed selection, or moving just the anchor point into the new block, would keep what was selected.
  2. Skip the indent copy when a block goes into an empty container (range-selection.ts:199 in $setBlocksType, and :274-275 ahead of the new append at :282-285 in $wrapNodes). Copying the old block's indent and alignment was right when the container was replaced. On the append path, an indented, centred empty declared box ends up holding heading[indent1,center] or quote[indent1,center], so the indent applies twice, while $insertList adds an unindented item in the same spot.
  3. Pin the fixes every editor gets. $wrapNodes on an empty root (which threw replace: cannot be called on root nodes before this change) or on an empty shadow root has no test, and the two shadow-root $insertList cases (an empty shadow root in a range, a horizontal rule selected in a shadow root) only run with NodeStructureExtension. A few rows with buildEditor(false) in the same unit file, the tier AGENTS.md describes for editor-state behavior, would cover the path most editors take.

The changeset follows CONTRIBUTING.md (patch entries, a [feature] first line and a Verify: paragraph), and serialization.md and y.md describe both documented decisions, including that a box holding only paragraphs is still replaced by one list item.

const element = $createElement();
$afterCreateElement(prevNode, element);
prevNode.append(element);
element.selectStart();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional, non-blocking: when the selection is a range that starts in this empty container (for example from the box's element point to offset 2 of the next paragraph), selectStart() collapses it into the new block, so the other end of the range is lost after $setBlocksType. Calling it only for a collapsed selection, or moving just the anchor point into element, would keep the range.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in be5a936: only the selection points in the empty container move into the new block, so a range keeps its other end. Covered by "$setBlocksType keeps a range that starts in the empty container" (anchor in the new heading, focus still at offset 2 of after).

target.replace(element);
if ($isBlockContainer(target)) {
// An empty container stays: the new block goes in it.
target.append(element);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional, non-blocking: element copied the container's indent and format a few lines up (setFormat/setIndent from target), which was right when it replaced the container. Appended inside it, an indented container now holds an indented block, so the indent applies twice. $setBlocksType does the same through $afterCreateElement(prevNode, element) (line 199), while $insertList adds an unindented item; skipping the copy on this path would match $insertList.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in be5a936: on the append path neither $wrapNodes nor $setBlocksType copies the container's indent and format ($setBlocksType skips $afterCreateElement there, since nothing is replaced), matching $insertList. Covered by "... does not take the container's indent and format" for both. The fixes that reach editors without the extension are now pinned with and without it in "fixes every editor gets" ($wrapNodes in an empty root, which threw on main, and in an empty shadow root; the two shadow-root $insertList cases).

…ip the container's indent when a new block goes into an empty declared container

## Description

From the Meta code-review bot's second review (optional suggestions):

- `$setBlocksType` with a range that starts in an empty declared container moves only the points in that container into the new block, so the range keeps its other end (it collapsed into the new block).
- When `$setBlocksType` or `$wrapNodes` puts the new block into an empty container instead of replacing it, the block no longer copies the container's indent and format (the indent applied twice), matching `$insertList`.
- Tests pin the fixes that also reach editors without `NodeStructureExtension`: `$wrapNodes` in an empty root (it threw `replace: cannot be called on root nodes`) and in an empty shadow root, and `$insertList` over an empty shadow root or with a horizontal rule selected in a shadow root, each with and without the extension.

## Test plan

### Before

```
$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts   # range-selection.ts at 8a7471f
     × $setBlocksType does not take the container's indent and format
     × $wrapNodes does not take the container's indent and format
     × $setBlocksType keeps a range that starts in the empty container
      Tests  3 failed | 393 passed (396)

$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts -t "fixes every editor gets"   # main's sources
Error: replace: cannot be called on root nodes
      Tests  8 failed | 388 skipped (396)
```

### After

```
$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts packages/lexical-selection
      Tests  749 passed (749)
$ pnpm run ci-check
Found 0 errors
```
…alCommands cells that waited for this change plain tests

## Description

Merges main (8e89481), which brought #9588's StructuralCommands matrix and #9569's y.md Moves wording. The matrix marked 135 cells `test.fails` until this change (declared and declared-in-declared containers for every structural command and mode, and list conversion in a box inside a box); with the rule they pass, so they are plain tests now and the model only describes the rule. The y.md Moves conflict keeps #9569's table cell merge and this change's declared containers and #9570 fallback.

## Test plan

### Before

On main the 135 cells were `test.fails`.

### After

```
$ pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/matrix/StructuralCommands.test.ts
      Tests  700 passed (700)
$ pnpm exec vitest run --project unit packages/lexical/src packages/lexical-extension packages/lexical-list packages/lexical-selection packages/lexical-mdast packages/lexical-markdown packages/lexical-utils
      Tests  5137 passed | 4 skipped (5141)
$ pnpm exec vitest run --project unit packages/lexical-y
      Tests  11150 passed | 71 expected fail | 2 skipped (11223)
$ pnpm run ci-check
Found 0 errors
```

@meta-code-review meta-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks good to me. Treating a class that declares children: 'block' as a block container only where node structure is enforced keeps editors that do not opt in on today's behavior, apart from the three fixes, which replace a throw or a lost shadow root with an in-place result. The command-by-context cases in packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts make each difference from main easy to check, and the @lexical/y cases assert the converged document on both peers. The suggestion below is optional and non-blocking.

Optional

  1. Name @lexical/extension in the changeset (.changeset/structure-block-containers.md:2-7). packages/lexical-extension/src/NodeStructureExtension.ts gains a JSDoc paragraph that ships in the package, and the Changesets workflow reports that file as changed without a changeset for @lexical/extension. CONTRIBUTING.md asks the frontmatter to list each affected package, so adding '@lexical/extension': patch clears the warning; since only JSDoc changed there, leaving it is also reasonable.

The changeset otherwise follows CONTRIBUTING.md ([feature], patch bumps and a Verify: paragraph), and serialization.md and y.md describe both documented decisions, including that a box which declares nothing and holds only paragraphs is still replaced by one list item.

'@lexical/markdown': patch
'@lexical/mdast': patch
'@lexical/selection': patch
'@lexical/utils': patch

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional, non-blocking: the Changesets workflow reports packages/lexical-extension/src/NodeStructureExtension.ts as changed without a changeset for @lexical/extension (its new JSDoc paragraph ships in the package). CONTRIBUTING.md asks the frontmatter to list each affected package, so adding '@lexical/extension': patch here clears the warning; leaving it is also reasonable since only JSDoc changed there.

@zurfyx zurfyx Oct 30, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in f31df5d: '@lexical/extension': patch is in the frontmatter.

…iners changeset

## Description

`NodeStructureExtension`'s JSDoc, which ships in `@lexical/extension`, now describes block containers, so the changeset lists that package too (the Changesets workflow reported it as changed without one).

## Test plan

### Before

The Changesets workflow warned that `packages/lexical-extension/src/NodeStructureExtension.ts` changed without a changeset for `@lexical/extension`.

### After

```
$ pnpm run check-changesets
Changeset check passed: 42 pending changeset(s) valid.
```

@meta-code-review meta-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the thorough test matrix and the real before/after output. The declared-container rule reads well, and the shadow-root and #9570 fixes are clear improvements. One regression needs a fix before this lands.

$insertList splits a paragraph that holds the character limit's OverflowNode (packages/lexical-list/src/formatList.ts:210-218)

Where node structure is enforced (NodeStructureExtension, registerNodeStructure, or any @lexical/y binding), $isListItemContent decides with node.isInline(), which is false for OverflowNode. The normalization treats OverflowNode as inline content, and packages/lexical-website/docs/serialization/serialization.md says it "stays in its paragraph although its isInline() is false". Because of that mismatch, a paragraph (or heading, or quote) holding the overflow is taken for a box that holds a block a list item cannot hold: $listTarget converts the OverflowNode itself, and the normalization then lifts the new list out of the paragraph. With the caret in the overflowed text and NodeStructureExtension on:

Document main this PR
p("abc" overflow("def")) list(li("abc" overflow("def"))) p("abc") / list(li("def"))
p("abc") / p(overflow("ghi")) p("abc") / list(li(overflow("ghi"))) p("abc") / list(li("ghi"))

That contradicts the description's and the changeset's statement that classes declaring nothing keep their behavior, and the backwards-compatibility rule in AGENTS.md. Counting what the normalization counts as inline fixes it: for example, also accept $isElementNode(node) && node.getType() === 'overflow' in $isListItemContent, or, more robustly, export an internal predicate from lexical that reuses the normalization's isInlineChild. With that clause both rows match main, and the existing BlockContainers.test.ts cases still pass. Please add a case for the first row; no current case puts an OverflowNode in a paragraph.

Design choices

Decisions 1 and 4 in the description (the declaration counts only where structure is enforced, @lexical/y included, and the fallback keeps box(h p) while box(p p) is still replaced by one list item) are documented and deliberate. They are a maintainer's call rather than a blocker here.

Comment thread packages/lexical-list/src/formatList.ts Outdated
$isLineBreakNode(node) ||
$isListNode(node) ||
($isParagraphNode(node) && !node.isShadowRoot()) ||
(($isElementNode(node) || $isDecoratorNode(node)) && node.isInline())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

OverflowNode.isInline() is false, but the node-structure normalization treats it as inline content (isInlineChild and allows in packages/lexical/src/LexicalStructure.ts; serialization.md says it "stays in its paragraph"). Here that makes a paragraph holding the character limit's overflow count as a box with a block a list item can't hold, so $listTarget converts the OverflowNode itself and the paragraph is split: with NodeStructureExtension, p("abc" overflow("def")) with the caret in def becomes p("abc") / list(li("def")) instead of list(li("abc" overflow("def"))). Also accepting $isElementNode(node) && node.getType() === 'overflow' here (or an internal predicate from lexical that reuses isInlineChild) restores the main result, and the existing cases still pass.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in edd6967 (head now 0caffb6, with main merged): $isListItemContent uses the normalization's own notion of inline content, exported from lexical as INTERNAL_isInlineContent (it calls isInlineChild, so the OverflowNode counts as inline), and the block that becomes a list in place is never inline content. Both rows match main again, and so does a paragraph with an overflow inside a box that holds a quote (that paragraph becomes the list, inside the box). New cases: "$insertList with the caret in an OverflowNode in a paragraph", "... alone in a paragraph after another" (with and without the extension) and "... in a box that holds a quote".

@zurfyx
zurfyx marked this pull request as draft October 30, 2026 20:46
…er limit's OverflowNode as inline content in $insertList's container check

## Description

From the Meta code-review bot: where node structure is enforced, `$insertList` decided whether a list item can hold a box's children with `isInline()`, which is false for the character limit's `OverflowNode`, although the normalization keeps it in its paragraph as inline content. A paragraph holding an overflow was taken for a box holding a block, so the `OverflowNode` itself became the list and the paragraph was split (`p("abc" overflow("def"))` became `p("abc") / list(li("def"))`).

The check now uses the normalization's own notion of inline content, exported from `lexical` as `INTERNAL_isInlineContent` (internal, not public API), and the block that becomes a list in place is never inline content. Both cases match main again.

## Test plan

### Before

```
$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts -t "OverflowNode"
Expected: "list[bullet](li("abc" overflow("def")))"
Received: "p("abc") / list[bullet](li("def"))"
Expected: "p("abc") / list[bullet](li(overflow("ghi")))"
Received: "p("abc") / list[bullet](li("ghi"))"
Expected: "box(quote("q") list[bullet](li("abc" overflow("def"))))"
Received: "box(quote("q") p("abc") list[bullet](li("def")))"
      Tests  3 failed | 396 skipped (399)
```

### After

```
$ pnpm exec vitest run --project unit packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts -t "OverflowNode"
      Tests  3 passed | 396 skipped (399)
```
## Description

Merges main (be5afea). The y.md Limits conflict keeps this change's Moves wording and main's new "Text nodes made again with other text" entry.

## Test plan

### Before

The pull request could not be merged (conflict in y.md).

### After

```
$ pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/matrix/StructuralCommands.test.ts packages/lexical-extension/src/__tests__/unit/BlockContainers.test.ts packages/lexical-y/src/__tests__/unit/BlockContainers.test.ts
      Tests  1107 passed (1107)
$ pnpm exec vitest run --project unit packages/lexical/src packages/lexical-extension packages/lexical-list packages/lexical-selection packages/lexical-mdast packages/lexical-markdown packages/lexical-utils packages/lexical-overflow
      Tests  5145 passed | 4 skipped (5149)
$ pnpm exec vitest run --project unit packages/lexical-y
      Tests  11644 passed | 69 expected fail | 2 skipped (11715)
$ pnpm run ci-check
Found 0 errors
```
zurfyx added a commit that referenced this pull request Oct 30, 2026
… and skip only the cells that cannot apply

## Description

Review found that the "caret inside it" cells of the inline content family returned early, without running the command, for 64 cells that should have run: the caret was placed in a text node that held neither sentinel, but normalization merges plain text (`text/normal`) and the text around a line break into the sentinels' nodes, so no such node was found. The caret is now placed by offset, one character into the inline content, in the leaves as they are after normalization, and a cell where it cannot be placed fails instead of passing. The cells that cannot apply, the caret inside an inline decorator (which has no text node; 128 cells), are `test.skip` with the reason in their names. The whole-paragraph selection now runs from the paragraph's first text node to its last.

## Test plan

```
pnpm exec vitest run --project unit packages/lexical-y/src/__tests__/unit/matrix/StructuralCommands.test.ts
pnpm run ci-check
```

### Before

```
      Tests  2736 passed | 24 expected fail (2760)    (192 "caret inside" cells returned early)
```

### After

On main `be5afea`, the 64 cells that used to return early run and pass:

```
      Tests  2608 passed | 24 expected fail | 128 skipped (2760)
```

On #9590 at `f31df5d`, the 18 overflow cells of `$insertList` still fail; at `0caffb6`, they pass.

```
$ pnpm run ci-check
Found 0 errors
```

@meta-code-review meta-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks good to me. Counting children: 'block' only where node structure is enforced keeps editors that don't opt in on today's behavior, the fixes that reach every editor ($insertList around shadow roots, $wrapNodes on an empty root or shadow root) are pinned with and without NodeStructureExtension, and the OverflowNode case from the previous round is fixed and covered in BlockContainers.test.ts.

Two optional, non-blocking suggestions:

  1. $setBlocksType in an empty declared container depends on the selection's direction (packages/lexical-selection/src/range-selection.ts:200). The new branch checks prevNode.is(anchorBlock), and getStartEndPoints() puts the anchor first in either direction, so with structure enforced a forward range from an empty declared box to after gives dbox(h()) / h("after"), while the same range made backward gives dbox() / h("after"). The loop just below already moves whichever selection point sits in the container, so checking both selection.anchor and selection.focus against prevNode would treat both directions alike, and a backward case next to "$setBlocksType keeps a range that starts in the empty container" would pin it.
  2. The $isBlockContainer JSDoc (packages/lexical/src/LexicalStructure.ts:1857) says that in an empty container $setBlocksType puts the new block in it. That holds for declared containers only: with the caret in an empty root or shadow root, $setBlocksType still does nothing, as on main. Naming declared containers in that sentence would match the code, serialization.md and the changeset.

// container stays, so its indent and format are not copied, and the
// selection points in it move into the new block (a range keeps its
// other end).
if (prevNode.is(anchorBlock) && prevNode.isEmpty()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional: this fills the empty container only when the selection's anchor is in it. getStartEndPoints() returns the anchor first in either direction, so with structure enforced a backward range whose focus is in an empty declared box leaves it empty (dbox() / h("after")), while the forward one gives dbox(h()) / h("after"). Checking whether either selection.anchor or selection.focus sits in prevNode (the loop below already moves both) would treat both directions alike.

@zurfyx zurfyx Oct 30, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

#9590 was merged at 0caffb6 before this landed, so the fix is in follow-up #9616: the empty declared container is filled when either selection point is in it, and those points move into the new block (also on the active selection, which a replacement earlier in the same call can make anew). Pinned by "$setBlocksType keeps a backward range that ends in the empty container" next to the forward case.

* `$insertNodeToNearestRoot`, `$insertNodeToNearestRootAtCaret` unless
* given `rootMode: 'root'`, the markdown shortcuts) stop at a container:
* they act on the blocks inside it and do not replace or split the container
* itself; in an empty one, `$setBlocksType` puts the new block in it. Unlike

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional: $setBlocksType fills only an empty declared container; with the caret in an empty root or shadow root it still does nothing, as on main. Saying "in an empty declared container" here would match the code and serialization.md.

@zurfyx zurfyx Oct 30, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

#9590 was merged at 0caffb6 before this landed, so the JSDoc fix ("in an empty declared container") is in follow-up #9616.

@zurfyx
zurfyx marked this pull request as ready for review October 30, 2026 21:22
@zurfyx
zurfyx added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit 92e1c6a Oct 30, 2026
61 checks passed
zurfyx added a commit that referenced this pull request Oct 30, 2026
main now has #9590, so its StructuralCommands cells are plain tests; the
inline content family keeps its #9612 marks.

This branch was successfully deployed

2 active deployments
Preview – lexical — 0caffb68 Deployed Oct 30, 2026 by vercel[bot]
Preview – lexical-playground — 0caffb68 Deployed Oct 30, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: [lexical-list] $insertList on a paragraph inside a nested container drops the outer container and makes no list when NodeStructureExtension runs

1 participant