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

Add warning when using react-error-overlay in production #3264

Merged
merged 3 commits into from
Oct 11, 2017
Merged
Changes from 2 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
21 changes: 21 additions & 0 deletions packages/react-error-overlay/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,24 @@ window.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__.iframeReady = function iframeReady()
isLoadingIframe = false;
updateIframeContent();
};

const warningText =
'When deploying an application, `react-error-overlay` should be excluded ' +
'as it is a heavy dependency meant for development.\n\n' +
'Consider adding an error boundary to your tree to customize error ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the error boundary text here? Doesn't seem very relevant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone was purposely including react-error-overlay for production errors, though I know most cases would be accidental.

We can remove this.

'handling behavior. See https://fb.me/react-error-boundaries for more ' +
'information.';

if (process.env.NODE_ENV !== 'production') {
var testFunc = function testFn() {};
if ((testFunc.name || testFunc.toString()).indexOf('testFn') === -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toString() is not guaranteed to be safe. I'd opt to remove this branch completely and for now just assume process.env.NODE_ENV is correct. We have detection in React DevTools for other cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this would probably error out if they did not envify variables, so I agree.

console.warn(
'It looks like you are using `react-error-overlay` in production. ' +
warningText
);
}
} else {
console.warn(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could be more severe with console.error, or perhaps throw.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it makes more sense to go with warn as it's technically not an error.

'You are using `react-error-overlay` in production. ' + warningText
);
}