Skip to content

[lexical] Bug Fix: restore managed line break in wrapped slot hosts - #9066

Merged
etrepum merged 3 commits into
meta:mainfrom
luantaraschi:fix/managed-linebreak-dom-slot
Aug 16, 2026
Merged

etrepum merged 3 commits into
meta:mainfrom
luantaraschi:fix/managed-linebreak-dom-slot

Conversation

@luantaraschi

@luantaraschi luantaraschi commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

An element with named slots can redirect its linked-list children to a separate DOM element through getDOMSlot().withElement(...). When that child area becomes empty, it still needs a managed line break even though the host has content in a named slot.

ElementDOMSlot now owns this decision. Named-slot containers form a contiguous prefix of its managed range, so it only checks the first node after the after boundary, or the element's first child when there is no boundary. A wrapped child area therefore receives the line break, while the default slot keeps the existing slots-only behavior. The reconciler delegates the decision on each relevant render, so adding or removing a slot updates the managed line break without leaving stale cached state.

Closes #9063

Test plan

Before

The wrapped-host regression fails because the redirected content element has no managed line break. The boundary regression also fails because a slot container before the managed range incorrectly suppresses the line break.

After

The wrapped content element receives the managed line break. Removing the named slot from a childless default host restores its line break, and adding the slot again removes it. Slot containers before an after boundary do not affect the managed range.

  • Core unit suite: 56 files, 1,269 tests passed.
  • Browser suite: 51 files, 365 tests passed and 4 skipped across Chromium, Firefox, and WebKit.
  • TypeScript, ESLint, Prettier, git diff --check, and the pre-commit hook passed.

@vercel

vercel Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Aug 13, 2026 7:37pm
lexical-playground Ready Ready Preview Aug 13, 2026 7:37pm

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 Aug 13, 2026

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think the right solution here is to have the default ElementDOMSlot implementation slot-aware

## Description

Move empty managed-line-break normalization from the reconciler into ElementDOMSlot. The slot now suppresses an empty line break only when its own element contains a named-slot container, and it rechecks that state when slots are added or removed.

Closes meta#9063

## Test plan

### Before

node node_modules/vitest/vitest.mjs --project unit --no-watch packages/lexical/src/__tests__/unit/LexicalSlot.test.ts packages/lexical/src/__tests__/unit/LexicalDOMSlot.test.tsx packages/lexical/src/__tests__/unit/LexicalReconciler.test.ts

Test Files  3 passed (3)
Tests  172 passed (172)

### After

node node_modules/vitest/vitest.mjs --project unit --no-watch packages/lexical/src

Test Files  56 passed (56)
Tests  1268 passed (1268)

VITEST_BROWSER=chromium,firefox,webkit node node_modules/vitest/vitest.mjs --project browser --no-watch packages/lexical/src/__tests__/browser

Test Files  30 passed (30)
Tests  263 passed | 4 skipped (267)

TypeScript, ESLint, Prettier, git diff --check, and the pre-commit hook also pass.
@luantaraschi

Copy link
Copy Markdown
Contributor Author

Thanks, that direction makes sense. I moved the named-slot handling into ElementDOMSlot. It now decides whether an empty managed line break is needed from the slot containers in its own element, while the reconciler only reports the linked-list last-child state.

I also added coverage for removing and adding a slot so the cached state cannot become stale. The full core unit suite passed with 1,268 tests. The browser suite passed with 263 tests across Chromium, Firefox, and WebKit, with 4 existing skips. TypeScript, ESLint, Prettier, git diff --check, and the pre-commit hook also passed.

Comment thread packages/lexical/src/LexicalDOMSlot.ts Resolved
## Description

Named-slot containers form a contiguous prefix of an ElementDOMSlot's
managed range. Check only the first node in that range when deciding whether
an empty managed line break is needed. This avoids scanning every child and
does not count slot containers outside an `after` boundary.

Closes meta#9063

## Test plan

### Before

```text
FAIL ElementDOMSlot class > setManagedLineBreak ignores slot containers before the managed range
AssertionError: expected null not to be null
```

### After

```text
Test Files  56 passed (56)
Tests       1269 passed (1269)

Test Files  51 passed (51)
Tests       365 passed | 4 skipped (369)
```

The browser suite ran in Chromium, Firefox, and WebKit. TypeScript, ESLint,
Prettier, and `git diff --check` also passed.
@etrepum
etrepum added this pull request to the merge queue Aug 16, 2026
Merged via the queue into meta:main with commit c3d301c Aug 16, 2026
56 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 9645085c Deployed Aug 13, 2026 by vercel[bot]
Preview – lexical-playground — 9645085c Deployed Aug 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Reconciler does not insert a managed line break into ElementDOMSlot

2 participants