Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Service worker files to cache don't include base path #1692

Closed
finnbear opened this issue Jan 8, 2021 · 2 comments
Closed

Service worker files to cache don't include base path #1692

finnbear opened this issue Jan 8, 2021 · 2 comments

Comments

@finnbear
Copy link

finnbear commented Jan 8, 2021

Describe the bug
The paths passed to the service worker for caching do not include the basepath

Logs
Here is the compiled service worker for my project, despite the fact that I specified a two-directory-deep base path following the instructions in the documentation. As you can see, many of the paths in the service worker start with /client rather than /my/basepath/client.

!function(){"use strict";const e=1610090779060,t=`cache${e}`,c=["/client/client.4a48bc03.js","/client/inject_styles.5607aec6.js","/client/index.a638974d.js","/client/integer.23b05fd4.js","/client/Select.f63838d9.js","/client/Slider.cdb985c1.js","/client/matrix.4cf47436.js","/client/cache.f20914d9.js","/client/float.8d03a59d.js","/client/heap.50efc23e.js"].concat(["/service-worker-index.html","/favicon.png","/global.css","/manifest.json"]),n=new Set(c);self.addEventListener("install",(e=>{e.waitUntil(caches.open(t).then((e=>e.addAll(c))).then((()=>{self.skipWaiting()})))})),self.addEventListener("activate",(e=>{e.waitUntil(caches.keys().then((async e=>{for(const c of e)c!==t&&await caches.delete(c);self.clients.claim()})))})),self.addEventListener("fetch",(t=>{if("GET"!==t.request.method||t.request.headers.has("range"))return;const c=new URL(t.request.url),s=c.protocol.startsWith("http"),a=c.hostname===self.location.hostname&&c.port!==self.location.port,i=c.host===self.location.host&&n.has(c.pathname),l="only-if-cached"===t.request.cache&&!i;!s||a||l||t.respondWith((async()=>i&&await caches.match(t.request)||async function(t){const c=await caches.open(`offline${e}`);try{const e=await fetch(t);return c.put(t,e.clone()),e}catch(e){const n=await c.match(t);if(n)return n;throw e}}(t.request))())}))}();

To Reproduce

  1. Create a sapper app
  2. Add a basepath, following the documentations instructions to add it to both the server and the argument to sapper export
  3. Load the site
  4. Look for failed caching requests to incorrect urls

Expected behavior
Service worker should be passed paths that conform to the basepath.

  • The output of npx envinfo --system --npmPackages svelte,sapper,rollup,webpack --binaries --browsers
    System:
    OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
    Memory: 7.26 GB / 31.31 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
    Binaries:
    Node: 14.13.0 - ~/.nvm/versions/node/v14.13.0/bin/node
    npm: 6.14.8 - ~/.nvm/versions/node/v14.13.0/bin/npm
    Browsers:
    Firefox: 81.0

  • Your browser: Firefox 81

  • Your hosting environment (i.e. Local, GCP/AWS/Azure, Vercel/Begin, etc...): Simple http server

  • If it is an exported (npm run export) or dynamic application: Exported/static

Severity
My site works fine, but nothing is cached properly by the service worker.

@benmccann
Copy link
Member

This was also reported in #1538 and #1441

I'm not quite sure what the best fix is. See the description in #1545 (comment). I'm leaning towards prepending the base path. Though I'm not actively working on Sapper at the moment. But if you'd like to send a PR I'll review it

@finnbear
Copy link
Author

finnbear commented Jan 8, 2021

Those do look like the same issue. I guess we can close this as duplicate.

@finnbear finnbear closed this as completed Jan 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants