@trackunit/react-graphql-hooks 1.13.5 → 1.13.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/index.cjs.js +11 -26
- package/index.esm.js +13 -28
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -212,38 +212,23 @@ const useStableVariables = (variables) => {
|
|
|
212
212
|
onChange: setStableVariables,
|
|
213
213
|
skip: !Boolean(variables),
|
|
214
214
|
});
|
|
215
|
-
return
|
|
215
|
+
return stableVariables;
|
|
216
216
|
};
|
|
217
217
|
/**
|
|
218
218
|
* Hook to manage AbortController for cancellable requests.
|
|
219
219
|
* Returns an abort signal that can be passed to fetch requests and a function to create new controllers.
|
|
220
220
|
*/
|
|
221
|
-
const useAbortableRequest = (
|
|
222
|
-
const [abortController
|
|
223
|
-
const
|
|
224
|
-
const [lastAbortController, setLastAbortController] = react.useState(undefined);
|
|
225
|
-
if (!esToolkit.isEqual(props.variables, prevVariables)) {
|
|
226
|
-
setPrevVariables(props.variables);
|
|
227
|
-
setStableVariables(props.variables);
|
|
228
|
-
if (!props.skip) {
|
|
229
|
-
if (lastAbortController) {
|
|
230
|
-
lastAbortController.abort();
|
|
231
|
-
}
|
|
232
|
-
const newAbortController = new AbortController();
|
|
233
|
-
setLastAbortController(newAbortController);
|
|
234
|
-
setAbortController(newAbortController);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
const abortControllerRef = react.useRef(abortController);
|
|
238
|
-
react.useEffect(() => {
|
|
239
|
-
abortControllerRef.current = abortController;
|
|
240
|
-
}, [abortController]);
|
|
241
|
-
// Cleanup on unmount only
|
|
221
|
+
const useAbortableRequest = () => {
|
|
222
|
+
const [abortController] = react.useState(() => new AbortController());
|
|
223
|
+
const firstRender = reactComponents.useIsFirstRender();
|
|
242
224
|
react.useEffect(() => {
|
|
225
|
+
if (firstRender) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
243
228
|
return () => {
|
|
244
|
-
|
|
229
|
+
abortController.abort();
|
|
245
230
|
};
|
|
246
|
-
}, []);
|
|
231
|
+
}, [abortController, firstRender]);
|
|
247
232
|
return { abortSignal: abortController.signal };
|
|
248
233
|
};
|
|
249
234
|
/**
|
|
@@ -304,9 +289,9 @@ const usePaginationQuery = (document, props) => {
|
|
|
304
289
|
resetTrigger: 0,
|
|
305
290
|
});
|
|
306
291
|
// Stabilize variables to prevent unnecessary re-fetches
|
|
307
|
-
const
|
|
292
|
+
const stableVariables = useStableVariables(props.variables);
|
|
308
293
|
// Manage abort controller for cancellable requests
|
|
309
|
-
const { abortSignal } = useAbortableRequest(
|
|
294
|
+
const { abortSignal } = useAbortableRequest();
|
|
310
295
|
const internalProps = react.useMemo(() => {
|
|
311
296
|
return {
|
|
312
297
|
...props,
|
package/index.esm.js
CHANGED
|
@@ -2,9 +2,9 @@ import 'react/jsx-runtime';
|
|
|
2
2
|
import { registerTranslations } from '@trackunit/i18n-library-translation';
|
|
3
3
|
import { truthy, objectKeys } from '@trackunit/shared-utils';
|
|
4
4
|
import { useLazyQuery as useLazyQuery$1, NetworkStatus, useQuery as useQuery$1 } from '@apollo/client';
|
|
5
|
-
import { omit
|
|
5
|
+
import { omit } from 'es-toolkit';
|
|
6
6
|
import { useMemo, useReducer, useCallback, useEffect, useState, useRef } from 'react';
|
|
7
|
-
import { useRelayPagination, defaultPageSize, useWatch } from '@trackunit/react-components';
|
|
7
|
+
import { useRelayPagination, defaultPageSize, useWatch, useIsFirstRender } from '@trackunit/react-components';
|
|
8
8
|
|
|
9
9
|
var defaultTranslations = {
|
|
10
10
|
|
|
@@ -210,38 +210,23 @@ const useStableVariables = (variables) => {
|
|
|
210
210
|
onChange: setStableVariables,
|
|
211
211
|
skip: !Boolean(variables),
|
|
212
212
|
});
|
|
213
|
-
return
|
|
213
|
+
return stableVariables;
|
|
214
214
|
};
|
|
215
215
|
/**
|
|
216
216
|
* Hook to manage AbortController for cancellable requests.
|
|
217
217
|
* Returns an abort signal that can be passed to fetch requests and a function to create new controllers.
|
|
218
218
|
*/
|
|
219
|
-
const useAbortableRequest = (
|
|
220
|
-
const [abortController
|
|
221
|
-
const
|
|
222
|
-
const [lastAbortController, setLastAbortController] = useState(undefined);
|
|
223
|
-
if (!isEqual(props.variables, prevVariables)) {
|
|
224
|
-
setPrevVariables(props.variables);
|
|
225
|
-
setStableVariables(props.variables);
|
|
226
|
-
if (!props.skip) {
|
|
227
|
-
if (lastAbortController) {
|
|
228
|
-
lastAbortController.abort();
|
|
229
|
-
}
|
|
230
|
-
const newAbortController = new AbortController();
|
|
231
|
-
setLastAbortController(newAbortController);
|
|
232
|
-
setAbortController(newAbortController);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
const abortControllerRef = useRef(abortController);
|
|
236
|
-
useEffect(() => {
|
|
237
|
-
abortControllerRef.current = abortController;
|
|
238
|
-
}, [abortController]);
|
|
239
|
-
// Cleanup on unmount only
|
|
219
|
+
const useAbortableRequest = () => {
|
|
220
|
+
const [abortController] = useState(() => new AbortController());
|
|
221
|
+
const firstRender = useIsFirstRender();
|
|
240
222
|
useEffect(() => {
|
|
223
|
+
if (firstRender) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
241
226
|
return () => {
|
|
242
|
-
|
|
227
|
+
abortController.abort();
|
|
243
228
|
};
|
|
244
|
-
}, []);
|
|
229
|
+
}, [abortController, firstRender]);
|
|
245
230
|
return { abortSignal: abortController.signal };
|
|
246
231
|
};
|
|
247
232
|
/**
|
|
@@ -302,9 +287,9 @@ const usePaginationQuery = (document, props) => {
|
|
|
302
287
|
resetTrigger: 0,
|
|
303
288
|
});
|
|
304
289
|
// Stabilize variables to prevent unnecessary re-fetches
|
|
305
|
-
const
|
|
290
|
+
const stableVariables = useStableVariables(props.variables);
|
|
306
291
|
// Manage abort controller for cancellable requests
|
|
307
|
-
const { abortSignal } = useAbortableRequest(
|
|
292
|
+
const { abortSignal } = useAbortableRequest();
|
|
308
293
|
const internalProps = useMemo(() => {
|
|
309
294
|
return {
|
|
310
295
|
...props,
|