Skip to content

Commit c20d096

Browse files
authored
Show disappointed elephant if web UI crashes (#10275)
* Do not crash the whole UI when loading an invalid column * Add error boundary component to catch Web UI crashes * Add stack trace on supported browsers * Add component stack info, pre-format everything for github * Make “Reload” a clickable link that calls window.location.reload() * Remove elephant friend from error boundary, make title stand out more * Simplify error boundary to only a graphic
1 parent ff56552 commit c20d096

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import illustration from '../../images/elephant_ui_disappointed.svg';
4+
5+
export default class ErrorBoundary extends React.PureComponent {
6+
7+
static propTypes = {
8+
children: PropTypes.node,
9+
};
10+
11+
state = {
12+
hasError: false,
13+
stackTrace: undefined,
14+
componentStack: undefined,
15+
}
16+
17+
componentDidCatch(error, info) {
18+
this.setState({
19+
hasError: true,
20+
stackTrace: error.stack,
21+
componentStack: info && info.componentStack,
22+
});
23+
}
24+
25+
render() {
26+
const { hasError } = this.state;
27+
28+
if (!hasError) {
29+
return this.props.children;
30+
}
31+
32+
return (
33+
<div>
34+
<img src={illustration} alt='' />
35+
</div>
36+
);
37+
}
38+
39+
}

app/javascript/mastodon/containers/mastodon.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { connectUserStream } from '../actions/streaming';
1313
import { IntlProvider, addLocaleData } from 'react-intl';
1414
import { getLocale } from '../locales';
1515
import initialState from '../initial_state';
16+
import ErrorBoundary from '../components/error_boundary';
1617

1718
const { localeData, messages } = getLocale();
1819
addLocaleData(localeData);
@@ -75,7 +76,9 @@ export default class Mastodon extends React.PureComponent {
7576
return (
7677
<IntlProvider locale={locale} messages={messages}>
7778
<Provider store={store}>
78-
<MastodonMount />
79+
<ErrorBoundary>
80+
<MastodonMount />
81+
</ErrorBoundary>
7982
</Provider>
8083
</IntlProvider>
8184
);

app/javascript/mastodon/features/ui/components/bundle.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class Bundle extends React.PureComponent {
5353
const { fetchComponent, onFetch, onFetchSuccess, onFetchFail, renderDelay } = props || this.props;
5454
const cachedMod = Bundle.cache.get(fetchComponent);
5555

56+
if (fetchComponent === undefined) {
57+
this.setState({ mod: null });
58+
return Promise.resolve();
59+
}
60+
5661
onFetch();
5762

5863
if (cachedMod) {

0 commit comments

Comments
 (0)