Skip to content

Commit 5c9b285

Browse files
committed
chore: improve web load robustness by detecting boot crashes and reload after cache reset
1 parent 3e0e098 commit 5c9b285

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@
349349
Note that this cannot be moved to a separate file and should be in index.html due to above reason.
350350
This is a nuke cache option. Though mostly safe, Use it wisely to prevent slow startup when resetting.
351351
*/
352-
async function _resetCacheIfNeeded() {
352+
async function _resetCacheIfNeeded(force) {
353353
if(Phoenix.browser.isTauri || Phoenix.isTestWindow) {
354354
// no web cache in desktop builds ot test windows
355355
return;
@@ -416,7 +416,7 @@
416416
console.log("No cache detected, ignore if first boot or safari ITP.");
417417
await _writeFileSafe(WEB_CACHE_FILE_PATH, PHOENIX_APP_CACHE_VERSION);
418418
// on next reload, the new cache will be active and populated by service worker
419-
} else if(currentCacheName !== PHOENIX_APP_CACHE_VERSION) {
419+
} else if(currentCacheName && (currentCacheName !== PHOENIX_APP_CACHE_VERSION || force)) {
420420
// This is an upgrade we could in the future use the cacheManifest.json to increase update speed
421421
// by only selectively updating the changed files.
422422
console.log("Old version cache detected", currentCacheName, "purging and setting", PHOENIX_APP_CACHE_VERSION);

src/main.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,26 @@ define(function (require) {
151151
require(["utils/Metrics", "utils/Compatibility", "utils/EventDispatcher"], function () {
152152
window.Metrics = require("utils/Metrics");
153153
// Load the brackets module. This is a self-running module that loads and runs the entire application.
154-
try{
155-
require(["brackets"]);
156-
} catch (err) {
157-
// try a cache reset
158-
window._resetCacheIfNeeded && window._resetCacheIfNeeded();
154+
require(["brackets"], ()=>{}, (err)=>{
159155
// metrics api might not be available here as we were seeing no metrics raised. Only bugsnag there.
160156
window.logger && window.logger.reportError(err,
161157
'Critical error when loading brackets. Trying to reload again.');
162-
// wait for 3 seconds for bugsnag to send report.
163-
setTimeout(window.location.reload, 3000);
164-
}
158+
alert("Oops! Something went wrong. Trying to restart app...");
159+
// try a cache reset
160+
if(window._resetCacheIfNeeded){
161+
window._resetCacheIfNeeded(true)
162+
.finally(()=>{
163+
// wait for 3 seconds for bugsnag to send report.
164+
setTimeout(()=>{
165+
location.reload();
166+
}, 3000);
167+
});
168+
} else {
169+
// wait for 3 seconds for bugsnag to send report.
170+
setTimeout(()=>{
171+
location.reload();
172+
}, 3000);
173+
}
174+
});
165175
});
166176
});

0 commit comments

Comments
 (0)