Repository navigation
fix(@astrojs/vercel): make redirects match when trailingSlash is always/never - #18085
Conversation
🦋 Changeset detectedLatest commit: ab47c82 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
| * for the root, spread routes, and file-extension paths (which Vercel | ||
| * normalizes without a slash even when `trailingSlash` is enabled). | ||
| */ | ||
| export function adjustSourceForTrailingSlash( |
There was a problem hiding this comment.
This function seems rather complicated and brittle. We have a set of utilities already for manipulating slashes in URLs, can you use these instead? https://github.com/withastro/astro/blob/main/packages/internal-helpers/src/path.ts
There was a problem hiding this comment.
Done — adjustSourceForTrailingSlash now uses appendForwardSlash / removeTrailingForwardSlash from @astrojs/internal-helpers/path instead of hand-slicing strings, and that is still the case after the latest change.
The one exclusion it keeps is the dot check, which is not a slash utility: it mirrors the two normalizers Vercel emits for trailingSlash: true (^/((?:[^/]+/)*[^/\.]+)$ adds a slash, ^/((?:[^/]+/)*[^/]+\.\w+)/$ strips one), so a source whose last segment contains a dot has to stay unslashed. hasFileExtension was the wrong predicate there — /release-1.0-beta is dotted but has no extension — so it is now a single LAST_SEGMENT_HAS_DOT regex with a comment explaining why.
Dynamic and spread sources are handled in getRedirects rather than in this helper, because they need two rules (slashed and unslashed) rather than one string.
|
Refactored |
There was a problem hiding this comment.
Verdict: changes requested.
Findings
[medium][correctness]packages/integrations/vercel/src/lib/redirects.ts:134: Spread redirects still never match undertrailingSlash: 'always'. Details are in the inline comment.
Merge Requirement Assessment
Status: gaps found
Redirect sources must match the path Vercel normalizes to under trailingSlash: 'always'(#18073): static and dynamic sources now get a trailing slash (adjustSourceForTrailingSlash), and the updatedtest/redirects.test.tsexpectations and new unit tests cover this. File-extension paths are correctly left without a slash. Spread sources are skipped, and with that slash rule active they still cannot match.Redirect sources under 'never' must not end in a slash: implemented viaremoveTrailingForwardSlash. The unit test named for this mode only checks a source that has no slash to begin with, so the strip branch is never exercised.'ignore' unchanged: satisfied.
Review Status
Verdict: changes required
Context: PR #18085 (title and description). I could not open the linked issue #18073.
Scope: PR base db2eaf17 to head b5b1d2fc (4 files).
Changeset: present and covers @astrojs/vercel (patch).
Limitations: I worked from memory of how @vercel/routing-utils handles trailingSlash and pathToRegexp; I did not read that package's source during this review.
Validation: Static review only; no project code, tests, builds, or checks were run.
GitHub context: collected
Git scope: PR base/head verified
This review was made by an LLM. The analysis may be wrong, and reports might be incorrect.
|
Addressed review: spread redirects are now adjusted like other sources (append trailing slash under |
|
Spread redirects are now adjusted under |
|
Requesting re-review from @astro-factory after spread-redirect fix. |
There was a problem hiding this comment.
Findings
[low][correctness]packages/integrations/vercel/src/lib/redirects.ts:143: Dotted static sources that aren't file extensions now get a slash appended that Vercel never adds to the request. Details are in the inline comment.
Merge Requirement Assessment
Status: gaps found
- With
trailingSlash: 'always', static redirect sources must match Vercel's normalized slashed path (#18073). Satisfied.adjustSourceForTrailingSlashappends/andgetRedirectsuses it. The fixture test expects^/one/$and similar, and the unit tests cover static and dynamic sources. - Spread sources must also match under
always. Satisfied. Spread sources are no longer skipped, and the unit test asserts/blog/:slug*/. The fixture test asserts the exact compiled regex, which ends in/$and matches both/blog/and/blog/a/b/. - The root and file-extension paths must stay unchanged. Mostly satisfied. One mismatch with Vercel's normalization remains for dotted segments (see the finding).
- With
never, trailing slashes must be stripped (except the root); withignore, sources stay unchanged. Implemented.getMatchPatternnever emits a trailing slash, so stripping only matters whenbaseitself ends with a slash.
Prior threads
- The spread-redirect thread is addressed. Spread routes now get a trailing slash, and both the JSDoc and the changeset describe this correctly.
Review Status
Verdict: changes required
Context: PR #18085 plus linked issue #18073 (from the PR body)
Scope: base db2eaf17 to head 33dc41b3, 4 files.
Changeset: present and covers @astrojs/vercel (patch).
Limitations: I checked Vercel routing-utils trailing-slash behavior against the regex in the earlier review thread, not against the dependency source.
Validation: Static review only. I did not run project code, tests, builds or checks.
GitHub context: collected
Git scope: PR base/head verified
This review was made by an LLM. The analysis may be wrong, and reports might be incorrect.
There was a problem hiding this comment.
Verdict: changes requested.
Findings
One new issue is posted inline: with trailingSlash: 'always', dynamic and spread redirect sources now always end in a hard-coded /, so they stop matching request paths whose last segment contains a dot.
The earlier thread about dotted static sources (hasFileExtension vs. Vercel's dot rule) is still open. The head commit hasn't changed and line 143 still uses hasFileExtension. I'm not repeating it here.
Merge Requirement Assessment
Status: gaps found
- Redirects match on Vercel with
trailingSlash: 'always'(#18073). Met for plain static sources.getRedirectsnow runs sources throughadjustSourceForTrailingSlash, which produces^/old/$. The fixture integration test and the new unit tests cover this. Two gaps remain: dotted static sources (the open thread) and dotted request paths for dynamic or spread sources (the inline finding). trailingSlash: 'never'sources have no trailing slash. Met. A trailing slash is removed except on the root. The only source that can end in/is a root redirect under a non-rootbase.ignoreis unchanged. Met, and covered by a unit test.- PR description vs. code. The description says spread routes are excluded from the slash, but the code and its doc comment deliberately add the slash to spread sources. The tests and changeset follow the code, not the description.
Review Status
- Verdict: changes required
- Context: PR #18085, plus its linked issue #18073 as described in the PR body
- Scope: PR base
db2eaf17to head33dc41b3(4 files) - Changeset: present and covers
@astrojs/vercel(patch) - Limitations: I didn't read the issue thread separately. Vercel routing behavior comes from
@vercel/routing-utilssemantics, not from running it. - Validation: Static review only. I didn't run any project code, tests, builds or checks.
- GitHub context: collected
- Git scope: PR base/head verified
This review was made by an LLM. The analysis may be wrong, and reports might be incorrect.
…rects Vercel's normalizer only appends a slash when the last segment has no dot, so a dotted source must stay unslashed and a dynamic or spread last segment has to match both forms. Verified against @vercel/routing-utils output.
|
Both open findings from the What changed
Verification
I confirmed the regexes above by compiling candidate sources through Re-requesting review. |
eslint's regexp/no-super-linear-backtracking rejects the two overlapping [^/]* quantifiers; anchoring on the last dot is equivalent and linear.
|
One follow-up: the previous head (
|
There was a problem hiding this comment.
Verdict: approved. No blocking findings remain.
Findings
No findings.
Merge Requirement Assessment
Status: satisfied
- With
trailingSlash: 'always', static redirect sources match Vercel's normalized slashed path (#18073).adjustSourceForTrailingSlashadds a trailing slash to static sources. The root path, already-slashed sources and sources whose last segment contains a dot are left as they are. Vercel'strailingSlash: trueredirect runs before user redirects and only slashes a path when its last segment has no dot (^/((?:[^/]+/)*[^/\.]+)$), and the dot check uses the same rule. The fixture test now expects^/one/$and similar, and the unit tests intest/units/redirects.test.tscover static, root, dotted and file-extension sources. - Dynamic and spread sources still match whether or not Vercel adds a slash. When
trailingSlashis'always',getRedirectsemits both a slashed and an unslashed rule for sources that end in a dynamic segment. The destination and status code are kept on both rules. Unit tests and the fixture assertions on both^/blog...regexes check this. 'never'and'ignore'keep working.'never'strips a trailing slash, except at the root.'ignore'leaves sources unchanged. Unit tests cover both.
Prior threads
- Dotted non-extension sources: addressed. The check is now
LAST_SEGMENT_HAS_DOT(/\.[^/]*$/), which follows Vercel's rule./release-1.0-betais covered by both a unit test and a fixture test. - Dynamic or spread sources and dotted request values: addressed. Sources ending in a dynamic segment now get both a slashed and an unslashed rule, so
/blog/post.htmlstill matches the unslashed spread rule.
Review Status
Verdict: ready to merge based on static review
Context: PR #18085 plus its linked issue #18073 (as described in the PR body)
Scope: PR base db2eaf17 to head ab47c824.
Changeset: present and covers @astrojs/vercel (patch).
Limitations: The PR body is slightly out of date. It mentions excluding spread routes, but the code now emits both forms for them. This doesn't block the merge. Vercel's route ordering was checked against the documented behavior of @vercel/routing-utils; this review didn't read that package's source.
Validation: Static review only. No project code, tests, builds or checks were run.
GitHub context: collected
Git scope: PR base/head verified
This review was made by an LLM. The analysis may be wrong, and reports might be incorrect.
* Fix corrupted `astro:env/server` module when env vars contain `$` replacement patterns (#18330) * [ci] format * Fix inlined Vue styles in dev serving untransformed (unscoped, raw v-bind) CSS (#18336) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(deps): update vitest monorepo to v5 (#18403) Co-authored-by: Florian Lefebvre <[email protected]> * Update Partytown to 1.0.1 (#18439) * fix(cloudflare): return 4xx instead of 500 from `/_image` when the source isn't an image (#18422) Co-authored-by: Claude Opus 5.5 <[email protected]> * Skip server island manifest in CSS ensureModulesLoaded to fix late-discovery 500 in dev (#18399) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Fix astro-check binary silently dropping the first two CLI arguments (#18455) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Preserve sharpImageService() options when imageService: 'compile' is used in the Cloudflare adapter (#18461) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(check): skip Volar's cancellation polling sleep in `astro check` (#18460) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(content): compute UTF-8 width arithmetically in getChunkEnd (#18430) * fix(content): compute UTF-8 width arithmetically in getChunkEnd * test(content): cover UTF-8 width boundaries and lone surrogates in chunkString * chore: changeset * fix(cloudflare): don't prebundle Astro in the Node prerender environment so a custom src/fetch.ts renders through the dev environment (#18465) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Respect exact version argument in @astrojs/upgrade (#18466) * fix(upgrade): respect exact version argument in @astrojs/upgrade * fix(upgrade): only pin exact version for the astro package Integrations are versioned independently, so a published version string matching the requested Astro version must not be used for them; they keep the dist-tag/latest fallback instead of being downgraded. --------- Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(i18n): use locale path instead of codes in defineConfig i18n types (#18467) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(cloudflare): skip Prism optimizeDeps include during type generation so sync/check/build don't overwrite a running dev server's deps_ssr (#18468) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Use a separate Vite cache for the temporary sync server (#18451) `astro sync`, which `astro check` and `astro build` also run, starts a temporary Vite server with `optimizeDeps: { noDiscovery: true }`. Astro and integrations still add `optimizeDeps.include` entries, so Vite keeps the dependency optimizer running there, and it wrote to the default Vite cache. That replaced the optimized dependencies of a dev server running in the same project, so framework islands in that dev server broke (for example React's production `jsx-dev-runtime`, where `jsxDEV` is undefined) until it was restarted with `--force`. The temporary server now writes to `<cacheDir>/vite-sync/`. It optimizes the same dependencies as before; only the output location changes. Fixes #18449 Tested: `astro-sync.test.ts` passes 10/10; the new test fails without the change in `sync/index.ts`. * fix(dev): treat missing ps row as stale in lockfile process check (#18376) Co-authored-by: Princesseuh <[email protected]> * fix(astro): stop excluding node-fetch from server dep optimization in workerd dev (#18438) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Update dependency @playwright/test to v1.64.1 (#18441) * Update @astrojs/node (#18440) * Close duplicate pull requests when an issue is fixed (#18472) * fix: minimal support node version (#18475) * [ci] release (#18459) * Fix release workflow package list after the Changesets v3 upgrade (#18104) Co-authored-by: Chris Swithinbank <[email protected]> Co-authored-by: Armand Philippot <[email protected]> * Fix DataCloneError when importing SVGs with parallelPrerender enabled (#18476) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> Co-authored-by: Princesseuh <[email protected]> * fix(telemetry): look up the project ID without blocking (#18481) * Skip CSP hashes for external stylesheets and scripts. (#18488) * [ci] format * fix(astro): allow Node.js >=22.22.0 on StackBlitz WebContainers (#18494) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(assets): dedupe equivalent densities in image srcset (#18500) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * docs: update legacy flags JSDocs to generate their reference in docs (#18378) Co-authored-by: ematipico <[email protected]> * Restore scroll position instantly on back/forward navigation when smooth scrolling is enabled (#18506) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(transitions): silence ready rejection before skipTransition in ClientRouter (#18517) * Merge commit from fork * ci: pass issue author login to needs-repro step via env (#18518) * Restore CSS tree-shaking for unused barrel-imported Astro components (#18493) * Mark $$createComponent pure so unused barrel-exported components drop their scoped CSS * Bump Vite to 8.3.5 (Rolldown 1.2.15) and exercise the image service at runtime in the Sharp test Rolldown 1.2.13 could fold its runtime helpers into a dynamically imported page chunk, making the SSR entry statically import (and eagerly evaluate) that page. Rolldown 1.2.14+ keeps the runtime out of entry chunks. With unused components tree-shaken, the Cloudflare worker only bundles the Sharp chain when an on-demand route uses the image service, so the Sharp test now makes api.ts call getImage(). --------- Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> Co-authored-by: Matthew Phillips <[email protected]> * Update @astrojs/markdoc (#18513) * fix(@astrojs/vercel): make redirects match when trailingSlash is always/never (#18085) * fix(@astrojs/vercel): make redirects match when trailingSlash is always/never * refactor(@astrojs/vercel): use path slash utilities in adjustSourceForTrailingSlash * fix(@astrojs/vercel): make spread redirects match under trailingSlash always * fix(@astrojs/vercel): match Vercel's dot rule for trailing-slash redirects Vercel's normalizer only appends a slash when the last segment has no dot, so a dotted source must stay unslashed and a dynamic or spread last segment has to match both forms. Verified against @vercel/routing-utils output. * fix(@astrojs/vercel): avoid super-linear backtracking in dot check eslint's regexp/no-super-linear-backtracking rejects the two overlapping [^/]* quantifiers; anchoring on the last dot is equivalent and linear. * fix(csp): include hashes inserted by body components in the CSP meta tag for non-streaming renders (#18512) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(server-islands): keep fallback instead of throwing when the island fetch fails (#18497) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(assets): avoid duplicate 1x candidate in Picture source srcset when densities includes 1 (#18504) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * [ci] format * fix(cloudflare): scope process.env define to server environments so client bundles get Vite's default replacement (#18526) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Fix type errors in shipped components under the `strictest` TypeScript preset (#18524) * Fix strictest tsc errors in shipped Image, Picture, Code, Debug and ClientRouter components * test(astro): type-check shipped components under strictest tsconfig Add an astro check fixture whose tsconfig extends astro/tsconfigs/strictest and includes node_modules/astro/components/*.astro, so the strictest errors from #18471 cannot come back without CI failing. --------- Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(cli): drop shell: true from astro info package manager calls to avoid DEP0190 warning (#18525) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Pass the React id prefix to `renderToString` when streaming is disabled (#18482) * fix(react): pass identifierPrefix to renderToString when streaming is disabled * test(react): give the disable-streaming fixture its own outDir * Merge commit from fork * Merge commit from fork * Fix transition:name styles silently dropped in dev when component is nested under a non-propagating component (#18511) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Prevent memory cache from storing empty 404/500 responses that would be rerouted to error pages (#18522) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * [ci] release (#18478) * astro add: configure tagged official adapters (#18344) Recognize resolved official package names when tagged specifiers are used so installation and Astro config updates stay aligned. Co-authored-by: Matthew Phillips <[email protected]> --------- Co-authored-by: Samuteg <[email protected]> Co-authored-by: Samuteg <[email protected]> Co-authored-by: astro-factory[bot] <316791938+astro-factory[bot]@users.noreply.github.com> Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Florian Lefebvre <[email protected]> Co-authored-by: Jack Hanford <[email protected]> Co-authored-by: Tim L. White <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Erika <[email protected]> Co-authored-by: Abhirup Pal <[email protected]> Co-authored-by: Denis Scarabelli <[email protected]> Co-authored-by: okxint <[email protected]> Co-authored-by: Emanuele Stoppa <[email protected]> Co-authored-by: Houston (Bot) <[email protected]> Co-authored-by: Chris Swithinbank <[email protected]> Co-authored-by: Armand Philippot <[email protected]> Co-authored-by: Muhammad Umer Aamir <[email protected]> Co-authored-by: ematipico <[email protected]> Co-authored-by: Nikolas Sapalidis <[email protected]> Co-authored-by: knj <[email protected]> Co-authored-by: Waleed Rostom 🐦⬛ <[email protected]> Co-authored-by: Edmund Hung <[email protected]>
Fixes #18073.
Problem
With
trailingSlash: 'always', Vercel normalizes/oldto/old/before redirects run, so an unslashed redirectsourcecould never match. (Symmetric edge:trailingSlash: 'never'sources with trailing slash never match.)Repro
Define a static redirect
/oldto/new/withtrailingSlash: 'always'; inspect generated Vercel config routes. Pre-fix:src: ^/old$(never matches normalized/old/); post-fix:src: ^/old/$.Solution
packages/integrations/vercel/src/lib/redirects.ts: new exportedadjustSourceForTrailingSlash(source, route, trailingSlash)wired intogetRedirects:always: append/except root (/), already-slashed, spread routes, file-extension paths.never: strip trailing/(except root).ignore: unchanged.Design choices
getMatchPatternuntouched.Tests
packages/integrations/vercel/test/units/redirects.test.ts: 7 pass vianode --test.test/redirects.test.tsexpectations;nft3 pass;tsc+biomeclean.@astrojs/vercel) added.Risks
Low-medium. Redirect
srcstrings change foralways/neverusers — intended fix, but anyone depending on the broken unslashed source will see route diff. No runtime API change.