From 4398b7faa863e8fb794d839836cf758e5d7e8c7f Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Wed, 18 Feb 2026 10:01:33 +0100 Subject: [PATCH 1/2] [TypeScript] Fix ReferenceManyField queryOptions type doesn't support error and success callbacks --- .../field/ReferenceManyFieldBase.stories.tsx | 27 +++++++++++++++++++ .../field/useReferenceManyFieldController.ts | 13 ++++----- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/packages/ra-core/src/controller/field/ReferenceManyFieldBase.stories.tsx b/packages/ra-core/src/controller/field/ReferenceManyFieldBase.stories.tsx index 78c8142bf4f..af6b4d3f684 100644 --- a/packages/ra-core/src/controller/field/ReferenceManyFieldBase.stories.tsx +++ b/packages/ra-core/src/controller/field/ReferenceManyFieldBase.stories.tsx @@ -414,3 +414,30 @@ const AuthorList = ({ source }) => {

); }; + +// test queryOptions type, it should support onSuccess and onError +export const QueryOptions = () => ( + + + + + console.log('Query successful'), + onError: () => console.log('Query failed'), + }} + > + + + + } + /> + + +); diff --git a/packages/ra-core/src/controller/field/useReferenceManyFieldController.ts b/packages/ra-core/src/controller/field/useReferenceManyFieldController.ts index 5548ba1a728..fa7a0a2c5a5 100644 --- a/packages/ra-core/src/controller/field/useReferenceManyFieldController.ts +++ b/packages/ra-core/src/controller/field/useReferenceManyFieldController.ts @@ -5,7 +5,11 @@ import isEqual from 'lodash/isEqual.js'; import lodashDebounce from 'lodash/debounce.js'; import { removeEmpty, useEvent } from '../../util'; -import { useDataProvider, useGetManyReference } from '../../dataProvider'; +import { + useDataProvider, + useGetManyReference, + UseGetManyReferenceHookOptions, +} from '../../dataProvider'; import { useNotify } from '../../notification'; import { Exporter, @@ -359,7 +363,7 @@ export const useReferenceManyFieldController = < export interface UseReferenceManyFieldControllerParams< RecordType extends Record = Record, - ReferenceRecordType extends Record = Record, + ReferenceRecordType extends RaRecord = any, ErrorType = Error, > { debounce?: number; @@ -375,10 +379,7 @@ export interface UseReferenceManyFieldControllerParams< storeKey?: string; target: string; queryOptions?: Omit< - UseQueryOptions< - { data: ReferenceRecordType[]; total: number }, - ErrorType - >, + UseGetManyReferenceHookOptions, 'queryKey' | 'queryFn' >; } From b0ba0b0dde6b77505b72c3ee6599d862ab1220cd Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Wed, 18 Feb 2026 15:31:13 +0100 Subject: [PATCH 2/2] Add argtype to allow testing error case --- .../field/ReferenceManyFieldBase.stories.tsx | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/ra-core/src/controller/field/ReferenceManyFieldBase.stories.tsx b/packages/ra-core/src/controller/field/ReferenceManyFieldBase.stories.tsx index af6b4d3f684..1f7f8a74b24 100644 --- a/packages/ra-core/src/controller/field/ReferenceManyFieldBase.stories.tsx +++ b/packages/ra-core/src/controller/field/ReferenceManyFieldBase.stories.tsx @@ -416,9 +416,9 @@ const AuthorList = ({ source }) => { }; // test queryOptions type, it should support onSuccess and onError -export const QueryOptions = () => ( +export const QueryOptions = ({ dataProvider }) => ( - + ( onSuccess: () => console.log('Query successful'), onError: () => console.log('Query failed'), + retry: false, }} > @@ -441,3 +442,18 @@ export const QueryOptions = () => ( ); + +QueryOptions.args = { + dataProvider: dataProviderWithAuthors, +}; + +QueryOptions.argTypes = { + dataProvider: { + control: { type: 'radio' }, + options: ['No error', 'With Error'], + mapping: { + 'No error': dataProviderWithAuthors, + 'With Error': dataProviderWithAuthorsError, + }, + }, +};