Commit 7ee3a6111e for woocommerce
commit 7ee3a6111e274fd48fa82cbd18b056aacea7d9d5
Author: Sam Seay <samueljseay@gmail.com>
Date: Tue Jan 13 16:11:26 2026 +1300
Only GET requests are cached, so passing the no-store header to POST requests is redundant (#62615)
diff --git a/plugins/woocommerce/changelog/62615-dev-only-avoid-cache-on-get-request b/plugins/woocommerce/changelog/62615-dev-only-avoid-cache-on-get-request
new file mode 100644
index 0000000000..187274ab9b
--- /dev/null
+++ b/plugins/woocommerce/changelog/62615-dev-only-avoid-cache-on-get-request
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Only apply no-store header to GET request of Mini Cart store.
\ No newline at end of file
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/stores/woocommerce/cart.ts b/plugins/woocommerce/client/blocks/assets/js/base/stores/woocommerce/cart.ts
index f8f070ae8f..e9cd40c251 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/stores/woocommerce/cart.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/base/stores/woocommerce/cart.ts
@@ -270,7 +270,6 @@ const { state, actions } = store< Store >(
`${ state.restUrl }wc/store/v1/cart/remove-item`,
{
method: 'POST',
- cache: 'no-store',
headers: {
Nonce: state.nonce,
'Content-Type': 'application/json',
@@ -366,7 +365,6 @@ const { state, actions } = store< Store >(
`${ state.restUrl }wc/store/v1/cart/${ endpoint }`,
{
method: 'POST',
- cache: 'no-store',
headers: {
Nonce: state.nonce,
'Content-Type': 'application/json',
@@ -451,7 +449,6 @@ const { state, actions } = store< Store >(
return {
method: 'POST',
path: `/wc/store/v1/cart/update-item`,
- cache: 'no-store',
headers: {
Nonce: state.nonce,
'Content-Type': 'application/json',
@@ -480,7 +477,6 @@ const { state, actions } = store< Store >(
return {
method: 'POST',
path: `/wc/store/v1/cart/add-item`,
- cache: 'no-store',
headers: {
Nonce: state.nonce,
'Content-Type': 'application/json',
@@ -493,7 +489,6 @@ const { state, actions } = store< Store >(
`${ state.restUrl }wc/store/v1/batch`,
{
method: 'POST',
- cache: 'no-store',
headers: {
Nonce: state.nonce,
'Content-Type': 'application/json',
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/stores/woocommerce/test/cart.ts b/plugins/woocommerce/client/blocks/assets/js/base/stores/woocommerce/test/cart.ts
new file mode 100644
index 0000000000..4f5384d861
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/js/base/stores/woocommerce/test/cart.ts
@@ -0,0 +1,59 @@
+/**
+ * Internal dependencies
+ */
+import type { Store } from '../cart';
+
+type MockStore = { state: Store[ 'state' ]; actions: Store[ 'actions' ] };
+
+let mockRegisteredStore: MockStore | null = null;
+const mockState = {
+ restUrl: 'https://example.com/wp-json/',
+ nonce: 'test-nonce-123',
+} as Store[ 'state' ];
+
+jest.mock(
+ '@wordpress/interactivity',
+ () => ( {
+ getConfig: jest.fn(),
+ store: jest.fn( ( _name, definition ) => {
+ mockRegisteredStore = {
+ state: mockState,
+ actions: definition.actions,
+ };
+ return mockRegisteredStore;
+ } ),
+ } ),
+ { virtual: true }
+);
+
+jest.mock( '../legacy-events', () => ( {
+ triggerAddedToCartEvent: jest.fn(),
+} ) );
+
+describe( 'WooCommerce Cart Interactivity API Store', () => {
+ it( 'refreshCartItems passes cache: no-store to fetch to prevent browser caching', () => {
+ const mockFetch = jest
+ .fn()
+ .mockResolvedValue(
+ new Response(
+ JSON.stringify( { items: [], totals: {}, errors: [] } )
+ )
+ );
+ global.fetch = mockFetch;
+
+ jest.isolateModules( () => require( '../cart' ) );
+
+ const iterator = mockRegisteredStore?.actions.refreshCartItems();
+
+ // Async actions are typed as void for consumers, but are actually generators internally.
+ ( iterator as unknown as Iterator< void > ).next();
+
+ expect( mockFetch ).toHaveBeenCalledWith(
+ 'https://example.com/wp-json/wc/store/v1/cart',
+ expect.objectContaining( {
+ method: 'GET',
+ cache: 'no-store',
+ } )
+ );
+ } );
+} );