Skip to content

Commit 287aa81

Browse files
committed
fix: memory leak
1 parent 4af3f6e commit 287aa81

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/block.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,16 @@ export class Block {
193193
}
194194
}
195195

196-
addChild(blockSignal: MaybeSignal<Block>, position?: number): void {
197-
const block = getValue(blockSignal);
198-
block.parent = this;
196+
addChild(block: MaybeSignal<Block>, position?: number): void {
197+
const blockValue = getValue(block);
198+
blockValue.parent = this;
199199
this.children ??= [];
200200
if (typeof position === "number") {
201-
this.children.splice(position, 0, blockSignal);
201+
this.children.splice(position, 0, block);
202202
} else {
203-
this.children.push(blockSignal);
203+
this.children.push(block);
204204
}
205-
block.mount();
205+
blockValue.mount();
206206
this.changed = true;
207207
}
208208

@@ -216,12 +216,12 @@ export class Block {
216216
this.changed = true;
217217
}
218218

219-
removeChild(blockSignal: MaybeSignal<Block>): void {
220-
const block = getValue(blockSignal);
221-
block.parent = undefined;
222-
block.unmount();
219+
removeChild(block: MaybeSignal<Block>): void {
220+
const blockValue = getValue(block);
221+
blockValue.parent = undefined;
222+
blockValue.unmount();
223223

224-
const index = this.children?.findIndex((value) => value === block || value === blockSignal);
224+
const index = this.children?.findIndex((value) => value === blockValue || value === block);
225225
if (typeof index !== "number" || index === -1) return;
226226

227227
this.children!.splice(index, 1);

src/style_block.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ export class StyleBlock extends Block {
134134
this.changed = true;
135135
}
136136

137+
static i = 0;
138+
almostTheSame(other: Block): boolean {
139+
if (other instanceof StyleBlock) {
140+
if (this.style !== other.style) return false;
141+
}
142+
143+
return super.almostTheSame(other);
144+
}
145+
137146
forceUpdate(): void {
138147
this.updateLines();
139148
super.forceUpdate();

0 commit comments

Comments
 (0)