Skip to content

Commit 24d26ad

Browse files
fredericookdaviduik
authored andcommitted
chore: document updated cartDeliveryAddressesUpdate empty array behavior
1 parent cd65345 commit 24d26ad

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
'@shopify/hydrogen': patch
3+
---
4+
5+
`cart.updateDeliveryAddresses` mutation now clears all delivery addresses when passed an empty array
6+
7+
## Breaking Behavior Change in Storefront API 2025-10
8+
9+
The `cartDeliveryAddressesUpdate` mutation now clears all delivery addresses when passed an empty array. This behavior was undefined in previous API versions.
10+
11+
## What Changed
12+
13+
**Before (API ≤ 2025-07):**
14+
Passing an empty array did not update any addresses, essentially a no-op.
15+
16+
**After (API ≥ 2025-10):**
17+
Passing an empty array explicitly clears all delivery addresses from the cart.
18+
19+
## Usage
20+
21+
```typescript
22+
context.cart.updateDeliveryAddresses([])
23+
```
24+
25+
## Migration
26+
27+
If you are relying on `cart.updateDeliveryAddresses([])` in your codebase, verify if the new behavior is compatible with your expectations.
28+
29+
Otherwise, no migration is required.

packages/hydrogen/src/cart/queries/cartDeliveryAddressesUpdateDefault.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,15 @@ describe('cartDeliveryAddressesUpdateDefault', () => {
2727
expect(result.cart).toHaveProperty('id', CART_ID);
2828
expect(result.userErrors?.[0]).toContain(cartFragment);
2929
});
30+
31+
it('should erase all addresses when passing an empty array', async () => {
32+
const updateDeliveryAddresses = cartDeliveryAddressesUpdateDefault({
33+
storefront: mockCreateStorefrontClient(),
34+
getCartId: () => CART_ID,
35+
});
36+
37+
const result = await updateDeliveryAddresses([]);
38+
39+
expect(result.cart).toHaveProperty('id', CART_ID);
40+
});
3041
});

packages/hydrogen/src/cart/queries/cartDeliveryAddressesUpdateDefault.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ export type CartDeliveryAddressesUpdateFunction = (
2020
/**
2121
* Updates delivery addresses in the cart.
2222
*
23-
* This function sends a mutation to the storefront API to update one or more delivery addresses in the cart.
24-
* It returns the result of the mutation, including any errors that occurred.
23+
* Pass an empty array to clear all delivery addresses from the cart.
2524
*
2625
* @param {CartQueryOptions} options - The options for the cart query, including the storefront API client and cart fragment.
2726
* @returns {CartDeliveryAddressUpdateFunction} - A function that takes an array of addresses and optional parameters, and returns the result of the API call.
2827
*
29-
* @example
28+
* @example Clear all delivery addresses
3029
* const updateAddresses = cartDeliveryAddressesUpdateDefault(cartQueryOptions);
31-
* const result = await updateAddresses([
30+
* await updateAddresses([]);
31+
*
32+
* @example Update specific delivery addresses
33+
* const updateAddresses = cartDeliveryAddressesUpdateDefault(cartQueryOptions);
34+
* await updateAddresses([
3235
{
3336
"address": {
3437
"copyFromCustomerAddressId": "gid://shopify/<objectName>/10079785100",

0 commit comments

Comments
 (0)