Commit 2080c4cbecd for woocommerce

commit 2080c4cbecd6c9e68ddb4a1acf9653996c56cc12
Author: Luigi Teschio <gigitux@gmail.com>
Date:   Fri May 29 07:54:14 2026 +0200

    Fix setting options core data locks (#65375)

    * Fix setting options core data locks

    * Fix setting options action types

    * Derive setting option lock types from core data

    * Avoid internal lock action types

    * improve types

diff --git a/packages/js/data/changelog/dev-setting-options-core-data-locks b/packages/js/data/changelog/dev-setting-options-core-data-locks
new file mode 100644
index 00000000000..9845c47d082
--- /dev/null
+++ b/packages/js/data/changelog/dev-setting-options-core-data-locks
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Setting options: register the core-data store in tests.
diff --git a/packages/js/data/src/setting-options/actions.ts b/packages/js/data/src/setting-options/actions.ts
index 2ebfeaac08c..ea324bc79dc 100644
--- a/packages/js/data/src/setting-options/actions.ts
+++ b/packages/js/data/src/setting-options/actions.ts
@@ -3,11 +3,7 @@
  */
 import apiFetch from '@wordpress/api-fetch';
 import type { createRegistry } from '@wordpress/data';
-import type { CurriedSelectorsOf } from '@wordpress/data/build-types/types';
-import type CreateLocksActions from '@wordpress/core-data/build-types/locks/actions';
-// @ts-expect-error WP core data doesn't explicitly export the actions
-// eslint-disable-next-line @woocommerce/dependency-group
-import createLocksActions from '@wordpress/core-data/build/locks/actions';
+import { store as coreDataStore } from '@wordpress/core-data';

 /**
  * Internal dependencies
@@ -24,9 +20,10 @@ import type {
 	SettingsState,
 } from './types';
 import { NAMESPACE } from '../constants';
-import { store, STORE_NAME } from './';
+import { STORE_NAME } from './';

 type WPDataRegistry = ReturnType< typeof createRegistry >;
+type Selectors = typeof import('./selectors');

 type CurriedState< F > = F extends (
 	state: SettingsState,
@@ -35,10 +32,21 @@ type CurriedState< F > = F extends (
 	? ( ...args: P ) => R
 	: F;

+type CurriedSelectors< T > = {
+	[ K in keyof T ]: CurriedState< T[ K ] >;
+};
+
 type Resolvers = typeof import('./resolvers');
+type CoreDataActions = ReturnType<
+	ReturnType< typeof coreDataStore.instantiate >[ 'getActions' ]
+>;
+type CoreDataLockDispatch = Pick<
+	CoreDataActions,
+	'__unstableAcquireStoreLock' | '__unstableReleaseStoreLock'
+>;

 export type ThunkArgs = {
-	select: CurriedSelectorsOf< typeof store >;
+	select: CurriedSelectors< Selectors >;
 	resolveSelect: CurriedState< Resolvers >;
 	dispatch: ActionDispatchersForThunk;
 	registry: WPDataRegistry;
@@ -413,13 +421,31 @@ export const saveEditedSetting =
 		return saveSettingRequest( groupId, settingId, value, dispatch );
 	};

-const lockActions = createLocksActions() as ReturnType<
-	typeof CreateLocksActions
+const getCoreDataLockDispatch = (
+	registry: WPDataRegistry
+): CoreDataLockDispatch =>
+	registry.dispatch( coreDataStore ) as CoreDataLockDispatch;
+
+type UnstableAcquireStoreLockParams = Parameters<
+	CoreDataLockDispatch[ '__unstableAcquireStoreLock' ]
 >;
+type UnstableReleaseStoreLockParams = Parameters<
+	CoreDataLockDispatch[ '__unstableReleaseStoreLock' ]
+>;
+
 export const __unstableAcquireStoreLock =
-	lockActions.__unstableAcquireStoreLock;
+	( ...args: UnstableAcquireStoreLockParams ) =>
+	( { registry }: ThunkArgs ) =>
+		getCoreDataLockDispatch( registry ).__unstableAcquireStoreLock(
+			...args
+		);
+
 export const __unstableReleaseStoreLock =
-	lockActions.__unstableReleaseStoreLock;
+	( ...args: UnstableReleaseStoreLockParams ) =>
+	( { registry }: ThunkArgs ) =>
+		getCoreDataLockDispatch( registry ).__unstableReleaseStoreLock(
+			...args
+		);

 // Return type of all action creators
 export type Actions = ReturnType<
@@ -446,5 +472,7 @@ export type ActionDispatchersForThunk = {
 	saveEditedSettingsGroup: typeof saveEditedSettingsGroup;
 	saveSetting: typeof saveSetting;
 	saveSettingsGroup: typeof saveSettingsGroup;
+	__unstableAcquireStoreLock: CoreDataLockDispatch[ '__unstableAcquireStoreLock' ];
+	__unstableReleaseStoreLock: CoreDataLockDispatch[ '__unstableReleaseStoreLock' ];
 	< T = Record< string, unknown > >( args: T ): void;
-} & ReturnType< typeof CreateLocksActions >;
+};
diff --git a/packages/js/data/src/setting-options/test/utils.ts b/packages/js/data/src/setting-options/test/utils.ts
index a7ac8b195c9..9a4d90ef6d6 100644
--- a/packages/js/data/src/setting-options/test/utils.ts
+++ b/packages/js/data/src/setting-options/test/utils.ts
@@ -3,6 +3,7 @@
  */
 import { createRegistry } from '@wordpress/data';
 import { controls } from '@wordpress/data-controls';
+import { store as coreDataStore } from '@wordpress/core-data';

 /**
  * Internal dependencies
@@ -13,15 +14,13 @@ import * as actions from '../actions';
 import reducer from '../reducer';
 import type { SettingsState } from '../types';
 import { Setting, SettingsGroup } from '../types';
-// @ts-expect-error WP core data doesn't explicitly export the actions
-// eslint-disable-next-line @woocommerce/dependency-group
-import createLocksActions from '@wordpress/core-data/build/locks/actions';

 /**
  * Creates a fresh registry and store for testing.
  */
 export const createTestRegistryAndStore = () => {
 	const registry = createRegistry();
+	registry.register( coreDataStore );

 	// Create initial state matching the reducer's initial state
 	const initialState: SettingsState = {
@@ -37,10 +36,7 @@ export const createTestRegistryAndStore = () => {

 	const store = registry.registerStore( STORE_NAME, {
 		reducer,
-		actions: {
-			...actions,
-			...createLocksActions(),
-		},
+		actions,
 		controls,
 		selectors,
 		initialState, // Pass initial state to ensure fresh state each time