Repository navigation
feat: expose trailingSlash to adapters and use a single Vercel route when every route agrees - #17522
Draft
elliott-with-the-longest-name-on-github wants to merge 1 commit into
Draft
elliott-with-the-longest-name-on-github wants to merge 1 commit into
elliott-with-the-longest-name-on-github wants to merge 1 commit into
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/2d0cb08c7a222220c842921e0aaf003f7f412a72Open in |
elliott-with-the-longest-name-on-github
added this pull request to stack #17524
October 22, 2026 18:17
🦋 Changeset detectedLatest commit: 2d0cb08 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 |
trailingSlash to adapters and use a single Vercel route when every route agrees
elliott-with-the-longest-name-on-github
deployed
to
@sveltejs/adapter-vercel platform tests
October 22, 2026 22:36 — with
GitHub Actions
Active
elliott-with-the-longest-name-on-github
deployed
to
@sveltejs/adapter-vercel platform tests
October 22, 2026 22:36 — with
GitHub Actions
Active
elliott-with-the-longest-name-on-github
deployed
to
@sveltejs/adapter-vercel platform tests
October 22, 2026 22:37 — with
GitHub Actions
Active
This branch was successfully deployed
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.
Vercel has no server at runtime for prerendered pages, so
adapter-vercelhandlestrailingSlashfor them in the routing table. Currently it adds two routes per prerendered page: one that serves the page and one that redirects the wrong trailing slash to the right one. Vercel only allows 2048 routes per deployment, so a blog with a thousand posts fails to deploy, even though every post comes from the same/blog/[slug]route.Basically, the adapter can't do better than per-page routes without knowing which trailing slash each route wants. It can't tell whether
/blog/should redirect everything, or whether/blog/about-mehas its own route with a different setting. This PR gives adapters that information. When every route agrees, the adapter replaces all of the per-page routes with one global rule. That's the case for most apps, since'never'is the default.What changed
@sveltejs/kit:builder.routesnow includes each route'strailingSlash. It's resolved the same way as at runtime: the page's option, then the endpoint's, then'never'.@sveltejs/adapter-vercel/@sveltejs/adapter-static(the copy it uses when building on Vercel):'never': a single 308 from^/(.+)/$to/$1, placed before the filesystem phase.'always': this is harder, because Vercel ignores the trailing slash when it looks up a static file, and it also serves anyfoo/index.htmlatfoo. So/foowould find the page before any redirect after the filesystem phase could run.foo/__index.html, which Vercel doesn't alias tofoo.missroute rewrites/foo/to/foo/__index.html. Vercel revertsmissrewrites that don't find a file, so other requests are unaffected./_app/*,__data.jsonand__route.jsrequests are excluded.paths.base, there's also a redirect from the base tobase/, since Kit always gives the root a trailing slash in that case.'ignore', or an older Kit) keeps the existing per-page routes. fix: combine prerendered trailing slash redirects into as few Vercel routes as possible #17523 makes that fallback much smaller.handlemarker rather than beforehandle: filesystem, since amisssection can now come first.Why only when every route agrees
I considered emitting a regex per route, ordered by Kit's route priority, with exceptions for conflicting routes. That falls apart quickly:
reroutemeans a route's pattern doesn't tell you which URLs it serves. You can end up with the edge removing a slash and Kit adding it back, forever.If every route agrees, none of that matters, because whichever route ends up handling a URL wants the same thing.
A few behaviour changes worth knowing about:
'always'apps, a+server.jsendpoint that doesn't exporttrailingSlashdefaults to'never'. That means the app isn't uniform, so it uses the fallback.Tests
split(which has notrailingSlashoptions, and has areroutehook) now has prerendered pages, plus build and platform tests for the'never'rule.trailing-slashapp uses'always'everywhere. It covers prerendered and server-rendered pages, endpoints, static assets with and without extensions, the query string and client-side navigation (which exercises__data.json).basicmixes options and keeps covering the fallback.CI setup needed before merging: the new app needs a Vercel project with its root directory set to
packages/adapter-vercel/test/apps/trailing-slash, and its ID stored as theVERCEL_PROJECT_ID_TRAILING_SLASHsecret. The workflows already reference it.With
paths.baseset, the'always'rename needs #17525, which fixes theoverrideskeys for apps that use a base path. Once that's merged, I'll rebase this and add the base to the rename as well.