Skip to content

Commit 42f362c

Browse files
Timerthongdong7
authored andcommitted
Reload the page when an error has occurred (facebook#3098)
* Reload the page when an error has occurred Fixes facebook#3096 * Use a global boolean instead
1 parent 88b9e2f commit 42f362c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/react-dev-utils/webpackHotDevClient.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ var launchEditorEndpoint = require('./launchEditorEndpoint');
2525
var formatWebpackMessages = require('./formatWebpackMessages');
2626
var ErrorOverlay = require('react-error-overlay');
2727

28+
// We need to keep track of if there has been a runtime error.
29+
// Essentially, we cannot guarantee application state was not corrupted by the
30+
// runtime error. To prevent confusing behavior, we forcibly reload the entire
31+
// application. This is handled below when we are notified of a compile (code
32+
// change).
33+
// See https://github.com/facebookincubator/create-react-app/issues/3096
34+
var hadRuntimeError = false;
2835
ErrorOverlay.startReportingRuntimeErrors({
2936
launchEditorEndpoint: launchEditorEndpoint,
3037
onError: function() {
31-
// TODO: why do we need this?
32-
if (module.hot && typeof module.hot.decline === 'function') {
33-
module.hot.decline();
34-
}
38+
hadRuntimeError = true;
3539
},
3640
filename: '/static/js/bundle.js',
3741
});
@@ -227,7 +231,7 @@ function tryApplyUpdates(onHotUpdateSuccess) {
227231
}
228232

229233
function handleApplyUpdates(err, updatedModules) {
230-
if (err || !updatedModules) {
234+
if (err || !updatedModules || hadRuntimeError) {
231235
window.location.reload();
232236
return;
233237
}

0 commit comments

Comments
 (0)