You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(shop): concurrent optimistic cart mutations no longer flicker
When two cart mutations fired in quick succession (e.g. delete item A,
then delete item B before A settles), A's onSuccess would overwrite the
cache with the server response — which still contained B — undoing B's
optimistic removal and making it flash back for a frame.
Root cause: each mutation's onSuccess called setQueryData with the
server response, clobbering any other in-flight optimistic state.
Fix:
- Removed onSuccess/setQueryData from update/remove/add mutations.
Each onMutate already layers its change onto the current (possibly
already-optimistic) cache, which is the right state for the user to
see.
- Added a shared CART_MUTATION_KEY across all cart-mutating hooks.
- settleWhenIdle() checks isMutating({ mutationKey }) — only when the
count is 0 (meaning the current mutation is the last to settle) does
it invalidate the query, triggering a single background refetch that
reconciles all accumulated changes with server truth at once.
- Discount apply keeps onSuccess since it has no optimistic state
(it only adds information, never conflicts with other in-flight ops).
0 commit comments