Skip to content

Commit 06fe4f7

Browse files
committed
fix(shop): cancel in-flight refetches on discount apply
1 parent a1ed746 commit 06fe4f7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/hooks/useCart.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ export function useApplyDiscountCode() {
185185
mutationKey: CART_MUTATION_KEY,
186186
mutationFn: (input: { code: string }) =>
187187
applyDiscountCode({ data: { code: input.code } }),
188+
onMutate: async () => {
189+
await qc.cancelQueries({ queryKey: CART_QUERY_KEY })
190+
},
188191
onSuccess: (cart) => {
189-
// Discount apply has no optimistic state, so setting server
190-
// response here is safe — it only adds information.
191192
qc.setQueryData(CART_QUERY_KEY, cart)
192193
},
193194
onSettled: () => settleWhenIdle(qc),

0 commit comments

Comments
 (0)