-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: disregard presence/absence of trailing slash in prerendered redirect #12966
Conversation
🦋 Changeset detectedLatest commit: ad68def 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 |
packages/adapter-vercel/index.js
Outdated
@@ -446,7 +446,7 @@ function static_vercel_config(builder, config, dir) { | |||
|
|||
for (const [src, redirect] of builder.prerendered.redirects) { | |||
prerendered_redirects.push({ | |||
src, | |||
src: src.replace(/\/?$/, '/?'), | |||
headers: { | |||
Location: redirect.location |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance that the redirect location is the same except the trailing slash, in which case this would create an infinite loop? Maybe we should double-check that before applying the /?
replacement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super edge case, since you can't create a /foo
route alongside a /foo/
route (best you could do is /foo
alongside /[blah]/
, but one would match over the other). But I guess you could do something wacky with a handle
hook or a custom server, and it does indeed create an infinite loop. Pushed some code to handle that case
packages/adapter-vercel/index.js
Outdated
for (const [src, redirect] of builder.prerendered.redirects) { | ||
for (let [src, redirect] of builder.prerendered.redirects) { | ||
if (src.replace(/\/$/, '') !== redirect.location.replace(/\/$/, '')) { | ||
// handle the extreme edge case of a `/foo` -> `/foo/` redirect, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on mobile, so maybe I'm just misreading, but I feel like this comment should apply to the if
statement rather than this line
This line could probably use a different comment about disregarding the presence/absence of trailing slash in prerendered redirect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah the position of the comment is tricky because even if it's outside the if
it looks like it's describing what happens inside rather than when you don't get there
fixed slightly unconventionally: inverted the condition and made the antecedent a no-op, just the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol. that works
I probably would have done it by changing the wording to something like "only apply if we're not hitting the extreme edge case of..."
but I guess I'm happy with this too. maybe the bundler will make them the same anyway 😆
closes #12869. With this change, if the prerenderer encounters a redirect when rendering
/foo
, the resulting entry invercel.json
will have asrc
of/foo/?
rather than/foo
or/foo/
.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits