Skip to content

[lexical] Bug Fix: A named slot's value moved out of its slot no longer makes the reconciler remove the DOM of the element it moved into - #9778

Merged
zurfyx merged 4 commits into
mainfrom
zurfyx/slot-value-moved-out-container
Nov 4, 2026
Merged

zurfyx merged 4 commits into
mainfrom
zurfyx/slot-value-moved-out-container

Conversation

@zurfyx

@zurfyx zurfyx commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Description

When a named slot's value moved, in one update, into an element rendered before its old host (as a child or into a slot of that element; the element can be new, existing, or built anew because its updateDOM returns true), or next to the host in the host's own parent (then that parent lost its DOM; for a top-level host the editor's root element left the page), while its slot was removed, given another value, or its host was removed, the reconciler removed the wrong element. $slotContainerForKey finds a slot's container as the parent of the value's DOM in the previous DOM map; by the time the old host's slot is cleaned up, creating or reconciling the new place has already moved that DOM (the reconciler reuses a moved node's DOM), so its parent is the new place. The cleanup removed the element the value moved into, or that element's new slot container: the editor state was right, but that element's DOM was gone, its DOM-map entry pointed at a detached element, and, when that element's updateDOM returns true, the next update that inserted a node next to it threw NotFoundError: The child can not be found in the parent. Swapping two slot values in one update could also leave one value's DOM outside the editor.

Now, when $createNode moves the DOM of a node that was a slot value in the previous state, it first records the DOM's parent, which is the value's old slot container, for the rest of that reconciliation, and $slotContainerForKey returns the recorded container for that key. The old slot's cleanup removes the old container. Nothing changes when the new place is rendered after the old host (the cleanup already ran with the right container), for slot values that stay, or for editors without slots. Named slots are experimental.

Closes #9758

Changeset

.changeset/slot-value-moved-out-container.md (lexical patch, [fix]).

Test plan

  • packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts (new, 61 tests): the new place before or after the old host; a new, an existing and a rebuilt element; moved in as a child, into a new slot, or replacing a slot's value; the old slot removed, given a new value, or its host removed. Each checks that nothing throws, that every node's element is in the editor's DOM, that the DOM equals a fresh render, that the moved value reports neither destroyed nor created, that a later update inserting next to the new place works, and, where the element is not one built anew, that no removed node stays in the DOM map. Two more tests: a decorator host that placed its slot container outside its own DOM (the container is removed and the element the value moved into keeps its DOM), a decorator slot value moved into an earlier element (that element and the value keep their DOM), two slot values swapped between two slots of one host or between two hosts (each keeps its DOM, the DOM matches a fresh render), a new element rendered before an old host that is removed in the same update (it keeps its DOM), and a slot value moved right before its top-level host (without the fix the editor's root element left the page).

Before

$ ./node_modules/.bin/vitest --run --project unit packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts
AssertionError: expected [ 'paragraph#4', 'text#5', …(3) ] to deeply equal []
AssertionError: expected [ 'paragraph#75', 'text#76' ] to deeply equal []
      Tests  31 failed | 30 passed (61)

After

$ ./node_modules/.bin/vitest --run --project unit packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts
      Tests  61 passed (61)

Every package's unit tests pass with no change from main, also together with #9773. The rich-text end-to-end tests for tables, copy and paste, lists, selection, headings, markdown, mutations and the four slot specs, and the collab-y specs including slot convergence, give the same results as main in Chromium and Firefox. A reconciler differential (random edits checked after every update against a fresh render, the DOM map and mutation events) over 100,000 sessions without slots gives the same results as main, and over 40,000 sessions with named slots finds no failure this change adds; together with #9773 the sessions with named slots show none of this class.

Review

Independent review with gpt-6.1-sol over two rounds (the last clean); both accepted mutants it found are rejected by the tests here.

…er makes the reconciler remove the DOM of the element it moved into

## Description

When a named slot's value moved, in one update, into an element rendered before its old host (as a child or into a slot of that element; the element can be new, existing, or built anew because its `updateDOM` returns true) while its slot was removed, given another value, or its host was removed, the reconciler removed the wrong element. `$slotContainerForKey` finds a slot's container as the parent of the value's DOM in the previous DOM map; by the time the old host's slot is cleaned up, creating or reconciling the new place has already moved that DOM (the reconciler reuses a moved node's DOM), so its parent is the new place. The cleanup removed the element the value moved into, or that element's new slot container: the editor state was right, but that element's DOM was gone, its DOM-map entry pointed at a detached element, and the next update that inserted a node next to it threw `NotFoundError: The child can not be found in the parent.`

Now, when `$createNode` moves the DOM of a node that was a slot value in the previous state, it first records the DOM's parent, which is the value's old slot container, for the rest of that reconciliation, and `$slotContainerForKey` returns the recorded container for that key. The old slot's cleanup removes the old container. Nothing changes when the new place is rendered after the old host (the cleanup already ran with the right container), for slot values that stay, or for editors without slots. Named slots are experimental.

Closes #9758

## Changeset

`.changeset/slot-value-moved-out-container.md` (`lexical` patch, `[fix]`).

## Test plan

- `packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts` (new, 56 tests): the new place before or after the old host; a new, an existing and a rebuilt element; moved in as a child, into a new slot, or replacing a slot's value; the old slot removed, given a new value, or its host removed. Each checks that nothing throws, that every node's element is in the editor's DOM, that the DOM equals a fresh render, that the moved value reports neither `destroyed` nor `created`, that a later update inserting next to the new place works, and, where the element is not one built anew, that no removed node stays in the DOM map. Two more tests: a decorator host that placed its slot container outside its own DOM (the container is removed and the element the value moved into keeps its DOM), and a decorator slot value moved into an earlier element (that element and the value keep their DOM).

### Before

```
$ ./node_modules/.bin/vitest --run --project unit packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts
AssertionError: expected [ 'paragraph#4', 'text#5', …(3) ] to deeply equal []
AssertionError: expected [ 'paragraph#75', 'text#76' ] to deeply equal []
      Tests  26 failed | 30 passed (56)
```

### After

```
$ ./node_modules/.bin/vitest --run --project unit packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts
      Tests  56 passed (56)
```

Every package's unit tests pass with no change from main, also together with #9773. The rich-text end-to-end tests for tables, copy and paste, lists, selection, headings, markdown, mutations and the four slot specs, and the collab-y specs including slot convergence, give the same results as main in Chromium and Firefox. A reconciler differential (random edits checked after every update against a fresh render, the DOM map and mutation events) over 100,000 sessions without slots gives the same results as main, and over 40,000 sessions with named slots finds no failure this change adds; together with #9773 the sessions with named slots show none of this class.

## Review

Independent review with gpt-6.1-sol over two rounds (the last clean); both accepted mutants it found are rejected by the tests here.
@vercel

vercel Bot commented Nov 4, 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 Nov 4, 2026 6:02am UTC
lexical-playground Ready Ready Preview Nov 4, 2026 6:02am 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 Nov 4, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
lexical

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

@lexical/a11y

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

@lexical/clipboard

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

@lexical/code

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

@lexical/code-core

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

@lexical/code-prism

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

@lexical/code-shiki

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

@lexical/compiler

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

@lexical/devtools-core

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

@lexical/dragon

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

@lexical/eslint-plugin

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

@lexical/extension

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

@lexical/fast-check

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

@lexical/file

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

@lexical/hashtag

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

@lexical/headless

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

@lexical/history

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

@lexical/html

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

@lexical/internal

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

@lexical/link

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

@lexical/list

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

@lexical/mark

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

@lexical/markdown

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

@lexical/mdast

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

@lexical/offset

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

@lexical/overflow

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

@lexical/plain-text

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

@lexical/react

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

@lexical/rich-text

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

@lexical/selection

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

@lexical/table

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

@lexical/tailwind

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

@lexical/text

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

@lexical/utils

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

@lexical/y

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

@lexical/yjs

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

commit: 1f7ebbf

@meta-code-review

meta-code-review Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 4, 2026, 6:17 AM UTC

@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, this change looks good. Recording the moved value's old slot container in $createNode and returning it from $slotContainerForKey makes the old slot's cleanup remove that container instead of the element the value moved into, and the new matrix in LexicalSlotValueMovedOut.test.ts tells the old behaviour from the new one by asserting the DOM against a fresh render.

Two optional, non-blocking suggestions:

  1. Pin the slot-swap path as well (packages/lexical/src/LexicalReconciler.ts, the container-reuse branch of $reconcileSlotChildren at lines 632-633). The same record also fixes swapping two values between slots in one update, {s0: V, s1: W} to {s0: W, s1: V} on one host, or between two hosts when the later host renders first; without this change one value's element ends up outside the editor DOM. A swap case in LexicalSlotValueMovedOut.test.ts would keep that from regressing.
  2. Qualify the NotFoundError sentence in the changeset (.changeset/slot-value-moved-out-container.md, lines 7 and 9). Without the fix, a later insert next to a plain element (updateDOM returning false) does not throw; the element just stays out of the DOM. NotFoundError appears only when that element's updateDOM returns true. AGENTS.md asks the Verify: paragraph to say what to test, so either add 'for an element whose updateDOM returns true' or keep only the 'matches a fresh render' check, which already tells old from new.


When a slot's value moved, in one update, into an element rendered before its old host (as a child or into a slot of that element, which can be new, existing, or built anew because its `updateDOM` returns true) while its slot was removed, given another value, or its host was removed, the reconciler had already moved the value's DOM when it cleaned up the old slot, and it removed the value's new parent instead of the old slot container. The element it moved into lost its DOM (the editor state was right, the DOM no longer matched it), and the next update that inserted a node next to that element threw `NotFoundError`. The reconciler now keeps the old slot container of a slot value whose DOM it moves and removes that container. Named slots are experimental.

Verify: in a mounted editor, with an element `R` before an element `A` whose slot `s0` holds `B`, in one update remove the slot and append `B` to `R`; `R`'s DOM stays in the editor and matches a fresh render, and inserting a paragraph before `R` in a later update does not throw.

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: without the fix, inserting a paragraph before a plain R (updateDOM returning false) does not throw; R just stays out of the DOM. NotFoundError only appears when R's updateDOM returns true. Consider qualifying the throw check (and the matching sentence on line 7), or keeping only the 'matches a fresh render' check, which already tells old from new.

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 606bd29: the changeset says the later NotFoundError happened only when that element's updateDOM returns true, and the Verify: paragraph checks the DOM against a fresh render.

'slot gets a new value',
] as const;

describe('a slot value moved out of its slot in one update', () => {

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: the recorded container also fixes swapping two slot values in one update ({s0: V, s1: W} to {s0: W, s1: V} on one host, or between two hosts when the later host renders first), which goes through the container-reuse branch of $reconcileSlotChildren. A swap case here would pin that path.

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 606bd29: three swap tests (two slots of one host; two hosts, both orders of operations). They fail on main and pass here.

… the old behaviour threw

## Description

Adds three tests to `LexicalSlotValueMovedOut.test.ts` for two slot values swapped in one update, between two slots of one host and between two hosts in both orders of operations: each value keeps its DOM inside the editor and the editor's DOM matches a fresh render. The recorded old slot container fixes these too. The changeset now says that the later `NotFoundError` happened only when the element the value moved into has an `updateDOM` that returns true, mentions swaps, and its `Verify:` paragraph checks the DOM against a fresh render. No source change.

## Test plan

### Before

```
$ ./node_modules/.bin/vitest --run --project unit packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts
AssertionError: expected false to be true // Object.is equality
      Tests  29 failed | 30 passed (59)
```

### After

```
$ ./node_modules/.bin/vitest --run --project unit packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts
      Tests  59 passed (59)
```

@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 — this change looks good. Recording the moved value's old slot container in $createNode and returning it from $slotContainerForKey makes the old slot's cleanup remove that container instead of the element the value moved into, and the matrix in LexicalSlotValueMovedOut.test.ts tells the old behaviour from the new one by checking the DOM against a fresh render. The swap tests and the qualified NotFoundError sentence in the changeset address the earlier suggestions.

One optional, non-blocking suggestion:

  • Three "new place first" cases run in the other order (packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts, lines 181-187 and 207-209). For a new element with the host removed, t is inserted directly before a and a is removed, so the root goes from [a, tail] to [t, tail]. $reconcileNodeChildren destroys a before it creates t (LexicalReconciler.ts lines 2104-2117), so the old slot is cleaned up before the value moves, and these three cases pass without the fix. The path is still covered for existing and rebuilt elements. Starting that branch from [x, a, tail] and inserting t before x makes the new element render before the old host; that shape removes t's DOM without the fix and passes with it.

if (target === 'new element') {
t = new Host().append($text('t'));
if (order === 'new place first') {
a.insertBefore(t);

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: for target === 'new element' with leaves === 'host removed', the root goes from [a, tail] to [t, tail], and $reconcileNodeChildren destroys a before it creates t, so these three cases run the old-host-first order and pass without the fix. Starting this branch from [x, a, tail] and inserting t before x would make the new element render before the old host; that shape removes t's DOM without the fix and passes with it.

…is removed in the same update

## Description

Adds a test to `LexicalSlotValueMovedOut.test.ts`: from `[x, A, tail]`, where `A`'s slot holds a value, one update inserts a new element before `x`, moves the value into it and removes `A`. The new element renders before the old host, so without the fix its DOM was removed. (In the matrix's "new element, host removed" cases the old host is destroyed before the new element is created, so those pass on main too.) No source change.

## Test plan

### Before

```
$ ./node_modules/.bin/vitest --run --project unit packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts
     × a new element rendered before the old host that is removed in the same update keeps its DOM
      Tests  30 failed | 30 passed (60)
```

### After

```
$ ./node_modules/.bin/vitest --run --project unit packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts
      Tests  60 passed (60)
```
@zurfyx

zurfyx commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

The optional item from the latest review is done in 87ac333: a test from [x, A, tail] that inserts the new element before x, moves the value into it and removes A. It fails on main and passes here.

@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 — this change looks good. Recording the moved value's old slot container in $createNode and returning it from $slotContainerForKey makes the old slot's cleanup remove that container instead of the element the value moved into, and the new matrix tells the old behaviour from the new one by comparing the DOM with a fresh render. The standalone test for a new element rendered before a removed host covers the earlier suggestion.

A few optional, non-blocking suggestions:

  • Test the unwrap shape (packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts). Moving a slot value into its host's own parent right before the host ($removeSlot(a, 's0'); a.insertBefore(value) in one update) is the most damaging form of this bug: on main the cleanup removes the host's parent, which for a top-level host is the editor's root element, so the whole editor leaves the page. The fix handles it, but every matrix case moves the value into a Host, so one case of that shape would pin it.
  • Three matrix cases still run in the other order (lines 184 and 208). For 'new place first, into a new element …, host removed', t is inserted directly before a and a is removed, so the root goes from [a, tail] to [t, tail], the same shape as the 'old host first' cases, and these three pass on main. Starting that branch from [x, a, tail], as the new standalone test does, would also cover moving the value into the new element's slot. Relatedly, for a new element the 'replaced slot value' case fills an empty slot, because the t that held old in the first update is never attached (lines 154-163).
  • Changeset scope (.changeset/slot-value-moved-out-container.md, line 7). CONTRIBUTING.md asks for the entry to be written for someone who uses Lexical; 'into an element rendered before its old host' does not read as covering the unwrap case, so a clause such as "or next to the host in its own parent, where the editor's root element was removed" would help someone who hit that symptom find it.


const ORDERS = ['new place first', 'old host first'] as const;
const TARGETS = ['new element', 'existing element', 'rebuilt element'] as const;
const INTO = ['child', 'new slot', 'replaced slot value'] as const;

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: every destination here is a Host, so the unwrap shape ($removeSlot(a, 's0'); a.insertBefore(value) in one update) is not covered. On main its cleanup removes the host's parent, which for a top-level host is the editor's root element; this fix handles it, and one case of that shape would pin it.

if (target === 'new element') {
t = new Host().append($text('t'));
if (order === 'new place first') {
a.insertBefore(t);

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: with leaves === 'host removed' this branch goes from [a, tail] to [t, tail], the same shape as the 'old host first' cases, because a is destroyed before t is created; these three cases pass on main. Starting from [x, a, tail] and inserting t before x, as the standalone test at the end of the file does, would make them test the new-place-first order, slot variants included.


[fix] A named slot's value moved out of its slot no longer makes the reconciler remove the DOM of the element it moved into

When a slot's value moved, in one update, into an element rendered before its old host (as a child or into a slot of that element, which can be new, existing, or built anew because its `updateDOM` returns true) while its slot was removed, given another value, or its host was removed, the reconciler had already moved the value's DOM when it cleaned up the old slot, and it removed the value's new parent instead of the old slot container. The element it moved into lost its DOM (the editor state was right, the DOM no longer matched it), and when that element's `updateDOM` returns true, the next update that inserted a node next to it threw `NotFoundError`. Swapping two slot values in one update could also leave one value's DOM outside the editor. The reconciler now keeps the old slot container of a slot value whose DOM it moves and removes that container. Named slots are experimental.

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: 'into an element rendered before its old host' does not read as covering a value unwrapped next to its host in the host's own parent, where the removed 'new parent' was that parent (the editor's root element for a top-level host). A clause naming that case would help users who hit it find this entry.

…ost, and name that symptom in the changeset

## Description

Adds a test to `LexicalSlotValueMovedOut.test.ts`: a top-level host's slot value is moved right before the host in one update. Without the fix the old slot's cleanup removed the host's parent, here the editor's root element, so the whole editor left the page. The changeset now names this shape and its symptom. No source change.

## Test plan

### Before

```
$ ./node_modules/.bin/vitest --run --project unit packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts
      Tests  31 failed | 30 passed (61)
```

### After

```
$ ./node_modules/.bin/vitest --run --project unit packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts
      Tests  61 passed (61)
```
@zurfyx

zurfyx commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

Optional items from the latest review: the unwrap shape is taken in 1f7ebbf (a test where a top-level host's slot value moves right before the host; on main the editor's root element left the page) and the changeset and description now name that symptom. The matrix's three "new element, host removed" cases stay as they are: the standalone test from [x, A, tail] covers that order.

@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. Recording the old slot container in $createNode before the moved value's DOM is reinserted (packages/lexical/src/LexicalReconciler.ts:734-739), and preferring that record in $slotContainerForKey (:591-594), makes the old slot's cleanup remove the right element in every shape I tried: a value moved into an earlier element as a child or into one of its slots, the unwrap right before a top-level host, swaps and rotations across slots and hosts, a host moved in the same update, and restoring the states on either side of the move. The record lives for a single $reconcileRoot call, nothing public changes, and the changeset follows .changeset/README.md, with the Verify: paragraph AGENTS.md asks for on a fix that changes output.

Thanks for adding the unwrap test and naming that symptom in the changeset. Leaving the three "new element, host removed" matrix cases as they are is fine, since the standalone test covers that order.

Optional, non-blocking

  • packages/lexical/src/__tests__/unit/LexicalSlotValueMovedOut.test.ts:156-163: when the target is a new element, the t that gets old in s1 is never attached, and the second update builds a fresh t (:182). So the three "new element as a replaced slot value" cases fill an empty slot, which is what the "new slot" cases already test. Putting old into the new element's s1 inside the second update would make them test a replacement.

t.append($text('t'));
if (into === 'replaced slot value') {
const old = $text('replaced');
$setSlot(t as never, 's1' as never, old);

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 target === 'new element', this t is never attached ($getRoot().clear().append(a, tail) at line 163), and the second update builds a fresh t at line 182, so the three "new element as a replaced slot value" cases fill an empty s1, the same as "new slot". Setting old into the new element's s1 inside the second update would make them test a replacement.

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.

Right: for a new element the old value sits on a host that is never attached, so those three cases fill an empty slot, as the "new slot" cases do. A replacement in an existing or rebuilt element is covered by its "replaced slot value" cases. Left as is, to keep the head that was verified.

@zurfyx
zurfyx marked this pull request as ready for review November 4, 2026 09:51
@zurfyx
zurfyx added this pull request to the merge queue Nov 4, 2026
@zurfyx
zurfyx added this pull request to the merge queue Nov 4, 2026
Merged via the queue into main with commit 0401ed9 Nov 4, 2026
61 checks passed
wozhenbang2004 pushed a commit to wozhenbang2004/lexical that referenced this pull request Nov 4, 2026
…er makes the reconciler remove the DOM of the element it moved into (meta#9778)
@potatowagon potatowagon mentioned this pull request Dec 2, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 1f7ebbff Deployed Nov 4, 2026 by vercel[bot]
Preview – lexical-playground — 1f7ebbff Deployed Nov 4, 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] Moving a named slot's value into a new element in one update removes the new element's DOM

1 participant