-
Notifications
You must be signed in to change notification settings - Fork 281
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 storefrontRedirect
on soft navigations
#1880
Conversation
cc8ebc5
to
7f7c628
Compare
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
Also change redirect status code from 301 to 302
7f7c628
to
6733dad
Compare
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.
LGTM but I've left a couple of comments 👍
const redirectFrom = | ||
pathname + (filteredSearchParams ? '?' + isSoftNavigation : ''); |
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 think this is wrong? Isn't redirectFrom
getting ?true
here?
Maybe you meant pathname + (isSoftNavigation ? '?' + filteredSearchParams : '')
instead?
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.
Also, maybe we could simplify this to:
const url = new URL(request.url);
const isSoftNavigation = url.searchParams.has('_data');
url.searchParams.delete('_data');
const redirectFrom = url.toString().replace(url.origin, '');
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.
Hmmm, this is odd that it worked. I'm going to add to the unit tests and figure out why the API request didn't fail.
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.
It didn't fail my unit test because the test didn't have an extra query parameter. I added another test to verify that scenario.
'@shopify/hydrogen': patch | ||
--- | ||
|
||
Fix bug where `storefrontRedirect` would return an error on soft page navigations. Also change the redirect status code from 301 to 302. |
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.
Thinking about it, should we consider 301 => 302 a breaking change? 🤔 Maybe not...
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 argue it was a bug in the first place 🙈
* Fix `storefrontRedirect` on soft navigations Also change redirect status code from 301 to 302 * Add test and PR feedback
WHY are these changes introduced?
Fix
storefrontRedirect
on soft navigations (click a link in the app to transition to a route that has a redirect). Also change the redirect status code from 301 to 302. 302 is not permanent and safer.WHAT is this pull request doing?
_data
search parameter when querying if a redirect exists.HOW to test your changes?
<Link to="/doesNotExist?return_to=%2Fcollections">Redirect</Link>
/collections
.Post-merge steps
Checklist