sveltejs / sapper-template

Starter template for Sapper apps
703 stars 215 forks source link

prevent service worker from responding with null #277

Closed ehrencrona closed 3 years ago

ehrencrona commented 3 years ago

There have been two instances reported where the service worker responds to a fetch with a null response, which is illegal. It does this because it assumes that the static assets are always in the cache. Clearly that assumption doesn't always hold, and it's easy to fix by just awaiting the result of cache.match and only responding with it if there is a non-null value.

This necessitated moving a bit of code around and I took the opportunity to refactor the code a little bit.

Fixes sveltejs/sapper#1432 (even though I don't know the exact circumstances that lead to the assets not being in the cache) and fixes sveltejs/sapper#1587.

benmccann commented 3 years ago

@ehrencrona setupTypeScriptRollup.js was renamed to setupTypeScript.js in another PR that added webpack support, so this PR will need to be rebased

ehrencrona commented 3 years ago

Rebased!