Skip to content

Commit 030a099

Browse files
authored
fix: disregard presence/absence of trailing slash in prerendered redirect (#12966)
* fix: disregard presence/absence of trailing slash in prerendered redirect * handle edge case * tweak comment placement
1 parent 92b2686 commit 030a099

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

.changeset/seven-kangaroos-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-vercel': patch
3+
---
4+
5+
fix: disregard presence/absence of trailing slash in prerendered redirect

packages/adapter-vercel/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,17 @@ function static_vercel_config(builder, config, dir) {
444444
/** @type {import('./index.js').ImagesConfig | undefined} */
445445
const images = config.images;
446446

447-
for (const [src, redirect] of builder.prerendered.redirects) {
447+
for (let [src, redirect] of builder.prerendered.redirects) {
448+
if (src.replace(/\/$/, '') === redirect.location.replace(/\/$/, '')) {
449+
// ignore the extreme edge case of a `/foo` -> `/foo/` redirect,
450+
// which would only arise if the response was generated by a
451+
// `handle` hook or outside the app altogether (since you
452+
// can't declaratively create both routes)
453+
} else {
454+
// redirect both `/foo` and `/foo/` to `redirect.location`
455+
src = src.replace(/\/?$/, '/?');
456+
}
457+
448458
prerendered_redirects.push({
449459
src,
450460
headers: {

0 commit comments

Comments
 (0)