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

fix: copy _headers and _redirects from project root instead of /static #13227

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

eltigerchino
Copy link
Member

@eltigerchino eltigerchino commented Dec 23, 2024

closes #12216

This PR documents the fact that the two Cloudflare Pages specific files need to be excluded from the service worker's files or the service worker will fail to register if it tries to add them to the cache. This is because the files are not publicly available after the app is deployed and the service worker will error if it can't find them from the internet.

It would be nicer if we could use the adapter to exclude them but I don't know of an easy way to hook into the service worker build process or to modify the final output.

Alternatively, we could stop encouraging _headers and _redirects files in the /static directory as mentioned in the docs, and have the adapter read/copy them from the root of the project instead. Technically, they never should have been in the /static directory since they are not meant to be public files. This would be a breaking change but it does fix this issue in a better way.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@eltigerchino eltigerchino added documentation Improvements or additions to documentation pkg:adapter-cloudflare labels Dec 23, 2024
Copy link

changeset-bot bot commented Dec 23, 2024

🦋 Changeset detected

Latest commit: 88c3008

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/adapter-cloudflare Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris
Copy link
Member

preview: https://svelte-dev-git-preview-kit-13227-svelte.vercel.app/

this is an automated message

@dummdidumm
Copy link
Member

and have the adapter read/copy them from the root of the project instead

So people would no longer do

src/
etc/
static/
   _headers

they would put it in the root directly?

src/
etc/
_headers

Do you remember why we did it originally by putting it in static? I think it makes sense to not have them in static because as you say that's not where they will end up eventually.

@eltigerchino
Copy link
Member Author

eltigerchino commented Jan 17, 2025

and have the adapter read/copy them from the root of the project instead

So people would no longer do

src/
etc/
static/
   _headers

they would put it in the root directly?

src/
etc/
_headers

Yes, that's right.

Do you remember why we did it originally by putting it in static?

I don't think it was ever intentional but it was the only way to have the files copied over to the root of the build output automatically without changes in the adapter.

@eltigerchino eltigerchino changed the title docs: explain why _headers and _redirects files need to be excluded from the service worker's files fix: copy _headers and _redirects from project root instead of /static Jan 17, 2025
@eltigerchino eltigerchino added breaking change and removed documentation Improvements or additions to documentation labels Jan 17, 2025
@eltigerchino
Copy link
Member Author

I've changed it so that we copy the files from the project root now instead of relying on /static.

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

Successfully merging this pull request may close these issues.

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