From c172f3096b629a4b3f6f9476917a1a93493ef576 Mon Sep 17 00:00:00 2001 From: Broda Noel Date: Sat, 20 May 2017 19:01:17 -0300 Subject: [PATCH 1/2] Wrap console calls into a check --- packages/react-dev-utils/webpackHotDevClient.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/react-dev-utils/webpackHotDevClient.js b/packages/react-dev-utils/webpackHotDevClient.js index 05c2bb2b7ab..cf4deae7c6d 100644 --- a/packages/react-dev-utils/webpackHotDevClient.js +++ b/packages/react-dev-utils/webpackHotDevClient.js @@ -172,7 +172,7 @@ var connection = new SockJS( // to avoid spamming the console. Disconnect usually happens // when developer stops the server. connection.onclose = function() { - if (typeof console !== 'undefined') { + if (typeof console !== 'undefined' && typeof console.info === 'function') { console.info( 'The development server has disconnected.\nRefresh the page if necessary.' ); @@ -186,8 +186,8 @@ var hasCompileErrors = false; function clearOutdatedErrors() { // Clean up outdated compile errors, if any. - if (typeof console !== 'undefined') { - if (hasCompileErrors && typeof console.clear === 'function') { + if (typeof console !== 'undefined' && typeof console.clear === 'function') { + if (hasCompileErrors) { console.clear(); } } @@ -226,7 +226,7 @@ function handleWarnings(warnings) { errors: [], }); - if (typeof console !== 'undefined') { + if (typeof console !== 'undefined' && typeof console.warn === 'function') { for (var i = 0; i < formatted.warnings.length; i++) { console.warn(stripAnsi(formatted.warnings[i])); } @@ -266,7 +266,7 @@ function handleErrors(errors) { showErrorOverlay(formatted.errors[0]); // Also log them to the console. - if (typeof console !== 'undefined') { + if (typeof console !== 'undefined' && typeof console.error === 'function') { for (var i = 0; i < formatted.errors.length; i++) { console.error(stripAnsi(formatted.errors[i])); } From df9f3faf31a1681b5e05cf0ab94b9714570370c3 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sun, 21 May 2017 20:41:51 +0100 Subject: [PATCH 2/2] Add another check --- .../src/effects/proxyConsole.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/react-error-overlay/src/effects/proxyConsole.js b/packages/react-error-overlay/src/effects/proxyConsole.js index f17d01890c2..ec50ae2ca23 100644 --- a/packages/react-error-overlay/src/effects/proxyConsole.js +++ b/packages/react-error-overlay/src/effects/proxyConsole.js @@ -50,20 +50,22 @@ const permanentRegister = function proxyConsole( ) { if (typeof console !== 'undefined') { const orig = console[type]; - console[type] = function __stack_frame_overlay_proxy_console__() { - try { - const message = arguments[0]; - if (typeof message === 'string' && reactFrameStack.length > 0) { - callback(message, reactFrameStack[reactFrameStack.length - 1]); + if (typeof orig === 'function') { + console[type] = function __stack_frame_overlay_proxy_console__() { + try { + const message = arguments[0]; + if (typeof message === 'string' && reactFrameStack.length > 0) { + callback(message, reactFrameStack[reactFrameStack.length - 1]); + } + } catch (err) { + // Warnings must never crash. Rethrow with a clean stack. + setTimeout(function() { + throw err; + }); } - } catch (err) { - // Warnings must never crash. Rethrow with a clean stack. - setTimeout(function() { - throw err; - }); - } - return orig.apply(this, arguments); - }; + return orig.apply(this, arguments); + }; + } } };