Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevTools error boundary: Search for pre-existing GH issues #21279

Merged
merged 2 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react-devtools-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"@babel/runtime": "^7.11.2",
"@octokit/rest": "^18.5.2",
"@reach/menu-button": "^0.1.17",
"@reach/tooltip": "^0.2.2",
"clipboard-js": "^0.3.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
************************************************************************/

export const enableProfilerChangedHookIndices = false;
export const isInternalFacebookBuild = false;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
************************************************************************/

export const enableProfilerChangedHookIndices = true;
export const isInternalFacebookBuild = true;

/************************************************************************
* Do not edit the code below.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
************************************************************************/

export const enableProfilerChangedHookIndices = false;
export const isInternalFacebookBuild = false;

/************************************************************************
* Do not edit the code below.
Expand Down
3 changes: 3 additions & 0 deletions packages/react-devtools-shared/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export const CHANGE_LOG_URL =
export const UNSUPPORTED_VERSION_URL =
'https://reactjs.org/blog/2019/08/15/new-react-devtools.html#how-do-i-get-the-old-version-back';

export const REACT_DEVTOOLS_WORKPLACE_URL =
'https://fburl.com/react-devtools-workplace-group';

// HACK
//
// Extracting during build time avoids a temporarily invalid state for the inline target.
Expand Down

This file was deleted.

154 changes: 0 additions & 154 deletions packages/react-devtools-shared/src/devtools/views/ErrorBoundary.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import * as React from 'react';
import {Component, Suspense} from 'react';
import ErrorView from './ErrorView';
import SearchingGitHubIssues from './SearchingGitHubIssues';
import SuspendingErrorView from './SuspendingErrorView';

type Props = {|
children: React$Node,
|};

type State = {|
callStack: string | null,
componentStack: string | null,
errorMessage: string | null,
hasError: boolean,
|};

const InitialState: State = {
callStack: null,
componentStack: null,
errorMessage: null,
hasError: false,
};

export default class ErrorBoundary extends Component<Props, State> {
state: State = InitialState;

static getDerivedStateFromError(error: any) {
const errorMessage =
typeof error === 'object' &&
error !== null &&
error.hasOwnProperty('message')
? error.message
: '' + error;

return {
errorMessage,
hasError: true,
};
}

componentDidCatch(error: any, {componentStack}: any) {
const callStack =
typeof error === 'object' &&
error !== null &&
error.hasOwnProperty('stack')
? error.stack
.split('\n')
.slice(1)
.join('\n')
: null;

this.setState({
callStack,
componentStack,
});
}

render() {
const {children} = this.props;
const {callStack, componentStack, errorMessage, hasError} = this.state;

if (hasError) {
return (
<ErrorView
callStack={callStack}
componentStack={componentStack}
errorMessage={errorMessage}>
<Suspense fallback={<SearchingGitHubIssues />}>
<SuspendingErrorView
callStack={callStack}
componentStack={componentStack}
errorMessage={errorMessage}
/>
</Suspense>
</ErrorView>
);
}

return children;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import * as React from 'react';
import styles from './shared.css';

type Props = {|
callStack: string | null,
children: React$Node,
componentStack: string | null,
errorMessage: string | null,
|};

export default function ErrorView({
callStack,
children,
componentStack,
errorMessage,
}: Props) {
return (
<div className={styles.ErrorBoundary}>
{children}
<div className={styles.ErrorInfo}>
<div className={styles.Header}>
Uncaught Error: {errorMessage || ''}
</div>
{!!callStack && (
<div className={styles.Stack}>
The error was thrown {callStack.trim()}
</div>
)}
{!!componentStack && (
<div className={styles.Stack}>
The error occurred {componentStack.trim()}
</div>
)}
</div>
</div>
);
}
Loading