@refinedev/core 5.0.4 → 5.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@refinedev/core",
3
- "version": "5.0.4",
3
+ "version": "5.0.6",
4
4
  "private": false,
5
5
  "description": "Refine is a React meta-framework for building enterprise-level, data-intensive applications rapidly with support for modern UI libraries and headless integrations.",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "module": "dist/index.mjs",
28
28
  "typings": "dist/index.d.ts",
29
29
  "dependencies": {
30
- "@refinedev/devtools-internal": "2.0.0",
30
+ "@refinedev/devtools-internal": "2.0.1",
31
31
  "@tanstack/react-query": "^5.81.5",
32
32
  "lodash": "^4.17.21",
33
33
  "lodash-es": "^4.17.21",
@@ -1,6 +1,7 @@
1
1
  import { useEffect } from "react";
2
2
 
3
3
  import { getXRay } from "@refinedev/devtools-internal";
4
+ import { useMemo } from "react";
4
5
  import {
5
6
  type QueryObserverResult,
6
7
  type UseQueryOptions,
@@ -200,6 +201,38 @@ export const useList = <
200
201
  },
201
202
  });
202
203
 
204
+ // Memoize the select function to prevent it from running multiple times
205
+ // Note: If queryOptions.select is not memoized by the user, this will still
206
+ // re-run on every render. Users should wrap their select function in useCallback.
207
+ const memoizedSelect = useMemo(() => {
208
+ return (rawData: GetListResponse<TQueryFnData>): GetListResponse<TData> => {
209
+ let data = rawData;
210
+
211
+ if (prefferedPagination.mode === "client") {
212
+ data = {
213
+ ...data,
214
+ data: data.data.slice(
215
+ (prefferedPagination.currentPage - 1) *
216
+ prefferedPagination.pageSize,
217
+ prefferedPagination.currentPage * prefferedPagination.pageSize,
218
+ ),
219
+ total: data.total,
220
+ };
221
+ }
222
+
223
+ if (queryOptions?.select) {
224
+ return queryOptions?.select?.(data);
225
+ }
226
+
227
+ return data as unknown as GetListResponse<TData>;
228
+ };
229
+ }, [
230
+ prefferedPagination.currentPage,
231
+ prefferedPagination.pageSize,
232
+ prefferedPagination.mode,
233
+ queryOptions?.select,
234
+ ]);
235
+
203
236
  const queryResponse = useQuery<
204
237
  GetListResponse<TQueryFnData>,
205
238
  TError,
@@ -238,28 +271,7 @@ export const useList = <
238
271
  typeof queryOptions?.enabled !== "undefined"
239
272
  ? queryOptions?.enabled
240
273
  : !!resource?.name,
241
- select: (rawData) => {
242
- let data = rawData;
243
-
244
- const { currentPage, mode, pageSize } = prefferedPagination;
245
-
246
- if (mode === "client") {
247
- data = {
248
- ...data,
249
- data: data.data.slice(
250
- (currentPage - 1) * pageSize,
251
- currentPage * pageSize,
252
- ),
253
- total: data.total,
254
- };
255
- }
256
-
257
- if (queryOptions?.select) {
258
- return queryOptions?.select?.(data);
259
- }
260
-
261
- return data as unknown as GetListResponse<TData>;
262
- },
274
+ select: memoizedSelect,
263
275
  meta: {
264
276
  ...queryOptions?.meta,
265
277
  ...getXRay("useList", resource?.name),
@@ -302,12 +302,28 @@ export const useForm = <
302
302
  return submissionPromise;
303
303
  };
304
304
 
305
- const onFinishAutoSave = asyncDebounce(
306
- (values: TVariables) => onFinish(values, { isAutosave: true }),
307
- props.autoSave?.debounce || 1000,
308
- "Cancelled by debounce",
305
+ const onFinishRef = React.useRef(onFinish);
306
+ React.useEffect(() => {
307
+ onFinishRef.current = onFinish;
308
+ }, [onFinish]);
309
+
310
+ const onFinishAutoSave = React.useMemo(
311
+ () =>
312
+ asyncDebounce(
313
+ (values: TVariables) =>
314
+ onFinishRef.current(values, { isAutosave: true }),
315
+ props.autoSave?.debounce ?? 1000,
316
+ "Cancelled by debounce",
317
+ ),
318
+ [props.autoSave?.debounce],
309
319
  );
310
320
 
321
+ React.useEffect(() => {
322
+ return () => {
323
+ onFinishAutoSave.cancel();
324
+ };
325
+ }, [onFinishAutoSave]);
326
+
311
327
  const overtime = {
312
328
  elapsedTime,
313
329
  };