Skip to content

Commit e5a8a55

Browse files
committed
Fix prefetched resources are not used by ReferenceField
## Problem `<ReferenceField>` relies on `getManyAggregate` to call the data provider. Each instance will call a `getMany(resource, [id])`, that react-admin will not pass to the data provider, -but aggregate into a single `getMany(resource, [id1, id2, id3])`. The prefetch feature pre-populates the `getMany(resource, [id1, id2, id3])` cache, but this isn't enough to prevent the actual data provider query. ## Solution Prefetched records should be used to populate the cache of *individual* getMany queries.
1 parent 3495c54 commit e5a8a55

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/ra-core/src/dataProvider/populateQueryCache.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ export const populateQueryCache = ({
3737
record,
3838
{ updatedAt }
3939
);
40+
queryClient.setQueryData(
41+
[resource, 'getMany', { ids: [String(record.id)] }],
42+
[record],
43+
{ updatedAt }
44+
);
4045
});
4146
const recordIds = data[resource].map(record => String(record.id));
4247
queryClient.setQueryData(

0 commit comments

Comments
 (0)