Skip to content

Commit

Permalink
[lexical] Fix TabNode deserialization regression (#7031)
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum authored Jan 9, 2025
1 parent 33e3677 commit 6add515
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/lexical/src/nodes/LexicalTabNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class TabNode extends TextNode {
}

setMode(type: TextModeType): this {
invariant(type !== 'normal', 'TabNode does not support setMode');
invariant(type === 'normal', 'TabNode does not support setMode');
return this;
}

Expand Down
26 changes: 26 additions & 0 deletions packages/lexical/src/nodes/__tests__/unit/LexicalTabNode.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
$insertNodes,
$isElementNode,
$isRangeSelection,
$isTabNode,
$isTextNode,
$setSelection,
KEY_TAB_COMMAND,
Expand Down Expand Up @@ -253,5 +254,30 @@ describe('LexicalTabNode tests', () => {
'<p dir="ltr"><span data-lexical-text="true">\t</span><span data-lexical-text="true">f</span><span data-lexical-text="true">\t</span></p>',
);
});

test('can be serialized and deserialized', async () => {
const {editor} = testEnv;
await editor.update(() => {
$getRoot()
.clear()
.append($createParagraphNode().append($createTabNode()));
const textNodes = $getRoot().getAllTextNodes();
expect(textNodes).toHaveLength(1);
expect($isTabNode(textNodes[0])).toBe(true);
});
const json = editor.getEditorState().toJSON();
await editor.update(() => {
$getRoot().clear().append($createParagraphNode());
});
editor.read(() => {
expect($getRoot().getAllTextNodes()).toHaveLength(0);
});
await editor.setEditorState(editor.parseEditorState(json));
editor.read(() => {
const textNodes = $getRoot().getAllTextNodes();
expect(textNodes).toHaveLength(1);
expect($isTabNode(textNodes[0])).toBe(true);
});
});
});
});

0 comments on commit 6add515

Please sign in to comment.