Skip to content

Commit 59c6470

Browse files
fix(core): forward custom getList response fields in result (#7372)
1 parent 62b2222 commit 59c6470

5 files changed

Lines changed: 44 additions & 0 deletions

File tree

.changeset/quick-maps-accept.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@refinedev/core": patch
3+
---
4+
5+
fix(core): preserve custom `getList` response fields in `useList` and `useTable` results.
6+
7+
We had an edge case where custom fields returned from `getList` were available on `query.data` but dropped from `result`. Now those extra fields are preserved in both `useList` and `useTable`.

packages/core/src/hooks/data/useList.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ describe("useList Hook", () => {
245245
});
246246

247247
expect(result.current.query.data?.foo).toBe("bar");
248+
expect(result.current.result.foo).toBe("bar");
248249
});
249250

250251
it("should only pass meta from the hook parameter and query parameters to the dataProvider", async () => {

packages/core/src/hooks/data/useList.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export type UseListReturnType<TData, TError> = {
9999
result: {
100100
data: TData[];
101101
total: number | undefined;
102+
[key: string]: any;
102103
};
103104
} & UseLoadingOvertimeReturnType;
104105

@@ -329,6 +330,7 @@ export const useList = <
329330
return {
330331
query: queryResponse,
331332
result: {
333+
...queryResponse?.data,
332334
data: queryResponse?.data?.data || EMPTY_ARRAY,
333335
total: queryResponse?.data?.total,
334336
},

packages/core/src/hooks/useTable/index.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,38 @@ describe("useTable Hook", () => {
5656
expect(tableResult.total).toBe(2);
5757
});
5858

59+
it("should preserve additional result fields from useList", async () => {
60+
const { result } = renderHook(
61+
() =>
62+
useTable({
63+
resource: "posts",
64+
}),
65+
{
66+
wrapper: TestWrapper({
67+
dataProvider: {
68+
default: {
69+
...MockJSONServer.default,
70+
getList: () =>
71+
Promise.resolve({
72+
data: [],
73+
total: 0,
74+
foo: "bar",
75+
}),
76+
},
77+
},
78+
resources: [{ name: "posts" }],
79+
routerProvider,
80+
}),
81+
},
82+
);
83+
84+
await waitFor(() => {
85+
expect(result.current.tableQuery.isSuccess).toBeTruthy();
86+
});
87+
88+
expect(result.current.result.foo).toBe("bar");
89+
});
90+
5991
it("with initial pagination parameters", async () => {
6092
const { result } = renderHook(
6193
() =>

packages/core/src/hooks/useTable/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export type useTableReturnType<
158158
result: {
159159
data: TData[];
160160
total: number | undefined;
161+
[key: string]: any;
161162
};
162163
} & UseLoadingOvertimeReturnType;
163164

@@ -435,6 +436,7 @@ export function useTable<
435436
createLinkForSyncWithLocation,
436437
overtime: queryResult.overtime,
437438
result: {
439+
...queryResult.result,
438440
data: queryResult.result?.data || EMPTY_ARRAY,
439441
total: queryResult.result?.total,
440442
},

0 commit comments

Comments
 (0)