Skip to content
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

Merged
merged 2 commits into from
Jul 5, 2023

Conversation

andyg0808
Copy link
Contributor

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

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.
@vercel
Copy link

vercel bot commented Jul 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-commerce ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2023 9:42pm
react-commerce-prod ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2023 9:42pm

@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2023

📦 Next.js Bundle Analysis for @ifixit/commerce-frontend

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

jarstelfox
jarstelfox previously approved these changes Jul 3, 2023
Copy link
Contributor

@jarstelfox jarstelfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR 🌵

@deltuh-vee deltuh-vee self-assigned this Jul 3, 2023
@deltuh-vee deltuh-vee added the QAing Under QA team review label Jul 3, 2023

if (context.resolvedUrl !== canonicalUrl.pathname.toString()) {
return {
redirect: {
destination: canonicalUrl.toString(),
Copy link
Member

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.

Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Member

@danielbeardsley danielbeardsley left a 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.

@deltuh-vee
Copy link
Contributor

QA 🎬
Redirects are still working in react-commerce. I think we'll have to check this once it's merged to see if the redirects are working again in cominor.

@deltuh-vee deltuh-vee removed the QAing Under QA team review label Jul 3, 2023
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.
@andyg0808 andyg0808 force-pushed the troubleshooting--fix-canonical-redirects branch from 19c7488 to 1542d4f Compare July 3, 2023 21:37
@andyg0808
Copy link
Contributor Author

Sorry for force-push; it was only to amend the last commit to include the correct query string.

@andyg0808
Copy link
Contributor Author

un_dev_block 👍
@danielbeardsley, thanks for the catch! I think that's fixed now.

Copy link
Contributor

@jarstelfox jarstelfox left a 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

@erinemay
Copy link
Contributor

erinemay commented Jul 5, 2023

QA 🦖
On this branch, /Vulcan/Dryer_Not_Spinning is redirected to /Vulcan/Dryer%20Not%20Spinning in production and dev links, but it is on main as well. Will need to check on cominor after merge.

@erinemay erinemay removed the QAing Under QA team review label Jul 5, 2023
@jarstelfox jarstelfox merged commit 6fc887e into main Jul 5, 2023
13 checks passed
@jarstelfox jarstelfox deleted the troubleshooting--fix-canonical-redirects branch July 5, 2023 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants