diff --git a/plugins/woocommerce-blocks/assets/js/base/hooks/cart/test/use-store-cart-item-quantity.js b/plugins/woocommerce-blocks/assets/js/base/hooks/cart/test/use-store-cart-item-quantity.js index b4408d1835b..01347b9dbc8 100644 --- a/plugins/woocommerce-blocks/assets/js/base/hooks/cart/test/use-store-cart-item-quantity.js +++ b/plugins/woocommerce-blocks/assets/js/base/hooks/cart/test/use-store-cart-item-quantity.js @@ -95,14 +95,14 @@ describe( 'useStoreCartItemQuantity', () => { ); } ); - const { changeQuantity, quantity } = renderer.root.findByType( + const { setItemQuantity, quantity } = renderer.root.findByType( 'div' ).props; expect( quantity ).toBe( 1 ); act( () => { - changeQuantity( 2 ); + setItemQuantity( 2 ); } ); const { quantity: newQuantity } = renderer.root.findByType( @@ -133,7 +133,7 @@ describe( 'useStoreCartItemQuantity', () => { expect( mockRemoveItemFromCart ).toHaveBeenCalledWith( '123' ); } ); - it( 'changeQuantity should call the dispatch action', () => { + it( 'setItemQuantity should call the dispatch action', () => { const TestComponent = getTestComponent( { key: '123', quantity: 1, @@ -145,10 +145,10 @@ describe( 'useStoreCartItemQuantity', () => { ); } ); - const { changeQuantity } = renderer.root.findByType( 'div' ).props; + const { setItemQuantity } = renderer.root.findByType( 'div' ).props; act( () => { - changeQuantity( 2 ); + setItemQuantity( 2 ); } ); expect( mockChangeCartItemQuantity.mock.calls ).toEqual( [ diff --git a/plugins/woocommerce-blocks/assets/js/base/hooks/cart/use-store-cart-item-quantity.ts b/plugins/woocommerce-blocks/assets/js/base/hooks/cart/use-store-cart-item-quantity.ts index 4786554c5cf..2512d2eebb5 100644 --- a/plugins/woocommerce-blocks/assets/js/base/hooks/cart/use-store-cart-item-quantity.ts +++ b/plugins/woocommerce-blocks/assets/js/base/hooks/cart/use-store-cart-item-quantity.ts @@ -68,7 +68,11 @@ export const useStoreCartItemQuantity = ( // Observe debounced quantity value, fire action to update server on change. useEffect( () => { - if ( cartItemKey && previousDebouncedQuantity !== debouncedQuantity ) { + if ( + cartItemKey && + Number.isFinite( previousDebouncedQuantity ) && + previousDebouncedQuantity !== debouncedQuantity + ) { changeCartItemQuantity( cartItemKey, debouncedQuantity ).then( triggerFragmentRefresh ); diff --git a/plugins/woocommerce-blocks/assets/js/type-defs/hooks.ts b/plugins/woocommerce-blocks/assets/js/type-defs/hooks.ts index 7577bd38026..4e02667c30f 100644 --- a/plugins/woocommerce-blocks/assets/js/type-defs/hooks.ts +++ b/plugins/woocommerce-blocks/assets/js/type-defs/hooks.ts @@ -16,7 +16,7 @@ import type { ResponseError } from '../data/types'; export interface StoreCartItemQuantity { isPendingDelete: boolean; quantity: number; - setItemQuantity: ( quantity: number ) => Promise< boolean >; + setItemQuantity: React.Dispatch< React.SetStateAction< number > >; removeItem: () => Promise< boolean >; cartItemQuantityErrors: Array< CartResponseErrorItem >; }