refactor: simplify endpoint/page routing logic and extend to HEAD - #16126
Merged
elliott-with-the-longest-name-on-github merged 2 commits intoJun 22, 2026
Conversation
- Restructure the endpoint load + decide flow into a single block with a positive `endpoint_can_handle` check, replacing the double-negative condition and await-in-ternary pattern - Extend the 'prefer page' behavior to HEAD requests: an endpoint with no HEAD, no GET (which render_endpoint falls back to for HEAD), and no fallback now renders the page instead of returning 405 - Add Vary: Accept header to HEAD responses for page+endpoint routes - Add tests for HEAD, POST, fallback, and content negotiation cases - Add fallback-with-page test route
|
| Name | Type |
|---|---|
| @sveltejs/kit | Patch |
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
dummdidumm
approved these changes
Jun 22, 2026
dummdidumm
left a comment
Member
There was a problem hiding this comment.
fix the lint and this can go in 👍
elliott-with-the-longest-name-on-github
merged commit Jun 22, 2026
c87c143
into
prefer-pages-when-no-get-endpoint
16 of 17 checks passed
elliott-with-the-longest-name-on-github
deleted the
prefer-pages-when-no-get-endpoint-refactor
branch
June 22, 2026 21:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #16125. No behavioral change to the GET fix — this refactors the endpoint load + decide flow for readability and extends the "prefer page" behavior to HEAD requests.
Refactor
Restructures the endpoint loading and decision logic in
respond.jsinto a single block with a positiveendpoint_can_handlecheck, replacing:await-in-ternary pattern (hard to scan)!route.pagecheck across load and use conditionsThe "load, then maybe discard" intent is now explicit and colocated.
HEAD fix
Extends the "prefer page" behavior to HEAD requests. Previously, a HEAD request with
accept: */*to a page+endpoint route where the endpoint had neither HEAD nor GET would get 405 fromrender_endpoint, even though the page could handle HEAD. Now the page is rendered instead.render_endpointalready falls back to GET for HEAD when GET exists — that case is preserved via theendpoint_can_handlecheck.Also extends the
Vary: Acceptheader to HEAD responses for page+endpoint routes, since HEAD can now be routed to either.Tests
fallback(newfallback-with-pagetest route)accept: application/jsonhits endpoint,accept: text/htmlhits page (using existingrouting/content-negotiationroute)