Skip to content

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

Closed

Description

@stevengibbsonline

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions