Skip to content

Commit b0ed1bf

Browse files
committed
error boundary class
1 parent faf1437 commit b0ed1bf

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/ErrorBoundary.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component, ErrorInfo, ReactNode } from "react";
22

33
interface ErrorBoundaryProps {
4+
element_class: string;
45
children: ReactNode;
56
}
67

@@ -10,8 +11,10 @@ interface ErrorBoundaryState {
1011
}
1112

1213
class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
14+
element_class: string;
1315
constructor(props: ErrorBoundaryProps) {
1416
super(props);
17+
this.element_class = props.element_class;
1518
this.state = { hasError: false, error: null };
1619
}
1720

@@ -20,15 +23,16 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
2023
}
2124

2225
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
23-
console.error("Error caught by ErrorBoundary:", error, errorInfo);
26+
console.error("Element render error:", error, errorInfo);
2427
}
2528

2629
render() {
2730
if (this.state.hasError) {
2831
return (
29-
<div style={{ color: "red" }}>
30-
<h2>Something went wrong.</h2>
32+
<div style={{ color: "red", backgroundColor: "black", padding: 2 }}>
33+
<h2>Element {this.element_class} render error</h2>
3134
<p>{this.state.error?.message}</p>
35+
<p>Open JS Console for details</p>
3236
</div>
3337
);
3438
}

src/elements.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class ElementPool {
116116
kind: kind,
117117
params: JSON.parse(JSON.stringify(el_class?.defaults)),
118118
position: pos || { x: 0, y: 0 },
119-
zindex: zindex === undefined ? 10 : zindex,
119+
zindex: zindex === undefined ? 10 : zindex
120120
};
121121
this.items.push(el);
122122
return el;
@@ -184,7 +184,7 @@ export class ElementPool {
184184
kind: el.kind,
185185
params: JSON.parse(JSON.stringify(el.params)),
186186
position: JSON.parse(JSON.stringify(el.position)),
187-
zindex: el.zindex,
187+
zindex: el.zindex
188188
};
189189
});
190190
}
@@ -211,7 +211,7 @@ export const DisplayElements = ({
211211
onActionFail,
212212
cur_offset,
213213
viewport_scrolled,
214-
forceUpdate,
214+
forceUpdate
215215
}: {
216216
element_pool: ElementPool;
217217
onMouseDown?: (e: any, element: DElement) => void;
@@ -274,7 +274,7 @@ export const DisplayElements = ({
274274
const Viewer = element_class?.Viewer || DefaultViewer;
275275
let el_view = (
276276
<>
277-
<ErrorBoundary>
277+
<ErrorBoundary element_class={el.kind}>
278278
<Viewer
279279
kind={el.kind}
280280
dragged={dragged || viewport_scrolled}
@@ -320,7 +320,7 @@ export const DisplayElements = ({
320320
style={{
321321
left: el.position.x - cur_offset.x - (selected ? 2 : 0),
322322
top: el.position.y - cur_offset.y - (selected ? 2 : 0),
323-
zIndex: el.zindex,
323+
zIndex: el.zindex
324324
}}
325325
{...doubleTapOpenSideBar}
326326
>

0 commit comments

Comments
 (0)