Skip to content

Commit

Permalink
create a new object in setState
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanJablo committed Jan 31, 2025
1 parent c663540 commit 113a4f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/lexical/src/LexicalNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class LexicalNode {

setState<T extends StateKey>(k: T, v: T['value']) {
const self = this.getWritable();
(self.__state as State)[k.key] = v;
self.__state = {...self.__state, [k.key]: v};
}

// Flow doesn't support abstract classes unfortunately, so we can't _force_
Expand Down Expand Up @@ -333,6 +333,7 @@ export class LexicalNode {
this.__parent = prevNode.__parent;
this.__next = prevNode.__next;
this.__prev = prevNode.__prev;
this.__state = prevNode.__state || {};
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
9 changes: 4 additions & 5 deletions packages/lexical/src/__tests__/unit/LexicalNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1618,11 +1618,10 @@ describe('LexicalNode state', () => {
type _Test = Expect<
Equal<
typeof paragraphObject,
| {
readonly bar: number;
readonly foo: string;
}
| undefined
{
readonly bar: number;
readonly foo: string;
}
>
>;

Expand Down

0 comments on commit 113a4f1

Please sign in to comment.