Skip to content

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

Open
teemingc wants to merge 85 commits into
version-3from
fix-split-reroute-2
Open

feat: add applyReroute helper for catch-all serverless functions#16665
teemingc wants to merge 85 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 draft August 6, 2026 12:39
@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
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.

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