From 9ccd7c9598ba0b29af9f3d1ef2f7c48d0c98fa33 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Wed, 15 Jul 2020 12:14:53 +0300 Subject: [PATCH] Add error boundary --- assets/js/dashboard/error-boundary.js | 26 ++++++++++++++++++++++++++ assets/js/dashboard/mount.js | 9 ++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 assets/js/dashboard/error-boundary.js diff --git a/assets/js/dashboard/error-boundary.js b/assets/js/dashboard/error-boundary.js new file mode 100644 index 000000000..e10fdccc5 --- /dev/null +++ b/assets/js/dashboard/error-boundary.js @@ -0,0 +1,26 @@ +import React from 'react'; +import RocketIcon from './stats/modals/rocket-icon' + +export default class ErrorBoundary extends React.Component { + constructor(props) { + super(props); + this.state = {error: null} + } + + static getDerivedStateFromError(error) { + return {error: error} + } + + render() { + if (this.state.error) { + return ( +
+ +
Oops! Something went wrong
+
{this.state.error.name + ': ' + this.state.error.message}
+
+ ) + } + return this.props.children; + } +} diff --git a/assets/js/dashboard/mount.js b/assets/js/dashboard/mount.js index b62775355..5799b4e18 100644 --- a/assets/js/dashboard/mount.js +++ b/assets/js/dashboard/mount.js @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom'; import 'url-search-params-polyfill'; import Router from './router' +import ErrorBoundary from './error-boundary' const container = document.getElementById('stats-react-container') @@ -13,5 +14,11 @@ if (container) { hasGoals: container.dataset.hasGoals === 'true' } - ReactDOM.render(, container); + const app = ( + + + + ) + + ReactDOM.render(app, container); }