Skip to content

Commit c2ae249

Browse files
committed
[lexical] Test: Drop unnecessary document.body round-trip in #8563 repro
A detached root element is enough to drive DOM reconciliation for this repro (the crash is in node-map lookups, not layout), so set it inline and let the `using` editor's dispose call setRootElement(null). Removes the test extension and document.body bookkeeping. https://claude.ai/code/session_01EAeZ6geVH74SpUrRhY6Z8h
1 parent 066f273 commit c2ae249

1 file changed

Lines changed: 6 additions & 18 deletions

File tree

packages/lexical/src/__tests__/unit/Issue8563Repro.test.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,11 @@
66
*
77
*/
88

9-
import {buildEditorFromExtensions, defineExtension} from '@lexical/extension';
9+
import {buildEditorFromExtensions} from '@lexical/extension';
1010
import {RichTextExtension} from '@lexical/rich-text';
1111
import {$createParagraphNode, $createTextNode, $getRoot} from 'lexical';
1212
import {describe, expect, test} from 'vitest';
1313

14-
// Attaches a root element so DOM reconciliation runs, and returns a dispose
15-
// that detaches it. `buildEditorFromExtensions` disposal calls both this
16-
// cleanup and `editor.setRootElement(null)`, so a `using` editor tears the
17-
// whole thing down at end of scope.
18-
const TestRootElementExtension = defineExtension({
19-
name: 'issue-8563-root',
20-
register(editor) {
21-
const root = document.createElement('div');
22-
document.body.appendChild(root);
23-
editor.setRootElement(root);
24-
return () => {
25-
document.body.removeChild(root);
26-
};
27-
},
28-
});
29-
3014
// Regression test for https://github.com/facebook/lexical/issues/8563
3115
//
3216
// Undo applies the previous editor state via `setEditorState`, which runs a
@@ -43,12 +27,16 @@ describe('Issue #8563: full reconcile with same-size child key swap', () => {
4327
test('undo (setEditorState) does not crash when a child is replaced by a different-key child of equal count', () => {
4428
const errors: Error[] = [];
4529
using editor = buildEditorFromExtensions({
46-
dependencies: [RichTextExtension, TestRootElementExtension],
30+
dependencies: [RichTextExtension],
4731
name: 'issue-8563-repro',
4832
onError: e => {
4933
errors.push(e);
5034
},
5135
});
36+
// A root element makes DOM reconciliation run; the crash is in node-map
37+
// lookups so the element does not need to be attached to the document.
38+
// `using` disposal calls setRootElement(null).
39+
editor.setRootElement(document.createElement('div'));
5240

5341
// State A: enough children to engage the fast path (>= 4).
5442
editor.update(

0 commit comments

Comments
 (0)