Shopify / hydrogen

Hydrogen lets you build faster headless storefronts in less time, on Shopify.
https://hydrogen.shop
MIT License
1.4k stars 268 forks source link

Inconsitent cart items when using browser's back and forward navigation #1691

Open pkubwiraBixlers opened 9 months ago

pkubwiraBixlers commented 9 months ago

What is the location of your example repository?

https://hydrogen.shop/cart (shopify hydrogen demo store)

Which package or tool is having this issue?

Hydrogen

What version of that package or tool are you using?

Not sure

What version of Remix are you using?

Not sure

Steps to Reproduce

when you add an item to the bag and go to the "/cart" route and remove the item from cart (the number of items in the cart is 0) if you use the browser's navigation button to go back to the whatever page you were on before and then use the browser to go forward (going back to the cart route) the item you previously deleted will be there and you can repeat this process indefinitely.

Expected Behavior

the removed item should not be back in the cart when you use the browser to forward navigate back to the cart becaude it had already been removed.

Actual Behavior

item comes back in the cart after having been removed

michenly commented 5 months ago

Hi @pkubwiraBixlers sorry about the late reply.

The behaviour you are seeing is because pages (including /cart) are server rendered. The browser does not re-fetch the page from server when you are going back and forth in the navigation.

We are playing with some idea of how to make this feel less broken, but it does always come with some performance trade off.

Is there any reason why you need to use the /cart route specially? Your end user should mostly be un-aware of the /cart route unelss they have JS disabled & the user clicks on cart. By default Hydrogen uses the cart side drawer.

blittle commented 4 months ago

@juanpprieto this I think would be fixed by not SSR'ing the cart.