-
Notifications
You must be signed in to change notification settings - Fork 0
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
Troubleshooting: Redirect to relative URL #1799
Conversation
The `Location` header supports relative URLs; let's use those to allow the browser to handle the protocol/host matching for the redirect. This code seems to have been causing weird redirect problems in prod; I'm not sure what's going wrong, but simplifying it seems to be a good first thing to try.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
📦 Next.js Bundle Analysis for @ifixit/commerce-frontendThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
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.
CR 🌵
|
||
if (context.resolvedUrl !== canonicalUrl.pathname.toString()) { | ||
return { | ||
redirect: { | ||
destination: canonicalUrl.toString(), |
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.
Before we perma-redirect, I think we need to compare the pathname to the pathname. It appears here that we're comparing the url (i.e. including query string) to the pathname. If we know that context.resolvedUrl
doesn't include the query string, then I'd suggest putting in a local const currentPathname = context.resolvedUrl
.
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.
You're right. I'd suggest turning both in to URL objects and comparing url.pathname
only (or explicitly checking the params as well)
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.
Oh, nice point. I'll switch that.
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.
CR 👍
While this change seems reasonable, I may see a problem in url redirection, so dev_block 👍 on looking into that.
QA 🎬 |
We were comparing the `resolvedUrl`, which we presume would include the query string, with the pathname of the `canonicalUrl` which doesn't. Now we extract just the pathname from the `resolvedUrl` and compare that. This also ensures that we include the query string from the current URL when we construct the target URL for the redirect, which I realized we were missing.
19c7488
to
1542d4f
Compare
Sorry for force-push; it was only to amend the last commit to include the correct query string. |
un_dev_block 👍 |
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.
CR 🌵 this sounds correct to me
QA 🦖 |
The
Location
header supports relative URLs; let's use those to allow the browser to handle the protocol/host matching for the redirect.This code seems to have been causing weird redirect problems in prod; I'm not sure what's going wrong, but simplifying it seems to be a good first thing to try.
Connects https://github.com/iFixit/ifixit/issues/48621