Skip to content

Commit

Permalink
fix: remove error boundary
Browse files Browse the repository at this point in the history
Removing the error boundary means that when the component throws
due to the schema changing,
it will try to rerender once the changes have complete.
If they are complete, then we will be able to successfully render.
  • Loading branch information
waynevanson committed Aug 29, 2023
1 parent c272641 commit 2be645a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
8 changes: 4 additions & 4 deletions .vault/.obsidian/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
"type": "split",
"children": [
{
"id": "9eaa83374cb4cf87",
"id": "7bf84358322f263b",
"type": "tabs",
"children": [
{
"id": "76b757e0be450594",
"id": "5915649f90428c68",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "Sample 06.md",
"mode": "source",
"mode": "preview",
"source": true
}
}
Expand Down Expand Up @@ -147,7 +147,7 @@
"command-palette:Open command palette": false
}
},
"active": "76b757e0be450594",
"active": "5915649f90428c68",
"lastOpenFiles": [
"Sample 06.md",
"Sample 05.md",
Expand Down
3 changes: 3 additions & 0 deletions .vault/Sample 06.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ schema:
properties:
name:
type: string
age:
type: number
datasource:
name: Yo bro
data: {}
---

```yaml-data-entry
Expand Down
33 changes: 2 additions & 31 deletions packages/data-entry/src/components/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function Application() {
}, [config.datasource.file.frontmatter, form, frontmatter.datasource]);

return (
<ErrorBoundary>
<>
{frontmatterErrors !== '' && (
<Alert severity="error">{frontmatterErrors}</Alert>
)}
Expand All @@ -107,35 +107,6 @@ export function Application() {
errorsSet(errors ?? []);
}}
/>
</ErrorBoundary>
</>
);
}

class ErrorBoundary extends React.Component<
{ children?: ReactNode },
{ hasError: false } | { hasError: true; error: Error }
> {
constructor(props: { children?: ReactNode }) {
super(props);
this.state = { hasError: false };
}

static getDerivedStateFromError(error: Error) {
return { hasError: true, error };
}

render() {
if (!this.state.hasError) return this.props.children;
console.error(this.state.error);
return (
<div>
<h2>Something went wrong.</h2>
<p>Please see the error that was thrown below for more information.</p>
<pre>
<code>{String(this.state.error)}</code>
<code>{this.state.error?.stack}</code>
</pre>
</div>
);
}
}

0 comments on commit 2be645a

Please sign in to comment.