Skip to content

Commit 6ddaafa

Browse files
Cichorekclaude
andauthored
Fix guest checkout showing "Order not found" on order-placed page (#32)
Skip CartProvider's refreshCart() on the order-placed page to prevent a race condition where getCart() auto-clears the _spree_cart_token cookie before getCheckoutOrder() can use it. For guest users this token is the only authentication — once cleared, the API returns nothing and the confirmation page shows "Order not found." Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a5532e2 commit 6ddaafa

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/contexts/CartContext.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,17 @@ export function CartProvider({ children }: { children: ReactNode }) {
116116
);
117117

118118
// Re-fetch cart on navigation (e.g., after checkout completes, the stale
119-
// cart token will be cleared by getCart and the cart state will update)
120-
// biome-ignore lint/correctness/useExhaustiveDependencies: pathname triggers re-fetch on navigation
119+
// cart token will be cleared by getCart and the cart state will update).
120+
// On the order-placed page, skip refreshCart to avoid a race condition:
121+
// getCart() auto-clears the cart token cookie on error (completed order
122+
// is no longer a cart), which removes the only auth token guest users
123+
// have before getCheckoutOrder() can use it.
121124
useEffect(() => {
125+
if (pathname.includes("/order-placed/")) {
126+
setCart(null);
127+
setLoading(false);
128+
return;
129+
}
122130
refreshCart();
123131
}, [refreshCart, pathname]);
124132

0 commit comments

Comments
 (0)