From 397b5ae949fcd150aa162065fcf246eeebddbf6d Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Tue, 10 Oct 2017 23:01:49 -0400 Subject: [PATCH 1/3] Add a warning when running minified --- packages/react-error-overlay/src/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/react-error-overlay/src/index.js b/packages/react-error-overlay/src/index.js index a800595cffb..1cccd49d8c3 100644 --- a/packages/react-error-overlay/src/index.js +++ b/packages/react-error-overlay/src/index.js @@ -167,3 +167,15 @@ window.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__.iframeReady = function iframeReady() isLoadingIframe = false; updateIframeContent(); }; + +var testFunc = function testFn() {}; +if ((testFunc.name || testFunc.toString()).indexOf('testFn') !== -1) { + console.warn( + 'It looks like you are using `react-error-overlay` in production. 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 ' + + 'handling behavior. See https://fb.me/react-error-boundaries for more ' + + 'information.' + ); +} From 2410af77be8e952fb19dde4307a6cbcd5d530eef Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Tue, 10 Oct 2017 23:06:40 -0400 Subject: [PATCH 2/3] Add more robust check --- packages/react-error-overlay/src/index.js | 25 +++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/react-error-overlay/src/index.js b/packages/react-error-overlay/src/index.js index 1cccd49d8c3..1447052a016 100644 --- a/packages/react-error-overlay/src/index.js +++ b/packages/react-error-overlay/src/index.js @@ -168,14 +168,23 @@ window.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__.iframeReady = function iframeReady() updateIframeContent(); }; -var testFunc = function testFn() {}; -if ((testFunc.name || testFunc.toString()).indexOf('testFn') !== -1) { +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 ' + + '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) { + console.warn( + 'It looks like you are using `react-error-overlay` in production. ' + + warningText + ); + } +} else { console.warn( - 'It looks like you are using `react-error-overlay` in production. 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 ' + - 'handling behavior. See https://fb.me/react-error-boundaries for more ' + - 'information.' + 'You are using `react-error-overlay` in production. ' + warningText ); } From 85109c39d9f04ef2062882781986db80f791ff90 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 11 Oct 2017 13:30:52 -0400 Subject: [PATCH 3/3] Update index.js --- packages/react-error-overlay/src/index.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/packages/react-error-overlay/src/index.js b/packages/react-error-overlay/src/index.js index 1447052a016..8bc61ca250e 100644 --- a/packages/react-error-overlay/src/index.js +++ b/packages/react-error-overlay/src/index.js @@ -168,23 +168,9 @@ window.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__.iframeReady = function iframeReady() 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 ' + - '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) { - console.warn( - 'It looks like you are using `react-error-overlay` in production. ' + - warningText - ); - } -} else { +if (process.env.NODE_ENV === 'production') { console.warn( - 'You are using `react-error-overlay` in production. ' + warningText + 'react-error-overlay is not meant for use in production. You should ' + + 'ensure it is not included in your build to reduce bundle size.' ); }