feat: add error boundary to the app root
This commit is contained in:
parent
f9a68e8b23
commit
6a9745171e
@ -3,18 +3,24 @@ import { ErrorBoundary, FallbackProps } from "react-error-boundary";
|
|||||||
|
|
||||||
function ErrorFallback({ error }: FallbackProps) {
|
function ErrorFallback({ error }: FallbackProps) {
|
||||||
return (
|
return (
|
||||||
<div role="alert">
|
<div role="alert" style={{ padding: 16 }}>
|
||||||
<p>Something went wrong:(</p>
|
<h4>Something went wrong:(</h4>
|
||||||
|
|
||||||
<pre>{error.message}</pre>
|
<pre>{error.message}</pre>
|
||||||
|
|
||||||
|
<details title="Error Stack">
|
||||||
|
<summary>Error Stack</summary>
|
||||||
|
<pre>{error.stack}</pre>
|
||||||
|
</details>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BaseErrorBoundaryProps {
|
interface Props {
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BaseErrorBoundary: React.FC<BaseErrorBoundaryProps> = (props) => {
|
export const BaseErrorBoundary = (props: Props) => {
|
||||||
return (
|
return (
|
||||||
<ErrorBoundary FallbackComponent={ErrorFallback}>
|
<ErrorBoundary FallbackComponent={ErrorFallback}>
|
||||||
{props.children}
|
{props.children}
|
||||||
|
@ -11,6 +11,7 @@ import React from "react";
|
|||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import { RecoilRoot } from "recoil";
|
import { RecoilRoot } from "recoil";
|
||||||
import { BrowserRouter } from "react-router-dom";
|
import { BrowserRouter } from "react-router-dom";
|
||||||
|
import { BaseErrorBoundary } from "./components/base";
|
||||||
import Layout from "./pages/_layout";
|
import Layout from "./pages/_layout";
|
||||||
import "./services/i18n";
|
import "./services/i18n";
|
||||||
|
|
||||||
@ -26,9 +27,11 @@ if (!container) {
|
|||||||
createRoot(container).render(
|
createRoot(container).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<RecoilRoot>
|
<RecoilRoot>
|
||||||
|
<BaseErrorBoundary>
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<Layout />
|
<Layout />
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
|
</BaseErrorBoundary>
|
||||||
</RecoilRoot>
|
</RecoilRoot>
|
||||||
</React.StrictMode>
|
</React.StrictMode>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user