Skip to content

Commit f3337aa

Browse files
author
Brian Vaughn
authored
DevTools error boundary: Search for pre-existing GH issues (#21279)
1 parent 9eddfbf commit f3337aa

20 files changed

+764
-209
lines changed

packages/react-devtools-shared/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"dependencies": {
1010
"@babel/runtime": "^7.11.2",
11+
"@octokit/rest": "^18.5.2",
1112
"@reach/menu-button": "^0.1.17",
1213
"@reach/tooltip": "^0.2.2",
1314
"clipboard-js": "^0.3.6",

packages/react-devtools-shared/src/config/DevToolsFeatureFlags.default.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
************************************************************************/
1515

1616
export const enableProfilerChangedHookIndices = false;
17+
export const isInternalFacebookBuild = false;

packages/react-devtools-shared/src/config/DevToolsFeatureFlags.extension-fb.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
************************************************************************/
1515

1616
export const enableProfilerChangedHookIndices = true;
17+
export const isInternalFacebookBuild = true;
1718

1819
/************************************************************************
1920
* Do not edit the code below.

packages/react-devtools-shared/src/config/DevToolsFeatureFlags.extension-oss.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
************************************************************************/
1515

1616
export const enableProfilerChangedHookIndices = false;
17+
export const isInternalFacebookBuild = false;
1718

1819
/************************************************************************
1920
* Do not edit the code below.

packages/react-devtools-shared/src/constants.js

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export const CHANGE_LOG_URL =
4949
export const UNSUPPORTED_VERSION_URL =
5050
'https://reactjs.org/blog/2019/08/15/new-react-devtools.html#how-do-i-get-the-old-version-back';
5151

52+
export const REACT_DEVTOOLS_WORKPLACE_URL =
53+
'https://fburl.com/react-devtools-workplace-group';
54+
5255
// HACK
5356
//
5457
// Extracting during build time avoids a temporarily invalid state for the inline target.

packages/react-devtools-shared/src/devtools/views/ErrorBoundary.css

-54
This file was deleted.

packages/react-devtools-shared/src/devtools/views/ErrorBoundary.js

-154
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import * as React from 'react';
11+
import {Component, Suspense} from 'react';
12+
import ErrorView from './ErrorView';
13+
import SearchingGitHubIssues from './SearchingGitHubIssues';
14+
import SuspendingErrorView from './SuspendingErrorView';
15+
16+
type Props = {|
17+
children: React$Node,
18+
|};
19+
20+
type State = {|
21+
callStack: string | null,
22+
componentStack: string | null,
23+
errorMessage: string | null,
24+
hasError: boolean,
25+
|};
26+
27+
const InitialState: State = {
28+
callStack: null,
29+
componentStack: null,
30+
errorMessage: null,
31+
hasError: false,
32+
};
33+
34+
export default class ErrorBoundary extends Component<Props, State> {
35+
state: State = InitialState;
36+
37+
static getDerivedStateFromError(error: any) {
38+
const errorMessage =
39+
typeof error === 'object' &&
40+
error !== null &&
41+
error.hasOwnProperty('message')
42+
? error.message
43+
: '' + error;
44+
45+
return {
46+
errorMessage,
47+
hasError: true,
48+
};
49+
}
50+
51+
componentDidCatch(error: any, {componentStack}: any) {
52+
const callStack =
53+
typeof error === 'object' &&
54+
error !== null &&
55+
error.hasOwnProperty('stack')
56+
? error.stack
57+
.split('\n')
58+
.slice(1)
59+
.join('\n')
60+
: null;
61+
62+
this.setState({
63+
callStack,
64+
componentStack,
65+
});
66+
}
67+
68+
render() {
69+
const {children} = this.props;
70+
const {callStack, componentStack, errorMessage, hasError} = this.state;
71+
72+
if (hasError) {
73+
return (
74+
<ErrorView
75+
callStack={callStack}
76+
componentStack={componentStack}
77+
errorMessage={errorMessage}>
78+
<Suspense fallback={<SearchingGitHubIssues />}>
79+
<SuspendingErrorView
80+
callStack={callStack}
81+
componentStack={componentStack}
82+
errorMessage={errorMessage}
83+
/>
84+
</Suspense>
85+
</ErrorView>
86+
);
87+
}
88+
89+
return children;
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import * as React from 'react';
11+
import styles from './shared.css';
12+
13+
type Props = {|
14+
callStack: string | null,
15+
children: React$Node,
16+
componentStack: string | null,
17+
errorMessage: string | null,
18+
|};
19+
20+
export default function ErrorView({
21+
callStack,
22+
children,
23+
componentStack,
24+
errorMessage,
25+
}: Props) {
26+
return (
27+
<div className={styles.ErrorBoundary}>
28+
{children}
29+
<div className={styles.ErrorInfo}>
30+
<div className={styles.Header}>
31+
Uncaught Error: {errorMessage || ''}
32+
</div>
33+
{!!callStack && (
34+
<div className={styles.Stack}>
35+
The error was thrown {callStack.trim()}
36+
</div>
37+
)}
38+
{!!componentStack && (
39+
<div className={styles.Stack}>
40+
The error occurred {componentStack.trim()}
41+
</div>
42+
)}
43+
</div>
44+
</div>
45+
);
46+
}

0 commit comments

Comments
 (0)