I’m developing a Shopify Checkout Extension and encountering a strange behavior when using useApplyCartLinesChange and useCartLines.
Problem Description:
-
What I’m doing:
- I’m using useApplyCartLinesChange to add a product to the cart when a button is clicked.
- useCartLines is used to retrieve the current cart line data.
-
What works:
- useCartLines correctly fetches the cart line data when the checkout page loads.
-
The issue:
- After calling useApplyCartLinesChange to update the cart (e.g., add a product), the cart updates for a moment, but then automatically reverts to the old state in useCartLines.
Expected Behavior:
- After useApplyCartLinesChange is called, useCartLines should reflect the updated cart state.
What I’ve Tried:
- Verified the logic for useApplyCartLinesChange.
- Ensured the product is successfully added to the cart (the UI briefly reflects the addition before reverting).
- Checked if any state management or caching is interfering.
Questions:
- Is there a specific mechanism required to sync useCartLines with the updated cart state after calling useApplyCartLinesChange?
- Could this be an issue with how Shopify propagates cart updates in the checkout extension?
Any insights, code samples, or documentation references would be greatly appreciated