Skip to content

Commit 4cb7147

Browse files
committed
Set up error handler around performance tab
1 parent b6ae85c commit 4cb7147

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/app/components/ErrorHandler.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
3+
class ErrorHandler extends React.Component {
4+
constructor(props) {
5+
super(props);
6+
this.state = { errorOccurred: false };
7+
}
8+
9+
componentDidCatch(error, info) {
10+
this.setState({ errorOccurred: true })
11+
console.log('Error occurred in React Component: ', error, info);
12+
}
13+
14+
render() {
15+
return this.state.errorOccurred ? <h1>Something went wrong!</h1> : this.props.children
16+
}
17+
}
18+
19+
export default ErrorHandler;

src/app/components/StateRoute.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { MemoryRouter as Router, Route, NavLink, Switch } from 'react-router-dom
77
import Chart from './Chart';
88
import Tree from './Tree';
99
import PerfView from './PerfView';
10+
import ErrorHandler from './ErrorHandler';
1011

1112
const NO_STATE_MSG = 'No state change detected. Trigger an event to change state';
1213
// eslint-disable-next-line react/prop-types
@@ -30,7 +31,11 @@ const StateRoute = ({ snapshot, hierarchy, snapshots, viewIndex }) => {
3031

3132
const renderPerfView = () => {
3233
if (hierarchy) {
33-
return <PerfView viewIndex={viewIndex} snapshots={snapshots} />;
34+
return (
35+
<ErrorHandler>
36+
<PerfView viewIndex={viewIndex} snapshots={snapshots} />
37+
</ErrorHandler>
38+
);
3439
}
3540
return <div className="noState">{NO_STATE_MSG}</div>;
3641
};

0 commit comments

Comments
 (0)