Skip to content

Commit

Permalink
Reload the page when an error has occurred (#3098)
Browse files Browse the repository at this point in the history
* Reload the page when an error has occurred
Fixes #3096

* Use a global boolean instead
  • Loading branch information
Timer committed Sep 9, 2017
1 parent fcb6dc5 commit 5e300ce
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/react-dev-utils/webpackHotDevClient.js
Expand Up @@ -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',
});
Expand Down Expand Up @@ -227,7 +231,7 @@ function tryApplyUpdates(onHotUpdateSuccess) {
}

function handleApplyUpdates(err, updatedModules) {
if (err || !updatedModules) {
if (err || !updatedModules || hadRuntimeError) {
window.location.reload();
return;
}
Expand Down

0 comments on commit 5e300ce

Please sign in to comment.