fix: run reroute in a middleware function before split functions - #16590
fix: run reroute in a middleware function before split functions#16590teemingc wants to merge 29 commits into
reroute in a middleware function before split functions#16590Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/df404ce1540794d3c0267050e096080eb3257175Open in |
🦋 Changeset detectedLatest commit: df404ce The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
| @@ -0,0 +1,6 @@ | |||
| --- | |||
| '@sveltejs/adapter-netlify': major | |||
| '@sveltejs/adapter-vercel': major | |||
There was a problem hiding this comment.
using a major here to make it more noticeable that folks will have this extra middleware function deployed
…nto fix-split-reroute
Split out from #16590 which adds a test to ensure we don't regress from getting `reroute` to work with multiple Vercel functions I've initialised a project at https://vercel.com/svelte/platform-tests-split but will need help checking if its configured correctly. Will also need someone with permissions to add the secret deployment ID to this repo for `secrets.VERCEL_PROJECT_ID_SPLIT`
|
|
||
| ### Individual functions and `reroute` | ||
|
|
||
| If the `split` option is set to `true` for a route, or at the adapter level, the [`reroute`](hooks#reroute) function will be deployed as a middleware that runs before any individual function. |
There was a problem hiding this comment.
is this right, or does it also apply to apps that are implicitly split because of differing configs?
There was a problem hiding this comment.
Yeah, the latter; as long as there's more than one function
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
| '@sveltejs/kit': minor | ||
| --- | ||
|
|
||
| feat: add `applyReroute` and `builder.getReroutePath` helpers for running `reroute` in a middleware before the main handler |
There was a problem hiding this comment.
I'm not 100% sure about this API. It's called getReroutePath but it returns a path to the universal hooks.js file which also includes transport (and whatever else we add in future) so at the very least it should be named getUniversalHooksPath or something.
But we probably only want to expose the reroute logic, which leaves me wondering if it makes sense to do something like this instead:
import { applyReroute } from 'WHATEVER';
export default function middleware(request) {
return applyReroute(request);
}There was a problem hiding this comment.
Mm would it be a good idea to have a builder.generateReroute() which bundles up the reroute logic and returns a string instead of writing to disk? and it returns undefined if the adapter doesn't need to care about reroute?
fixes #11879
See #12296 for context
This PR adds a middleware that runs
reroutebeforehand so that, when there are multiple functions, the correct one is invoked instead of not matching any function matchers.The Vercel middleware uses a simplified version of the rewrite helper from
@vercel/functionsto avoid pulling in the whole bundle.rewritedocs - https://vercel.com/docs/functions/edge-middleware/middleware-api#rewritesrewriteimplementation - https://github.com/vercel/vercel/blob/cefda60a603d60cc35e4697c36e751cca411e6bb/packages/functions/src/middleware.ts#L101The Netlify middleware resolves the URL then passes it to the next handler.
There's currently an issue with Vercel rewrites discarding the SvelteKit form action in the URL because the query parameter doesn't have a value vercel/vercel#12902
TODOS
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