Skip to content

Commit

Permalink
fix: disregard presence/absence of trailing slash in prerendered redi…
Browse files Browse the repository at this point in the history
…rect (#12966)

* fix: disregard presence/absence of trailing slash in prerendered redirect

* handle edge case

* tweak comment placement
  • Loading branch information
Rich-Harris authored Nov 7, 2024
1 parent 92b2686 commit 030a099
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/seven-kangaroos-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': patch
---

fix: disregard presence/absence of trailing slash in prerendered redirect
12 changes: 11 additions & 1 deletion packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,17 @@ function static_vercel_config(builder, config, dir) {
/** @type {import('./index.js').ImagesConfig | undefined} */
const images = config.images;

for (const [src, redirect] of builder.prerendered.redirects) {
for (let [src, redirect] of builder.prerendered.redirects) {
if (src.replace(/\/$/, '') === redirect.location.replace(/\/$/, '')) {
// ignore the extreme edge case of a `/foo` -> `/foo/` redirect,
// which would only arise if the response was generated by a
// `handle` hook or outside the app altogether (since you
// can't declaratively create both routes)
} else {
// redirect both `/foo` and `/foo/` to `redirect.location`
src = src.replace(/\/?$/, '/?');
}

prerendered_redirects.push({
src,
headers: {
Expand Down

0 comments on commit 030a099

Please sign in to comment.