kit
kit copied to clipboard
fix: prefer pages over endpoints when prerendering
fixes https://github.com/sveltejs/kit/issues/10735
This PR adds an Accept header to the prerender requests, preferring text/html first then whatever with */*. Previously, it would always end up as */* during content negotiation, which invokes the endpoint handler, causing a 405 method not allowed if the GET handler doesn't exist.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] 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
- [x] This message body should clearly illustrate what problems it solves.
- [ ] Ideally, include a test that fails without this PR but passes with it. No test because it would break the prerender app build.
Tests
- [x] Run the tests with
pnpm testand lint the project withpnpm lintandpnpm check
Changesets
- [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.
Edits
- [x] Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.
🦋 Changeset detected
Latest commit: 7ab5f9762e5eb0df8cb27acd0bf8bd596f54123e
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| @sveltejs/kit | Patch |
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
preview: https://svelte-dev-git-preview-kit-12998-svelte.vercel.app/
this is an automated message
Is this the right fix? Feels like maybe 405 is the wrong response for a GET request with */* if a page exists. Thoughts?
Is a test still TODO or is it basically impossable to test?
I chose not to add a test because it's only reproducible by breaking the prerender app build. But I could add a test that just sends a request to the route and see if we get a 405.
Is this the right fix? Feels like maybe 405 is the wrong response for a
GETrequest with*/*if a page exists. Thoughts?
An alternative is to await the route.endpoint() call earlier so we can check which methods it has but I'm not sure what kind of impact that will have. Either that, or prefer pages over endpoints during content negotiation (or earlier).
https://github.com/sveltejs/kit/blob/435984bf61b047d1e1a8efe88354ca7ac4e9109f/packages/kit/src/runtime/server/respond.js#L451
related to content negotiation https://github.com/sveltejs/kit/issues/11794
Is this the right fix? Feels like maybe 405 is the wrong response for a
GETrequest with*/*if a page exists. Thoughts?
Agreed that this PR is the wrong fix. Other people are having a similar issue with bot indexing https://github.com/sveltejs/kit/issues/11794