Skip to content

Commit

Permalink
[lexical-mark] Bug Fix: Stop MarkNode __ids array deep copy in clone (#…
Browse files Browse the repository at this point in the history
…6810)

Co-authored-by: Ebad Salehi <[email protected]>
  • Loading branch information
ebads67 and Ebad Salehi authored Nov 8, 2024
1 parent 29611d2 commit fd4aca7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/lexical-mark/src/MarkNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export type SerializedMarkNode = Spread<
/** @noInheritDoc */
export class MarkNode extends ElementNode {
/** @internal */
__ids: Array<string>;
__ids: readonly string[];

static getType(): string {
return 'mark';
}

static clone(node: MarkNode): MarkNode {
return new MarkNode(Array.from(node.__ids), node.__key);
return new MarkNode(node.__ids, node.__key);
}

static importDOM(): null {
Expand All @@ -57,13 +57,13 @@ export class MarkNode extends ElementNode {
exportJSON(): SerializedMarkNode {
return {
...super.exportJSON(),
ids: this.getIDs(),
ids: Array.from(this.getIDs()),
type: 'mark',
version: 1,
};
}

constructor(ids: Array<string>, key?: NodeKey) {
constructor(ids: readonly string[], key?: NodeKey) {
super(key);
this.__ids = ids || [];
}
Expand Down Expand Up @@ -112,13 +112,13 @@ export class MarkNode extends ElementNode {

getIDs(): Array<string> {
const self = this.getLatest();
return $isMarkNode(self) ? self.__ids : [];
return $isMarkNode(self) ? Array.from(self.__ids) : [];
}

addID(id: string): void {
const self = this.getWritable();
if ($isMarkNode(self)) {
const ids = self.__ids;
const ids = Array.from(self.__ids);
self.__ids = ids;
for (let i = 0; i < ids.length; i++) {
// If we already have it, don't add again
Expand All @@ -133,7 +133,7 @@ export class MarkNode extends ElementNode {
deleteID(id: string): void {
const self = this.getWritable();
if ($isMarkNode(self)) {
const ids = self.__ids;
const ids = Array.from(self.__ids);
self.__ids = ids;
for (let i = 0; i < ids.length; i++) {
if (id === ids[i]) {
Expand Down Expand Up @@ -197,7 +197,7 @@ export class MarkNode extends ElementNode {
}
}

export function $createMarkNode(ids: Array<string>): MarkNode {
export function $createMarkNode(ids: readonly string[]): MarkNode {
return $applyNodeReplacement(new MarkNode(ids));
}

Expand Down

0 comments on commit fd4aca7

Please sign in to comment.