From b70303c4370ceed9ea4593478f66800422adcb65 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Thu, 11 Mar 2021 14:13:40 +0100 Subject: [PATCH] Add error boundary to App Catch errors in the component stack that reaches the App component and display an error message for them instead of a black screen. --- packages/web_ui/src/components/App.jsx | 30 +++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/packages/web_ui/src/components/App.jsx b/packages/web_ui/src/components/App.jsx index 2c90130d..255f1aa1 100644 --- a/packages/web_ui/src/components/App.jsx +++ b/packages/web_ui/src/components/App.jsx @@ -5,13 +5,25 @@ import { BrowserRouter } from "react-router-dom"; import { logger } from "@clusterio/lib/logging"; import basename from "../basename"; +import ErrorBoundary from "./ErrorBoundary"; import SiteLayout from "./SiteLayout"; import ControlContext from "./ControlContext"; import PluginsContext from "./PluginsContext"; import LoginForm from "./LoginForm"; -import { Card, Spin } from "antd"; +import { Card, Spin, Typography } from "antd"; +const { Paragraph } = Typography; + + +function ErrorCard(props) { + return
+ +

An unexpected error occured

+ {props.error.stack} +
+
; +} export default function App(props) { let [connected, setConnected] = useState(false); @@ -77,12 +89,14 @@ export default function App(props) { } return ( - - - - {page} - - - + + + + + {page} + + + + ); }