Skip to content

Commit

Permalink
Fix ListItemNode serialization throws (#7116)
Browse files Browse the repository at this point in the history
  • Loading branch information
zurfyx authored Jan 30, 2025
1 parent a62a1a6 commit 03be169
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/lexical-list/src/LexicalListItemNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export class ListItemNode extends ElementNode {
getIndent(): number {
// If we don't have a parent, we are likely serializing
const parent = this.getParent();
if (parent === null) {
if (parent === null || !this.isAttached()) {
return this.getLatest().__indent;
}
// ListItemNode should always have a ListNode for a parent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {

import {
$createListItemNode,
$createListNode,
$isListItemNode,
ListItemNode,
ListNode,
Expand Down Expand Up @@ -1361,5 +1362,24 @@ describe('LexicalListItemNode tests', () => {
});
});
});

test('Can serialize a node that is not attached', async () => {
const {editor} = testEnv;
await editor.update(() => {
const listItemNode = $createListItemNode();
const listNode = $createListNode();
listNode.append(listItemNode);
expect(listItemNode.exportJSON()).toEqual({
checked: undefined,
children: [],
direction: null,
format: '',
indent: 0,
type: 'listitem',
value: 1,
version: 1,
});
});
});
});
});

0 comments on commit 03be169

Please sign in to comment.