From 383245e0e2d02a0b4e18ba1b11a1fd742890055a Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Fri, 8 Sep 2017 22:52:18 -0400 Subject: [PATCH] Reload the page when an error has occurred (#3098) * Reload the page when an error has occurred Fixes #3096 * Use a global boolean instead --- packages/react-dev-utils/webpackHotDevClient.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/react-dev-utils/webpackHotDevClient.js b/packages/react-dev-utils/webpackHotDevClient.js index 18a6a4a0ae1..b0508dc4d23 100644 --- a/packages/react-dev-utils/webpackHotDevClient.js +++ b/packages/react-dev-utils/webpackHotDevClient.js @@ -25,13 +25,17 @@ var launchEditorEndpoint = require('./launchEditorEndpoint'); var formatWebpackMessages = require('./formatWebpackMessages'); var ErrorOverlay = require('react-error-overlay'); +// We need to keep track of if there has been a runtime error. +// Essentially, we cannot guarantee application state was not corrupted by the +// runtime error. To prevent confusing behavior, we forcibly reload the entire +// application. This is handled below when we are notified of a compile (code +// change). +// See https://github.com/facebookincubator/create-react-app/issues/3096 +var hadRuntimeError = false; ErrorOverlay.startReportingRuntimeErrors({ launchEditorEndpoint: launchEditorEndpoint, onError: function() { - // TODO: why do we need this? - if (module.hot && typeof module.hot.decline === 'function') { - module.hot.decline(); - } + hadRuntimeError = true; }, filename: '/static/js/bundle.js', }); @@ -227,7 +231,7 @@ function tryApplyUpdates(onHotUpdateSuccess) { } function handleApplyUpdates(err, updatedModules) { - if (err || !updatedModules) { + if (err || !updatedModules || hadRuntimeError) { window.location.reload(); return; }