diff --git a/src/renderer/ErrorBoundary.jsx b/src/renderer/ErrorBoundary.jsx new file mode 100644 index 000000000..a9191cd75 --- /dev/null +++ b/src/renderer/ErrorBoundary.jsx @@ -0,0 +1,29 @@ +/* eslint-disable */ +import React from "react"; + +class ErrorBoundary extends React.Component { + constructor(props) { + super(props); + this.state = { hasError: true, errorMessage: "" }; + } + + static getDerivedStateFromError(error) { + return { hasError: true, errorMessage: error.message }; + } + + render() { + if (this.state.hasError) { + return ( +
+

Uh oh!

+

This wasn't supposed to happen. If you continue to see this message, please reach out to support.

+

{this.state.errorMessage}

+
+ ); + } + + return this.props.children; + } +} + +export default ErrorBoundary; diff --git a/src/renderer/index.tsx b/src/renderer/index.tsx index a3c09cacc..8297b7a44 100644 --- a/src/renderer/index.tsx +++ b/src/renderer/index.tsx @@ -24,16 +24,19 @@ import Error from "./Error"; import "bootstrap-css-only/css/bootstrap.min.css"; import "@appigram/react-rangeslider/lib/index.css"; import i18n from "./i18n"; +import ErrorBoundary from "./ErrorBoundary"; const container = document.getElementById("root"); const root = createRoot(container); try { root.render( - - - - - , + + + + + + + , ); } catch (e) { root.render();