Skip to content

Commit 5cb5dcb

Browse files
Add service worker update with asyn await to handle install event
1 parent d7beaef commit 5cb5dcb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

app/service-worker.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,20 @@ registerRoute(
5050
// Offline fallback
5151
self.addEventListener('install', (event: ExtendableEvent) => {
5252
const offlineFallbackPage = new Request('/offline.html');
53-
event.waitUntil(
54-
fetch(offlineFallbackPage).then(response => {
55-
return caches.open('offline').then(cache => {
56-
return cache.put(offlineFallbackPage, response);
57-
});
58-
})
59-
);
53+
54+
// Using an async function to handle the install event
55+
const installHandler = async () => {
56+
try {
57+
const response = await fetch(offlineFallbackPage);
58+
const cache = await caches.open('offline');
59+
await cache.put(offlineFallbackPage, response);
60+
} catch (error) {
61+
console.error('Failed to cache offline page:', error);
62+
}
63+
};
64+
65+
// Wait until the async function completes
66+
event.waitUntil(installHandler());
6067
});
6168

6269
export {}; // This helps with module augmentation

0 commit comments

Comments
 (0)