Cart clear Ajax API not always working (since Winter 25 Edition?)

We’ve recently seen a problem where clearing the cart through the AJAX API, then later adding to it, adds to the items that were in in the cart prior to the clear.

The behaviour is:

  • POST to /cart/clear.js returns a success and shows an empty cart
  • POST to /cart/add.js returns a success and shows the correct new items in the cart
  • GET to /cart.js returns a success and shows the correct new items AND the items previously in the cart

For more background:

  • It appeared to start around 10th December, which makes me think that it may be related to changes in Winter 25 Edition - I see there are various changes about speeding up the checkout, so not sure if it could be related to any of these?
  • We use a custom template on the /cart page - however do not use it as a traditional cart (as we essentially sell a single product but with different plans) - and instead when the user is ready to go to checkout, we clear the cart each time, then add their items, before proceeding
  • Because of this, it means we can see ‘impossible’ quantities of items in orders from around 10th Dec onwards - essentially people who we would have only ever added 1x item to a cleared basket, somehow having more than 1x
  • We’ve had this reported by end users as well as seeing it in the data (people going back and forth between cart and checkout, where the add takes place, but it only increasing and not being cleared)
  • It is not happening all the time, but only in a percentage of clears then adds - it’s maybe affecting about 5% of our related orders, but possibly could be happening to a higher % of people who do not complete ordering because of the problem
  • I’ve found it hard to reliably replicate the problem - the best I’ve managed is by having 2x checkout tabs open, navigating back in the browser in tab 1, then back in the browser in tab 2, then doing the clear > add > get in tab 1 (fine), then doing the clear > add > get in tab 2 after (sometimes, not always, gives the uncleared cart) - However this doesn’t seem to be the scenario for most users, its just I can’t easily replicate what they are seeing through a ‘normal’ progression through the cart
  • The AJAX ‘add’ call only happens after the success response of the ‘clear’ so shouldn’t be a race condition AFAIK
  • I’ve tried adding an additional /cart/clear.js on cart load, again to give plenty of time for the cart to be cleared prior to addition, but doesn’t appear to have helped

For further reference, we rely on some apps (notably Recharge, Mailchimp, and the Google and Facebook sales channels) which could have also updated around that time - I did wonder if some of them were pushing updates to the cart with line item properties (and getting the data to update before the clear) - but I haven’t been able to pinpoint it if it is the case.

Has anyone else had any similar problems? Or anyone have an idea of which changes might have caused a change in behaviour? Thank you!

Hi JDdev,

I’m not seeing reports of this internally - can you share some stores where this is happening? Are there any commonalities where this is happening - eg: only when products are bundles/ in selling plans, etc.