Skip to content

Visualize Your Ideas With Code

fix(2d): better error handling (#524)

Jacobb7475ba5ff35
diff --git a/packages/2d/src/components/Layout.ts b/packages/2d/src/components/Layout.ts
index b9be34fc..3c0fd27a 100644
--- a/packages/2d/src/components/Layout.ts
+++ b/packages/2d/src/components/Layout.ts
@@ -815,9 +815,11 @@ export class Layout extends Node {
public override dispose() {
super.dispose();
- this.sizeLockCounter.context.dispose();
- this.element.remove();
- this.element.innerHTML = '';
+ this.sizeLockCounter?.context.dispose();
+ if (this.element) {
+ this.element.remove();
+ this.element.innerHTML = '';
+ }
this.element = null as unknown as HTMLElement;
this.styles = null as unknown as CSSStyleDeclaration;
}
diff --git a/packages/2d/src/components/Node.ts b/packages/2d/src/components/Node.ts
index 4b0395b6..6a6bb8db 100644
--- a/packages/2d/src/components/Node.ts
+++ b/packages/2d/src/components/Node.ts
@@ -866,7 +866,7 @@ export class Node implements Promisable<Node> {
public dispose() {
this.stateStack = [];
for (const {signal} of this) {
- signal.context.dispose();
+ signal?.context.dispose();
}
}
diff --git a/packages/2d/src/scenes/Scene2D.ts b/packages/2d/src/scenes/Scene2D.ts
index 1ab4596a..1a22984b 100644
--- a/packages/2d/src/scenes/Scene2D.ts
+++ b/packages/2d/src/scenes/Scene2D.ts
@@ -47,7 +47,11 @@ export class Scene2D extends GeneratorScene<View2D> implements Inspectable {
public override reset(previousScene?: Scene): Promise<void> {
for (const key in this.registeredNodes) {
- this.registeredNodes[key].dispose();
+ try {
+ this.registeredNodes[key].dispose();
+ } catch (e: any) {
+ this.logger.error(e);
+ }
}
this.registeredNodes = {};
this.nodeCounters = {};