Skip to content

Commit

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

* Use a global boolean instead
  • Loading branch information
Timer authored and kasperpeulen committed Sep 24, 2017
1 parent f3defb9 commit 5786537
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/react-dev-utils/webpackHotDevClient.js
Original file line number Diff line number Diff line change
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 5786537

Please sign in to comment.