Many requests when changing quantity in cart
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:
- Add a product to the cart
- Open the cart page with the network inspector attached
- Click 10 times in quick succession on the plus-button to increase the quantity to 11
- 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
Hi @jpboskdnz, debouncing this action seems like a good optimization! Is it something you'd want to contribute?
Hi @migueloller, I wish I could, but I'm not a Next.js/frontend developer unfortunately.
No worries @jpboskdnz! I'll have the team look into it.
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