Title: applyCartLinesChange
succeeds but cart doesn’t update reliably when shipping country changes — possible conflict with auto-focus on checkout fields
Body:
Hi Shopify Devs,
I’ve built a Checkout UI Extension that dynamically adds/removes deposit products based on the shipping country selected during checkout. Here’s a quick rundown of what the extension does:
- Listens for
shippingAddress
changes viauseShippingAddress()
. - On a valid
countryCode
change, runs logic to:- Remove deposit-related products not needed for that region.
- Add region-specific deposit products using
applyCartLinesChange
.
The behavior was rock-solid during development. Even now its completely intact But recently — and only intermittently — when I change the shipping country using the country dropdown, Shopify auto-focuses the Postal Code or City field, and that somehow disrupts my extension’s cart modification logic.
Again, this only happens when Zip Code field gets auto focused, Like in 2 out of 10 attempts which proves my logic was and still is okay unless the Auto-Focus on Zipe code field happens when shipping country changed.
Symptoms:
applyCartLinesChange()
resolves successfully (verified in logs and DevTools network tab withsuccess
response).- But the cart does not reflect the changes (no line added/removed).
- This only happens sometimes, and strangely, adding a delay using
setTimeout
(400–500ms) reduces but does not eliminate the issue. In this case the Auto-focus on Zip code maybe gets suppressed on most attempts but this isn’t a sufficient solution. - There are no errors from the extension code or hook invocations.
What I’ve Tried:
- Verified
applyCartLinesChange
response is{ status: "success" }
. - Verified network tab on the operations and the response is
status = 200
when the Auto focus thing happen.
Theories:
- The auto-focus on postal code/city input might trigger a checkout re-render that wipes/overrides the cart state shortly after my updates.
- Some internal debounce or batching of Shopify’s shipping updates might conflict with cart updates fired too soon.
Questions:
- Is this auto-focus behavior intentional or recently introduced?
- Is there a recommended pattern to queue or delay cart modifications safely after country updates?
- Are there lifecycle hooks or callbacks we can rely on to detect when the Shopify checkout has “settled” post-country-change?
- Can
applyCartLinesChange()
be “cancelled” silently if another re-render or input focus event happens soon after?
Any advice, patterns, or insights from the team or community would be incredibly helpful!
Thanks in advance!