Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$service-worker files array includes non-asset _headers and _redirect files on cloudflare pages deployments #12216

Open
stevengibbsonline opened this issue May 14, 2024 · 0 comments

Comments

@stevengibbsonline
Copy link

Describe the bug

The _headers and _redirects files specific to the Cloudflare Pages adapter are not served by CF Pages as static assets. However, because they are placed in the static folder, they are included by default in the files array export from $service-worker.

If a service-worker implementation attempts to add these files to the Cache, without filtering them out in the service-worker or svelte config, it can cause service-worker registration to fail.

This is only a minor annoyance and not blocking, as the files can easily be filtered out.

Reproduction

Repo: https://github.com/stevengibbsonline/sk/tree/sw-files
Example CF Pages deployment: https://sw-files.sk-dj5.pages.dev/

  • Using cloudflare-adapter, and deployed to CF Pages
  • src/service-worker.js uses the example from https://kit.svelte.dev/docs/service-workers (additionally logs the files array at registration)
  • static includes a _headers file

Logs

Browser logs:

(3) ['/_headers', '/favicon.png', '/robots.txt']

service-worker.js:1 the static _headers or _redirects was included in the files array, and needs to be filtered out before we call cache.addAll

service-worker.js:1 Uncaught (in promise) TypeError: Failed to execute 'addAll' on 'Cache': Request failed

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
    Memory: 17.25 GB / 31.86 GB
  Binaries:
    Node: 20.12.0 - C:\Program Files\nodejs\node.EXE     
    npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD        
  Browsers:
    Chrome: 124.0.6367.201
    Edge: Chromium (124.0.2478.97)
    Internet Explorer: 11.0.19041.3636
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.2.0
    @sveltejs/adapter-cloudflare: ^4.4.0 => 4.4.0
    @sveltejs/kit: ^2.0.0 => 2.5.8
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.1.0
    svelte: ^4.2.7 => 4.2.16
    vite: ^5.0.3 => 5.2.11

Severity

annoyance

Additional Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant