Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useOptimistic is highly ineffective for updating line items #1385

Open
sorenhoyer opened this issue Oct 14, 2024 · 0 comments
Open

useOptimistic is highly ineffective for updating line items #1385

sorenhoyer opened this issue Oct 14, 2024 · 0 comments

Comments

@sorenhoyer
Copy link

sorenhoyer commented Oct 14, 2024

I'm not sure why this has not been mentioned yet:

  • add an item to the cart
  • open the cart
  • increment the quantity count by clicking as fast as possible 50 times in a row
  • try to click outside the cart and navigate to another page

It'll take a while before navigation occurs (while the server actions is being processed).

useOptimistic is not great for incrementing quantity, as you can't easily debounce server actions as far as I know. Meaning if you click to increment quantity e.g. 50 times, you'll queue and execute 50 server actions after each other.

That can be reduced to just 1 server action call if you do it manually with useState and debounce of e.g. 300-400ms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant