Skip to content

Commit 4de1b5c

Browse files
authored
Fix serice worker creating null cache and console errors (#41)
1 parent 498ebe7 commit 4de1b5c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

service-worker/bootstrap.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@ workbox.routing.registerRoute(matchRuntimePath, async context => {
341341
const cacheName = getAPICacheName(apiVersion)
342342
const cacheOptions = { ...runtimeCacheOptions, cacheName }
343343

344+
if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') {
345+
return
346+
}
347+
348+
if (!apiVersion) {
349+
return new workbox.strategies.NetworkOnly().handle(context)
350+
}
344351
// Check the cache for all routes. If the result is not found, get it from the network.
345352
return new workbox.strategies.CacheOnly(cacheOptions)
346353
.handle(context)
@@ -350,7 +357,7 @@ workbox.routing.registerRoute(matchRuntimePath, async context => {
350357
// 2. it provide that to client and server build as a webpack define
351358
// 3. we should monkey-patch xhr to send x-rsf-api-version as a request header on all requests
352359

353-
if (apiRes.headers.get('x-rsf-cache-control') && apiVersion) {
360+
if (apiRes.headers.get('x-rsf-cache-control')) {
354361
const path = url.pathname
355362

356363
caches.open(cacheName).then(cache => {

0 commit comments

Comments
 (0)