catalyst icon indicating copy to clipboard operation
catalyst copied to clipboard

Many requests when changing quantity in cart

Open jpboskdnz opened this issue 5 months ago • 4 comments

Describe the bug When you change the quantity in the cart using the plus and minus buttons, a request is sent to the /cart/ with every single click. This call isn’t particularly fast to begin with, and it becomes even more problematic when a large number of requests are sent in quick succession (see screenshot). Is this something that could be improved?

To Reproduce Steps to reproduce the behavior:

  1. Add a product to the cart
  2. Open the cart page with the network inspector attached
  3. Click 10 times in quick succession on the plus-button to increase the quantity to 11
  4. Check the network inspector: there are 10 requests to /cart/

Also reproduceable on https://catalyst-demo.site/.

Expected behavior When clicking in quick succession on the plus of minus button, I don't expect a direct request for each click. Instead, I expect a debounce, and only one request after some time (let's say 300-500ms).

Screenshots Image

jpboskdnz avatar Jul 10 '25 13:07 jpboskdnz

Hi @jpboskdnz, debouncing this action seems like a good optimization! Is it something you'd want to contribute?

migueloller avatar Jul 11 '25 13:07 migueloller

Hi @migueloller, I wish I could, but I'm not a Next.js/frontend developer unfortunately.

jpboskdnz avatar Jul 14 '25 07:07 jpboskdnz

No worries @jpboskdnz! I'll have the team look into it.

migueloller avatar Jul 14 '25 20:07 migueloller

Thanks for the report, @jpboskdnz! I have a POC available here with a potential fix. I've just got to clean up some of the code, but I hope to have a PR open soon to merge this into canary. I'll tag this issue in the PR so you are notified when the fix is merged. Thanks again!

https://github.com/user-attachments/assets/24a64320-c2d3-417c-bc44-af486110a3a2

matthewvolk avatar Jul 14 '25 23:07 matthewvolk