cartLinesUpdate removes properties that are not being passed. #170
Replies: 3 comments
-
Was struggling for a long time trying to get this working, grateful I found this post to understand what's going on under the hood. Does anyone have a work around for it? |
Beta Was this translation helpful? Give feedback.
-
Hi @ogaguinaga - Thanks for bringing this to our attention. |
Beta Was this translation helpful? Give feedback.
-
Came across this issue today. Can we revisit this idea? @vixdug |
Beta Was this translation helpful? Give feedback.
-
There is currently an issue using
CartLineQuantityAdjustButton
when trying to increase or decrease the quantity of a specificcartLineItem
with an existingattributes
property. Currently it increases and decreases the quantity correctly but removes all other properties that were originally on thecartLine
. Here is a reproduction of this issue. In order to replicate follow the following steeps.attributes={[{key: 'Engraving', value: 'Hello world'}]}
After discussing this issue on the Discord channel with someone from the Shopify Hydrogen Team he was able to figure out the following:
CartLineQuantityAdjustButton
callslinesUpdate()
here https://github.com/Shopify/hydrogen/blob/767a4ac15c112324ab885863600e9329e1b1416d/packages/hydrogen/src/components/CartLineQuantityAdjustButton/CartLineQuantityAdjustButton.tsx#L36 and only passes in the ID and QuantityCartLineUpdate()
method here https://github.com/Shopify/hydrogen/blob/767a4ac15c112324ab885863600e9329e1b1416d/packages/hydrogen/src/components/CartProvider/CartActions.client.tsx#L122 and here https://github.com/Shopify/hydrogen/blob/767a4ac15c112324ab885863600e9329e1b1416d/packages/hydrogen/src/components/CartProvider/cart-queries.ts#L39cartLinesUpdate
mutation does not keep existing properties (such as attributes) if you don't pass them into the mutation. In this case, the component is only passing in the ID and Quantity, and not the Attributes, so those get lost as the quantity is updated.And as a solution he suggested to update the
cartLinesUpdate()
so that when you call it, it only updates what you pass to it and doesn't remove/delete things that you don't pass to it. Looking forward to hearing you opinion on this.Beta Was this translation helpful? Give feedback.
All reactions