Skip to content

feat: add applyReroute helper for catch-all serverless functions - #16665

Merged
Rich-Harris merged 90 commits into
version-3from
fix-split-reroute-2
Aug 20, 2026
Merged

feat: add applyReroute helper for catch-all serverless functions#16665
Rich-Harris merged 90 commits into
version-3from
fix-split-reroute-2

Conversation

@teemingc

@teemingc teemingc commented Aug 6, 2026

Copy link
Copy Markdown
Member

alternative to #16590

fixes #11879

This PR makes the assumption that a catch-all serverless function is deployed with no routes in its manifest (the alternative was an explicit flag). It then exports a helper which should be called in such a serverless function after server.respond so that it can invoke the correct handler instead of simply returning a 404 since it has no route information in its SSR manifest.

The advantage of this approach compared to deploying a middleware that only runs reroute is that it's simpler implementation-wise and it allows the user's handleFetch, init hooks, etc. to run correctly without any additional effort from us.

The disadvantages are that:

  • reroute will run twice: once in the catch-all function then again in the correct function. We could choose to skip the second reroute based on some header value or context (if any) that can be passed between serverless functions. Otherwise, I chose to omit this so that the reroute hook can't be skipped from outside influence (someone setting the header themselves without running reroute first)
  • Slightly bigger serverless function bundle than a middleware which just runs reroute. Not that big of an issue I think...

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.

@teemingc
teemingc marked this pull request as ready for review August 6, 2026 17:28
Comment thread packages/adapter-netlify/index.js Outdated
teemingc and others added 2 commits August 7, 2026 02:01
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
@teemingc
teemingc requested a review from Rich-Harris August 7, 2026 07:32
@teemingc

Copy link
Copy Markdown
Member Author

/autofix

@teemingc teemingc added pkg:adapter-vercel Pertaining to the Vercel adapter pkg:adapter-netlify labels Aug 20, 2026

@Rich-Harris Rich-Harris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@Rich-Harris
Rich-Harris merged commit 4f63c79 into version-3 Aug 20, 2026
27 checks passed
@Rich-Harris
Rich-Harris deleted the fix-split-reroute-2 branch August 20, 2026 19:19
Rich-Harris pushed a commit that referenced this pull request Aug 21, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to version-3, this PR
will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`version-3` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `version-3`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @sveltejs/adapter-bun@1.0.0-next.1

### Minor Changes

- feat: add a Bun-native adapter with static file serving and
single-executable support
([#16695](#16695))

### Patch Changes

- Updated dependencies
[[`9b3d195`](9b3d195),
[`385d378`](385d378),
[`3782448`](3782448),
[`d0d3a33`](d0d3a33),
[`4b7a483`](4b7a483),
[`e325d7d`](e325d7d),
[`4f63c79`](4f63c79)]:
  - @sveltejs/kit@3.0.0-next.25
## @sveltejs/kit@3.0.0-next.25

### Minor Changes

- feat: add an `applyReroute` helper for adapters that support split
serverless function deployments
([#16665](#16665))

### Patch Changes

- chore: build streamed responses from async generators
([#16847](#16847))

- fix: tweak response logging for remote requests
([#16865](#16865))

- fix: discard invalidation results when a navigation completes while
they load ([#16852](#16852))

- fix: route dev-server response logging through Vite's logger so it
respects `logLevel` and `customLogger`
([#16858](#16858))

- chore: read build-time config from defines on the server instead of
carrying it in `options`
([#16873](#16873))

- chore: read `options` from a single module instead of passing it
through the server runtime
([#16871](#16871))
## @sveltejs/adapter-netlify@7.0.0-next.10

### Patch Changes

- fix: correctly apply `reroute` results for apps configured with split
serverless functions
([#16665](#16665))
- Updated dependencies
[[`9b3d195`](9b3d195),
[`385d378`](385d378),
[`3782448`](3782448),
[`d0d3a33`](d0d3a33),
[`4b7a483`](4b7a483),
[`e325d7d`](e325d7d),
[`4f63c79`](4f63c79)]:
  - @sveltejs/kit@3.0.0-next.25
## @sveltejs/adapter-vercel@7.0.0-next.8

### Patch Changes

- fix: omit ISR data endpoints for server-only routes
([#16731](#16731))

- fix: correctly apply `reroute` results for apps configured with split
serverless functions
([#16665](#16665))
- Updated dependencies
[[`9b3d195`](9b3d195),
[`385d378`](385d378),
[`3782448`](3782448),
[`d0d3a33`](d0d3a33),
[`4b7a483`](4b7a483),
[`e325d7d`](e325d7d),
[`4f63c79`](4f63c79)]:
  - @sveltejs/kit@3.0.0-next.25

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-platform-tests This PR needs to run platform tests in order to merge. pkg:adapter-netlify pkg:adapter-vercel Pertaining to the Vercel adapter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reroute hook breaks when deployed on Vercel if the app is deployed as multiple functions

2 participants