Skip to content

Commit 52e1e84

Browse files
committed
fix: crash recovery infinite dialogs
1 parent 7691b84 commit 52e1e84

File tree

3 files changed

+46
-28
lines changed

3 files changed

+46
-28
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-node/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,47 @@ function _unregisterServiceWorkers() {
188188
});
189189
}
190190

191+
const SESSION_RESTART_ONCE_DUE_TO_CRITICAL_ERROR = "SESSION_RESTART_ONCE_DUE_TO_CRITICAL_ERROR";
192+
193+
async function _recoverOnFailure(err) {
194+
// metrics api might not be available here as we were seeing no metrics raised. Only bugsnag there.
195+
window.logger && window.logger.reportError(err,
196+
'Critical error when loading brackets. Trying to reload again.');
197+
const restartedOnce = sessionStorage.getItem(SESSION_RESTART_ONCE_DUE_TO_CRITICAL_ERROR);
198+
let shouldRestart;
199+
if(!restartedOnce){
200+
sessionStorage.setItem(SESSION_RESTART_ONCE_DUE_TO_CRITICAL_ERROR, "true");
201+
shouldRestart = true;
202+
} else {
203+
shouldRestart = confirm("Oops! Something went wrong. Reload app?");
204+
if(shouldRestart instanceof Promise){
205+
shouldRestart = await shouldRestart;
206+
}
207+
}
208+
if(!shouldRestart) {
209+
return;
210+
}
211+
212+
// try a cache reset
213+
if(window._resetCacheIfNeeded){
214+
window._resetCacheIfNeeded(true)
215+
.finally(()=>{
216+
// wait for 3 seconds for bugsnag to send report and service workers to be active.
217+
setTimeout(()=>{
218+
_unregisterServiceWorkers()
219+
.then(()=>{
220+
location.reload();
221+
});
222+
}, 3000);
223+
});
224+
} else {
225+
// wait for 3 seconds for bugsnag to send report.
226+
setTimeout(()=>{
227+
location.reload();
228+
}, 3000);
229+
}
230+
}
231+
191232
define(function (require) {
192233

193234

@@ -196,29 +237,6 @@ define(function (require) {
196237
require(["utils/Metrics", "utils/Compatibility", "utils/EventDispatcher"], function () {
197238
window.Metrics = require("utils/Metrics");
198239
// Load the brackets module. This is a self-running module that loads and runs the entire application.
199-
require(["brackets"], ()=>{}, (err)=>{
200-
// metrics api might not be available here as we were seeing no metrics raised. Only bugsnag there.
201-
window.logger && window.logger.reportError(err,
202-
'Critical error when loading brackets. Trying to reload again.');
203-
alert("Oops! Something went wrong. Trying to restart app...");
204-
// try a cache reset
205-
if(window._resetCacheIfNeeded){
206-
window._resetCacheIfNeeded(true)
207-
.finally(()=>{
208-
// wait for 3 seconds for bugsnag to send report and service workers to be active.
209-
setTimeout(()=>{
210-
_unregisterServiceWorkers()
211-
.then(()=>{
212-
location.reload();
213-
});
214-
}, 3000);
215-
});
216-
} else {
217-
// wait for 3 seconds for bugsnag to send report.
218-
setTimeout(()=>{
219-
location.reload();
220-
}, 3000);
221-
}
222-
});
240+
require(["brackets"], ()=>{}, _recoverOnFailure);
223241
});
224242
});

0 commit comments

Comments
 (0)