feat: add applyReroute helper for catch-all serverless functions - #16665
Open
teemingc wants to merge 85 commits into
Open
feat: add applyReroute helper for catch-all serverless functions#16665teemingc wants to merge 85 commits into
applyReroute helper for catch-all serverless functions#16665teemingc wants to merge 85 commits into
Conversation
…nto fix-split-reroute
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
teemingc
marked this pull request as draft
August 6, 2026 12:39
teemingc
marked this pull request as ready for review
August 6, 2026 17:28
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
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.
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.respondso 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,inithooks, etc. to run correctly without any additional effort from us.The disadvantages are that:
reroutewill run twice: once in the catch-all function then again in the correct function. We could choose to skip the secondreroutebased on someheadervalue or context (if any) that can be passed between serverless functions. Otherwise, I chose to omit this so that thereroutehook can't be skipped from outside influence (someone setting the header themselves without runningreroutefirst)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:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
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