Skip to content

Commit

Permalink
BuyNowButton always redirects to checkout when cart is not empty (#827)
Browse files Browse the repository at this point in the history
* Fix 2023 01 (#807)

* Revert "Support optional segments in `check routes` CLI command (#774)"

This reverts commit 2039a4a.

* update package.lock

* Fix demo store search action url (#802)

* Fixing #825

* Add loading dependency to redirect effect

* Revert "Fix 2023 01 (#807)"

This reverts commit 53e6dbf.

* Revert "Fix demo store search action url (#802)"

This reverts commit a783b42.

* add a changeset

---------

Co-authored-by: Daniel Rios <daniel.riospavia@shopify.com>
Co-authored-by: Ós <zeptok@gmail.com>
Co-authored-by: Anthony Frehner <frehner@users.noreply.github.com>
  • Loading branch information
4 people committed May 17, 2023
1 parent 112ac42 commit 2e1e459
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-jokes-bathe.md
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen-react': patch
---

Fix issue where the `<BuyNowButton/>` would incorrectly redirect to checkout when React re-renders in certain situations.
4 changes: 2 additions & 2 deletions packages/hydrogen-react/src/BuyNowButton.tsx
Expand Up @@ -41,10 +41,10 @@ export function BuyNowButton<AsType extends React.ElementType = 'button'>(
} = props;

useEffect(() => {
if (checkoutUrl) {
if (loading && checkoutUrl) {
window.location.href = checkoutUrl;
}
}, [checkoutUrl]);
}, [loading, checkoutUrl]);

const handleBuyNow = useCallback(() => {
setLoading(true);
Expand Down

0 comments on commit 2e1e459

Please sign in to comment.