Skip to content

Commit 67a5a08

Browse files
committed
Improvements to service workers and error handling
1 parent d16cc5a commit 67a5a08

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

packages/app/src/sandbox/compile.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -708,14 +708,14 @@ async function compile({
708708

709709
hadError = true;
710710
} finally {
711-
try {
712-
setTimeout(() => {
711+
setTimeout(() => {
712+
try {
713713
// Set a timeout so there's a chance that we also catch runtime errors
714714
localStorage.removeItem('running');
715-
}, 600);
716-
} catch (e) {
717-
/* no */
718-
}
715+
} catch (e) {
716+
/* no */
717+
}
718+
}, 600);
719719

720720
if (manager) {
721721
const managerState = {

packages/app/src/sandbox/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ import { show404 } from 'sandbox-hooks/not-found-screen';
1818

1919
import compile, { getCurrentManager } from './compile';
2020

21+
Object.defineProperty(window, 'localStorage', {
22+
get() {
23+
return {};
24+
},
25+
});
26+
Object.defineProperty(window, 'indexedDB', {
27+
get() {
28+
return {};
29+
},
30+
});
31+
2132
// Call this before importing React (or any other packages that might import React).
2233
initialize(window);
2334

packages/common/src/registerServiceWorker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function registerValidSW(
7676
} else if (installingWorker.state === 'redundant') {
7777
if ('storage' in navigator && 'estimate' in navigator.storage) {
7878
navigator.storage.estimate().then(results => {
79-
const percentUsed = (results.usage / results.quota) * 100;
79+
const percentUsed = results.usage / results.quota;
8080
// Let's assume that if we're using 95% of our quota, then this failure
8181
// was due to quota exceeded errors.
8282
// TODO: Hardcoding a threshold stinks.

0 commit comments

Comments
 (0)