@hyper-fetch/react 9.6.2 → 9.8.0
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/__tests__/features/use-cache/use-cache.base.spec.ts +10 -0
- package/__tests__/features/use-fetch/use-fetch.payload.spec.ts +74 -0
- package/__tests__/features/use-infinite-fetch/use-infinite-fetch.key.spec.ts +39 -0
- package/__tests__/features/use-submit/use-submit.optimistic-helpers.spec.tsx +455 -0
- package/dist/hooks/use-cache/use-cache.hooks.d.ts.map +1 -1
- package/dist/hooks/use-fetch/use-fetch.hooks.d.ts.map +1 -1
- package/dist/hooks/use-infinite-fetch/use-infinite-fetch.utils.d.ts.map +1 -1
- package/dist/hooks/use-submit/use-submit.constants.d.ts +1 -1
- package/dist/hooks/use-submit/use-submit.constants.d.ts.map +1 -1
- package/dist/hooks/use-submit/use-submit.hooks.d.ts.map +1 -1
- package/dist/hooks/use-submit/use-submit.types.d.ts +6 -1
- package/dist/hooks/use-submit/use-submit.types.d.ts.map +1 -1
- package/dist/index.mjs +18 -5
- package/dist/index.mjs.map +1 -1
- package/dist/utils/key.utils.d.ts +7 -0
- package/dist/utils/key.utils.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/hooks/use-cache/use-cache.hooks.ts +2 -1
- package/src/hooks/use-fetch/use-fetch.hooks.ts +2 -1
- package/src/hooks/use-infinite-fetch/use-infinite-fetch.utils.ts +3 -2
- package/src/hooks/use-submit/use-submit.constants.ts +3 -1
- package/src/hooks/use-submit/use-submit.hooks.ts +5 -1
- package/src/hooks/use-submit/use-submit.types.ts +6 -0
- package/src/utils/key.utils.ts +8 -0
package/dist/index.mjs
CHANGED
|
@@ -1261,6 +1261,16 @@ var useProvider = () => {
|
|
|
1261
1261
|
return useContext(ConfigContext);
|
|
1262
1262
|
};
|
|
1263
1263
|
//#endregion
|
|
1264
|
+
//#region src/utils/key.utils.ts
|
|
1265
|
+
/**
|
|
1266
|
+
* `JSON.stringify` replacer for the keys the hooks build from a request.
|
|
1267
|
+
* Adapters with their own serializers accept `BigInt` payloads, which plain JSON can't encode.
|
|
1268
|
+
* They are kept in the key and stay distinct from a string with the same digits.
|
|
1269
|
+
*/
|
|
1270
|
+
var keyReplacer = (_key, value) => {
|
|
1271
|
+
return typeof value === "bigint" ? { "~bigint": value.toString() } : value;
|
|
1272
|
+
};
|
|
1273
|
+
//#endregion
|
|
1264
1274
|
//#region src/hooks/use-fetch/use-fetch.hooks.ts
|
|
1265
1275
|
/**
|
|
1266
1276
|
* Suspended components lose their state, so the pending promises and the responses that are not stored in the cache
|
|
@@ -1306,7 +1316,7 @@ var mergeOptions$1 = (...sources) => {
|
|
|
1306
1316
|
var useFetch = (request, options) => {
|
|
1307
1317
|
const { config: globalConfig } = useProvider();
|
|
1308
1318
|
const { suspense, dependencies, disabled, dependencyTracking, revalidate, initialResponse, keepPreviousData, refresh, refreshTime, refetchBlurred, refetchOnBlur, refetchOnFocus, refetchOnReconnect, bounce, bounceType, bounceTime, bounceTimeout, deepCompare, structuralSharing, throwOnError } = mergeOptions$1(useFetchDefaultOptions, globalConfig.useFetchConfig, options);
|
|
1309
|
-
const updateKey = JSON.stringify(request.toJSON());
|
|
1319
|
+
const updateKey = JSON.stringify(request.toJSON(), keyReplacer);
|
|
1310
1320
|
const requestDebounce = f({ delay: bounceTime });
|
|
1311
1321
|
const requestThrottle = p({
|
|
1312
1322
|
interval: bounceTime,
|
|
@@ -1753,8 +1763,8 @@ var getInfiniteKey = (request, pagination, maxPages) => {
|
|
|
1753
1763
|
request.toJSON(),
|
|
1754
1764
|
pagination,
|
|
1755
1765
|
maxPages ?? null
|
|
1756
|
-
], (
|
|
1757
|
-
return typeof value === "function" ? value.toString() : value;
|
|
1766
|
+
], (key, value) => {
|
|
1767
|
+
return typeof value === "function" ? value.toString() : keyReplacer(key, value);
|
|
1758
1768
|
});
|
|
1759
1769
|
};
|
|
1760
1770
|
/**
|
|
@@ -2703,12 +2713,15 @@ var useSubmit = (request, options) => {
|
|
|
2703
2713
|
});
|
|
2704
2714
|
return Promise.resolve(getNotSentResponse("Cannot submit request. Option 'disabled' is enabled"));
|
|
2705
2715
|
}
|
|
2706
|
-
const
|
|
2716
|
+
const { optimistic: submitOptimistic, ...cloneOptions } = submitOptions || {};
|
|
2717
|
+
const requestClone = request.clone(cloneOptions);
|
|
2718
|
+
const optimistic = submitOptimistic ?? options?.optimistic;
|
|
2707
2719
|
const triggerRequest = () => {
|
|
2708
2720
|
addCacheDataListener(requestClone);
|
|
2709
2721
|
return sendRequest(requestClone, {
|
|
2710
2722
|
dispatcherType: "submit",
|
|
2711
2723
|
...submitOptions,
|
|
2724
|
+
optimistic,
|
|
2712
2725
|
onBeforeSent: (data) => {
|
|
2713
2726
|
removeLifecycleListener(data.requestId);
|
|
2714
2727
|
addLifecycleListeners(requestClone, data.requestId, data.mutationContext);
|
|
@@ -3062,7 +3075,7 @@ var useCache = (request, options) => {
|
|
|
3062
3075
|
const { cache, loggerManager } = client;
|
|
3063
3076
|
const logger = useRef(loggerManager.initialize(client, "useCache")).current;
|
|
3064
3077
|
const [dispatcher] = getRequestDispatcher(request);
|
|
3065
|
-
const updateKey = JSON.stringify(request.toJSON());
|
|
3078
|
+
const updateKey = JSON.stringify(request.toJSON(), keyReplacer);
|
|
3066
3079
|
const { config: globalConfig } = useProvider();
|
|
3067
3080
|
const { dependencyTracking, initialResponse, deepCompare, structuralSharing } = mergeOptions(useCacheDefaultOptions, globalConfig.useCacheConfig, options);
|
|
3068
3081
|
/**
|