@hyper-fetch/react 8.2.0 → 8.2.2

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.
Files changed (115) hide show
  1. package/README.md +17 -7
  2. package/__tests__/features/helpers/use-request-events/use-request-events.base.spec.ts +1 -1
  3. package/__tests__/features/helpers/use-request-events/use-request-events.utils.spec.ts +1 -1
  4. package/__tests__/features/helpers/use-socket-state/use-socket-state.base.spec.ts +3 -3
  5. package/__tests__/features/helpers/use-tracked-state/use-tacked-state.actions.spec.ts +1 -1
  6. package/__tests__/features/helpers/use-tracked-state/use-tracked-state.base.spec.ts +55 -55
  7. package/__tests__/features/helpers/use-tracked-state/use-tracked-state.utils.spec.ts +8 -9
  8. package/__tests__/features/provider/provider.hydration.spec.tsx +3 -4
  9. package/__tests__/features/provider/use-config-provider.base.spec.tsx +1 -2
  10. package/__tests__/features/use-app-manager/use-app-manager.base.spec.ts +1 -1
  11. package/__tests__/features/use-cache/use-cache.base.spec.ts +6 -6
  12. package/__tests__/features/use-cache/use-cache.typescript.spec.ts +1 -2
  13. package/__tests__/features/use-emitter/use-emitter.base.spec.ts +1 -1
  14. package/__tests__/features/use-fetch/use-fetch.base.spec.ts +13 -9
  15. package/__tests__/features/use-fetch/use-fetch.cancel.spec.ts +1 -1
  16. package/__tests__/features/use-fetch/use-fetch.clear-state.spec.ts +1 -1
  17. package/__tests__/features/use-fetch/use-fetch.concurrency.spec.ts +1 -1
  18. package/__tests__/features/use-fetch/use-fetch.debounce.spec.ts +1 -1
  19. package/__tests__/features/use-fetch/use-fetch.integration.spec.tsx +2 -2
  20. package/__tests__/features/use-fetch/use-fetch.keep-previous-data.spec.ts +1 -1
  21. package/__tests__/features/use-fetch/use-fetch.methods.spec.ts +1 -1
  22. package/__tests__/features/use-fetch/use-fetch.offline.spec.ts +1 -1
  23. package/__tests__/features/use-fetch/use-fetch.prefetch.spec.tsx +2 -2
  24. package/__tests__/features/use-fetch/use-fetch.refresh.spec.ts +3 -2
  25. package/__tests__/features/use-fetch/use-fetch.rerender.spec.tsx +3 -3
  26. package/__tests__/features/use-fetch/use-fetch.revalidate.spec.ts +47 -17
  27. package/__tests__/features/use-fetch/use-fetch.suspense.spec.tsx +4 -4
  28. package/__tests__/features/use-fetch/use-fetch.typescript.spec.ts +1 -2
  29. package/__tests__/features/use-fetch/use-fetch.utils.spec.ts +2 -2
  30. package/__tests__/features/use-fetch/use-fetch.window.spec.ts +1 -1
  31. package/__tests__/features/use-listener/use-listener.base.spec.ts +1 -1
  32. package/__tests__/features/use-queue/use-queue.actions.spec.ts +3 -3
  33. package/__tests__/features/use-queue/use-queue.base.spec.ts +13 -13
  34. package/__tests__/features/use-queue/use-queue.resolve.spec.ts +6 -6
  35. package/__tests__/features/use-stream/use-stream.base.spec.ts +1 -1
  36. package/__tests__/features/use-submit/use-submit.base.spec.ts +2 -2
  37. package/__tests__/features/use-submit/use-submit.cancel.spec.ts +1 -1
  38. package/__tests__/features/use-submit/use-submit.concurrency.spec.ts +1 -1
  39. package/__tests__/features/use-submit/use-submit.debounce.spec.ts +15 -15
  40. package/__tests__/features/use-submit/use-submit.methods.spec.ts +1 -1
  41. package/__tests__/features/use-submit/use-submit.optimistic.spec.ts +1 -1
  42. package/__tests__/features/use-submit/use-submit.queue.spec.ts +1 -1
  43. package/__tests__/features/use-submit/use-submit.retry.spec.ts +2 -2
  44. package/__tests__/features/use-submit/use-submit.revalidate.spec.ts +1 -1
  45. package/__tests__/features/use-submit/use-submit.submit.spec.ts +1 -1
  46. package/__tests__/features/use-submit/use-submit.typescript.spec.ts +2 -3
  47. package/__tests__/shared/isolation.tests.ts +1 -1
  48. package/__tests__/shared/response.tests.ts +2 -2
  49. package/__tests__/tsconfig.json +11 -17
  50. package/__tests__/utils/cache.utils.ts +6 -6
  51. package/__tests__/utils/use-app-manager.utils.ts +0 -1
  52. package/__tests__/utils/use-cache.utils.ts +0 -1
  53. package/__tests__/utils/use-emitter.utils.ts +1 -2
  54. package/__tests__/utils/use-fetch.utils.ts +0 -1
  55. package/__tests__/utils/use-listener.utils.ts +1 -2
  56. package/__tests__/utils/use-queue.utils.ts +4 -5
  57. package/__tests__/utils/use-request-events.utils.ts +0 -1
  58. package/__tests__/utils/use-socket-state.utils.ts +1 -2
  59. package/__tests__/utils/use-submit.utils.ts +0 -1
  60. package/__tests__/utils/use-tracked-state.utils.ts +0 -1
  61. package/dist/helpers/use-request-events/use-request-events.hooks.d.ts.map +1 -1
  62. package/dist/helpers/use-request-events/use-request-events.types.d.ts.map +1 -1
  63. package/dist/helpers/use-socket-state/use-socket-state.hooks.d.ts.map +1 -1
  64. package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts.map +1 -1
  65. package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts.map +1 -1
  66. package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts.map +1 -1
  67. package/dist/hooks/use-cache/use-cache.hooks.d.ts.map +1 -1
  68. package/dist/hooks/use-cache/use-cache.types.d.ts +2 -2
  69. package/dist/hooks/use-cache/use-cache.types.d.ts.map +1 -1
  70. package/dist/hooks/use-emitter/use-emitter.hooks.d.ts.map +1 -1
  71. package/dist/hooks/use-fetch/use-fetch.constants.d.ts.map +1 -1
  72. package/dist/hooks/use-fetch/use-fetch.hooks.d.ts.map +1 -1
  73. package/dist/hooks/use-fetch/use-fetch.types.d.ts.map +1 -1
  74. package/dist/hooks/use-listener/use-listener.hooks.d.ts.map +1 -1
  75. package/dist/hooks/use-queue/use-queue.constants.d.ts.map +1 -1
  76. package/dist/hooks/use-queue/use-queue.hooks.d.ts.map +1 -1
  77. package/dist/hooks/use-submit/use-submit.hooks.d.ts.map +1 -1
  78. package/dist/hooks/use-submit/use-submit.types.d.ts +1 -1
  79. package/dist/hooks/use-submit/use-submit.types.d.ts.map +1 -1
  80. package/dist/index.mjs +20 -19
  81. package/dist/index.mjs.map +1 -1
  82. package/dist/provider/provider.types.d.ts +4 -4
  83. package/dist/provider/provider.types.d.ts.map +1 -1
  84. package/dist/utils/bounce.utils.d.ts.map +1 -1
  85. package/dist/utils/deep-equal.utils.d.ts +2 -2
  86. package/dist/utils/deep-equal.utils.d.ts.map +1 -1
  87. package/dist/utils/tracked-proxy.utils.d.ts +1 -1
  88. package/dist/utils/tracked-proxy.utils.d.ts.map +1 -1
  89. package/package.json +8 -13
  90. package/src/helpers/use-request-events/use-request-events.hooks.ts +4 -5
  91. package/src/helpers/use-request-events/use-request-events.types.ts +0 -1
  92. package/src/helpers/use-socket-state/use-socket-state.hooks.ts +5 -6
  93. package/src/helpers/use-tracked-state/use-tracked-state.hooks.ts +11 -11
  94. package/src/helpers/use-tracked-state/use-tracked-state.types.ts +0 -1
  95. package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +12 -13
  96. package/src/hooks/use-app-manager/use-app-manager.hooks.ts +1 -2
  97. package/src/hooks/use-cache/use-cache.hooks.ts +3 -4
  98. package/src/hooks/use-cache/use-cache.types.ts +2 -3
  99. package/src/hooks/use-emitter/use-emitter.hooks.ts +3 -4
  100. package/src/hooks/use-fetch/use-fetch.constants.ts +0 -1
  101. package/src/hooks/use-fetch/use-fetch.hooks.ts +12 -9
  102. package/src/hooks/use-fetch/use-fetch.types.ts +0 -1
  103. package/src/hooks/use-listener/use-listener.hooks.ts +2 -3
  104. package/src/hooks/use-queue/use-queue.constants.ts +0 -1
  105. package/src/hooks/use-queue/use-queue.hooks.ts +1 -2
  106. package/src/hooks/use-stream/use-stream.hooks.ts +4 -4
  107. package/src/hooks/use-submit/use-submit.hooks.ts +5 -6
  108. package/src/hooks/use-submit/use-submit.types.ts +1 -2
  109. package/src/provider/provider.types.ts +4 -5
  110. package/src/utils/bounce.utils.ts +1 -0
  111. package/src/utils/deep-equal.utils.ts +28 -12
  112. package/src/utils/tracked-proxy.utils.ts +1 -1
  113. package/tsconfig.json +11 -2
  114. package/vite.config.ts +14 -20
  115. package/.eslintrc.cjs +0 -12
package/README.md CHANGED
@@ -30,7 +30,9 @@
30
30
 
31
31
  ## 📖 About
32
32
 
33
- `@hyper-fetch/react` connects HyperFetch's typed request system to React's component lifecycle. `useFetch` triggers requests on mount and re-fetches when dependencies change. `useSubmit` gives you a `submit` function for mutations triggered by user actions. Both hooks return fully typed `data`, `error`, and loading states with built-in callbacks.
33
+ `@hyper-fetch/react` connects HyperFetch's typed request system to React's component lifecycle. `useFetch` triggers
34
+ requests on mount and re-fetches when dependencies change. `useSubmit` gives you a `submit` function for mutations
35
+ triggered by user actions. Both hooks return fully typed `data`, `error`, and loading states with built-in callbacks.
34
36
 
35
37
  ## 🎯 Key Capabilities
36
38
 
@@ -60,7 +62,13 @@ const UserList = () => {
60
62
 
61
63
  if (loading) return <p>Loading...</p>;
62
64
  if (error) return <p>Something went wrong</p>;
63
- return <ul>{data?.map((user) => <li key={user.id}>{user.name}</li>)}</ul>;
65
+ return (
66
+ <ul>
67
+ {data?.map((user) => (
68
+ <li key={user.id}>{user.name}</li>
69
+ ))}
70
+ </ul>
71
+ );
64
72
  };
65
73
  ```
66
74
 
@@ -79,9 +87,7 @@ import { useFetch } from "@hyper-fetch/react";
79
87
 
80
88
  const UserProfile = ({ userId }: { userId: number }) => {
81
89
  // setParams makes the request dynamic — re-fetches when userId changes
82
- const { data, loading, error, onSuccess, onError } = useFetch(
83
- getUser.setParams({ userId }),
84
- );
90
+ const { data, loading, error, onSuccess, onError } = useFetch(getUser.setParams({ userId }));
85
91
 
86
92
  // Typed callbacks — response shape matches your request definition
87
93
  onSuccess(({ response }) => {
@@ -151,7 +157,9 @@ const UserPosts = ({ userId }: { userId: number }) => {
151
157
  return (
152
158
  <div>
153
159
  <h1>{user?.name}</h1>
154
- {posts?.map((post) => <article key={post.id}>{post.title}</article>)}
160
+ {posts?.map((post) => (
161
+ <article key={post.id}>{post.title}</article>
162
+ ))}
155
163
  </div>
156
164
  );
157
165
  };
@@ -201,7 +209,9 @@ const AddComment = ({ postId }: { postId: number }) => {
201
209
  return (
202
210
  <form onSubmit={handleSubmit}>
203
211
  <input name="text" placeholder="Write a comment..." required />
204
- <button type="submit" disabled={submitting}>Post</button>
212
+ <button type="submit" disabled={submitting}>
213
+ Post
214
+ </button>
205
215
  </form>
206
216
  );
207
217
  };
@@ -1,6 +1,6 @@
1
- import { act } from "@testing-library/react";
2
1
  import { createClient } from "@hyper-fetch/core";
3
2
  import { createHttpMockingServer } from "@hyper-fetch/testing";
3
+ import { act } from "@testing-library/react";
4
4
 
5
5
  import { renderUseRequestEvents } from "../../../utils";
6
6
 
@@ -1,5 +1,5 @@
1
- import { act } from "@testing-library/react";
2
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
2
+ import { act } from "@testing-library/react";
3
3
 
4
4
  import { createRequest, renderUseRequestEvents } from "../../../utils";
5
5
 
@@ -1,6 +1,6 @@
1
- import { act } from "@testing-library/react";
2
1
  import { Socket } from "@hyper-fetch/sockets";
3
2
  import { createWebsocketMockingServer } from "@hyper-fetch/testing";
3
+ import { act } from "@testing-library/react";
4
4
 
5
5
  import { renderUseSocketState } from "../../../utils/use-socket-state.utils";
6
6
 
@@ -191,13 +191,13 @@ describe("useSocketState [ Base ]", () => {
191
191
  actions.setExtra({ test: true } as any);
192
192
  actions.setConnected(true);
193
193
  actions.setConnecting(true);
194
- actions.setTimestamp(12345);
194
+ actions.setTimestamp(12_345);
195
195
  });
196
196
 
197
197
  expect(view.result.current[0].data).toBe("some-data");
198
198
  expect(view.result.current[0].connected).toBe(true);
199
199
  expect(view.result.current[0].connecting).toBe(true);
200
- expect(view.result.current[0].timestamp).toBe(12345);
200
+ expect(view.result.current[0].timestamp).toBe(12_345);
201
201
 
202
202
  act(() => {
203
203
  view.result.current[1].clearState();
@@ -1,6 +1,6 @@
1
1
  import { createClient } from "@hyper-fetch/core";
2
- import { act, waitFor } from "@testing-library/react";
3
2
  import { createHttpMockingServer } from "@hyper-fetch/testing";
3
+ import { act, waitFor } from "@testing-library/react";
4
4
 
5
5
  import { renderUseTrackedState } from "../../../utils";
6
6
 
@@ -1,8 +1,8 @@
1
1
  import { createClient, xhrExtra } from "@hyper-fetch/core";
2
- import { act, waitFor } from "@testing-library/react";
3
2
  import { createHttpMockingServer, sleep } from "@hyper-fetch/testing";
4
-
3
+ import { act, waitFor } from "@testing-library/react";
5
4
  import { initialState } from "helpers";
5
+
6
6
  import { renderUseTrackedState } from "../../../utils";
7
7
 
8
8
  const { resetMocks, startServer, stopServer, mockRequest } = createHttpMockingServer();
@@ -68,10 +68,10 @@ describe("useTrackingState [ Events ]", () => {
68
68
  success: true,
69
69
  extra: xhrExtra,
70
70
  retries: 0,
71
- requestTimestamp: +new Date(),
72
- responseTimestamp: +new Date(),
73
- addedTimestamp: +new Date(),
74
- triggerTimestamp: +new Date(),
71
+ requestTimestamp: Date.now(),
72
+ responseTimestamp: Date.now(),
73
+ addedTimestamp: Date.now(),
74
+ triggerTimestamp: Date.now(),
75
75
  cacheKey: request.cacheKey,
76
76
  scope: request.scope,
77
77
  isCanceled: false,
@@ -95,10 +95,10 @@ describe("useTrackingState [ Events ]", () => {
95
95
  success: true,
96
96
  extra: xhrExtra,
97
97
  retries: 0,
98
- requestTimestamp: +new Date(),
99
- responseTimestamp: +new Date(),
100
- addedTimestamp: +new Date(),
101
- triggerTimestamp: +new Date(),
98
+ requestTimestamp: Date.now(),
99
+ responseTimestamp: Date.now(),
100
+ addedTimestamp: Date.now(),
101
+ triggerTimestamp: Date.now(),
102
102
  cacheKey: request.cacheKey,
103
103
  scope: request.scope,
104
104
  isCanceled: false,
@@ -131,10 +131,10 @@ describe("useTrackingState [ Events ]", () => {
131
131
  success: true,
132
132
  extra: xhrExtra,
133
133
  retries: 0,
134
- requestTimestamp: +new Date(),
135
- responseTimestamp: +new Date(),
136
- addedTimestamp: +new Date(),
137
- triggerTimestamp: +new Date(),
134
+ requestTimestamp: Date.now(),
135
+ responseTimestamp: Date.now(),
136
+ addedTimestamp: Date.now(),
137
+ triggerTimestamp: Date.now(),
138
138
  cacheKey: request.cacheKey,
139
139
  scope: request.scope,
140
140
  isCanceled: false,
@@ -168,10 +168,10 @@ describe("useTrackingState [ Events ]", () => {
168
168
  success: true,
169
169
  extra: xhrExtra,
170
170
  retries: 0,
171
- requestTimestamp: +new Date(),
172
- responseTimestamp: +new Date(),
173
- addedTimestamp: +new Date(),
174
- triggerTimestamp: +new Date(),
171
+ requestTimestamp: Date.now(),
172
+ responseTimestamp: Date.now(),
173
+ addedTimestamp: Date.now(),
174
+ triggerTimestamp: Date.now(),
175
175
  cacheKey: request.cacheKey,
176
176
  scope: request.scope,
177
177
  isCanceled: false,
@@ -204,10 +204,10 @@ describe("useTrackingState [ Events ]", () => {
204
204
  success: true,
205
205
  extra: xhrExtra,
206
206
  retries: 0,
207
- requestTimestamp: +new Date(),
208
- responseTimestamp: +new Date(),
209
- addedTimestamp: +new Date(),
210
- triggerTimestamp: +new Date(),
207
+ requestTimestamp: Date.now(),
208
+ responseTimestamp: Date.now(),
209
+ addedTimestamp: Date.now(),
210
+ triggerTimestamp: Date.now(),
211
211
  cacheKey: request.cacheKey,
212
212
  scope: request.scope,
213
213
  isCanceled: false,
@@ -243,10 +243,10 @@ describe("useTrackingState [ Events ]", () => {
243
243
  success: true,
244
244
  extra: xhrExtra,
245
245
  retries: 0,
246
- requestTimestamp: +new Date(),
247
- responseTimestamp: +new Date(),
248
- addedTimestamp: +new Date(),
249
- triggerTimestamp: +new Date(),
246
+ requestTimestamp: Date.now(),
247
+ responseTimestamp: Date.now(),
248
+ addedTimestamp: Date.now(),
249
+ triggerTimestamp: Date.now(),
250
250
  cacheKey: request.cacheKey,
251
251
  scope: request.scope,
252
252
  isCanceled: false,
@@ -287,7 +287,7 @@ describe("useTrackingState [ Events ]", () => {
287
287
  it("should map the async data", async () => {
288
288
  const { result } = renderUseTrackedState(
289
289
  request.setResponseMapper(async (response) => {
290
- return Promise.resolve({ ...response, data: "new-data" } as typeof response);
290
+ return { ...response, data: "new-data" } as typeof response;
291
291
  }),
292
292
  );
293
293
 
@@ -300,10 +300,10 @@ describe("useTrackingState [ Events ]", () => {
300
300
  success: true,
301
301
  extra: xhrExtra,
302
302
  retries: 0,
303
- requestTimestamp: +new Date(),
304
- responseTimestamp: +new Date(),
305
- addedTimestamp: +new Date(),
306
- triggerTimestamp: +new Date(),
303
+ requestTimestamp: Date.now(),
304
+ responseTimestamp: Date.now(),
305
+ addedTimestamp: Date.now(),
306
+ triggerTimestamp: Date.now(),
307
307
  cacheKey: request.cacheKey,
308
308
  scope: request.scope,
309
309
  isCanceled: false,
@@ -338,10 +338,10 @@ describe("useTrackingState [ Events ]", () => {
338
338
  success: true,
339
339
  extra: xhrExtra,
340
340
  retries: 0,
341
- requestTimestamp: +new Date(),
342
- responseTimestamp: +new Date(),
343
- addedTimestamp: +new Date(),
344
- triggerTimestamp: +new Date(),
341
+ requestTimestamp: Date.now(),
342
+ responseTimestamp: Date.now(),
343
+ addedTimestamp: Date.now(),
344
+ triggerTimestamp: Date.now(),
345
345
  cacheKey: request.cacheKey,
346
346
  scope: request.scope,
347
347
  isCanceled: false,
@@ -375,10 +375,10 @@ describe("useTrackingState [ Events ]", () => {
375
375
  success: true,
376
376
  extra: xhrExtra,
377
377
  retries: 0,
378
- requestTimestamp: +new Date(),
379
- responseTimestamp: +new Date(),
380
- addedTimestamp: +new Date(),
381
- triggerTimestamp: +new Date(),
378
+ requestTimestamp: Date.now(),
379
+ responseTimestamp: Date.now(),
380
+ addedTimestamp: Date.now(),
381
+ triggerTimestamp: Date.now(),
382
382
  cacheKey: request.cacheKey,
383
383
  scope: request.scope,
384
384
  isCanceled: false,
@@ -434,10 +434,10 @@ describe("useTrackingState [ Events ]", () => {
434
434
  success: true,
435
435
  extra: xhrExtra,
436
436
  retries: 0,
437
- requestTimestamp: +new Date(),
438
- responseTimestamp: +new Date(),
439
- addedTimestamp: +new Date(),
440
- triggerTimestamp: +new Date(),
437
+ requestTimestamp: Date.now(),
438
+ responseTimestamp: Date.now(),
439
+ addedTimestamp: Date.now(),
440
+ triggerTimestamp: Date.now(),
441
441
  cacheKey: request.cacheKey,
442
442
  scope: request.scope,
443
443
  isCanceled: false,
@@ -459,10 +459,10 @@ describe("useTrackingState [ Events ]", () => {
459
459
  success: true,
460
460
  extra: xhrExtra,
461
461
  retries: 0,
462
- requestTimestamp: +new Date(),
463
- responseTimestamp: +new Date(),
464
- addedTimestamp: +new Date(),
465
- triggerTimestamp: +new Date(),
462
+ requestTimestamp: Date.now(),
463
+ responseTimestamp: Date.now(),
464
+ addedTimestamp: Date.now(),
465
+ triggerTimestamp: Date.now(),
466
466
  cacheKey: request.cacheKey,
467
467
  scope: request.scope,
468
468
  isCanceled: false,
@@ -510,10 +510,10 @@ describe("useTrackingState [ Events ]", () => {
510
510
  success: true,
511
511
  extra: xhrExtra,
512
512
  retries: 0,
513
- requestTimestamp: +new Date(),
514
- responseTimestamp: +new Date(),
515
- addedTimestamp: +new Date(),
516
- triggerTimestamp: +new Date(),
513
+ requestTimestamp: Date.now(),
514
+ responseTimestamp: Date.now(),
515
+ addedTimestamp: Date.now(),
516
+ triggerTimestamp: Date.now(),
517
517
  cacheKey: request.cacheKey,
518
518
  scope: request.scope,
519
519
  isCanceled: false,
@@ -543,10 +543,10 @@ describe("useTrackingState [ Events ]", () => {
543
543
  success: true,
544
544
  extra: xhrExtra,
545
545
  retries: 0,
546
- requestTimestamp: +new Date(),
547
- responseTimestamp: +new Date(),
548
- addedTimestamp: +new Date(),
549
- triggerTimestamp: +new Date(),
546
+ requestTimestamp: Date.now(),
547
+ responseTimestamp: Date.now(),
548
+ addedTimestamp: Date.now(),
549
+ triggerTimestamp: Date.now(),
550
550
  cacheKey: request.cacheKey,
551
551
  scope: request.scope,
552
552
  isCanceled: false,
@@ -1,5 +1,4 @@
1
1
  import { createClient } from "@hyper-fetch/core";
2
-
3
2
  import { getValidCacheData, getInitialState, initialState } from "helpers";
4
3
  import { isEmpty, isEqual } from "utils";
5
4
 
@@ -16,7 +15,7 @@ describe("useTrackedState [ Utils ]", () => {
16
15
  expect(isEmpty(NaN)).toBe(false);
17
16
  expect(isEmpty("")).toBe(false);
18
17
  expect(isEmpty(false)).toBe(false);
19
- expect(isEmpty(undefined)).toBe(false);
18
+ expect(isEmpty()).toBe(false);
20
19
  expect(isEmpty(0)).toBe(false);
21
20
  expect(isEmpty(true)).toBe(false);
22
21
  expect(isEmpty(123)).toBe(false);
@@ -70,7 +69,7 @@ describe("useTrackedState [ Utils ]", () => {
70
69
 
71
70
  expect(isEqual(true, true)).toBe(true);
72
71
  expect(isEqual(false, false)).toBe(true);
73
- expect(isEqual(undefined, undefined)).toBe(true);
72
+ expect(isEqual()).toBe(true);
74
73
  expect(isEqual(null, null)).toBe(true);
75
74
  expect(isEqual(date, date)).toBe(true);
76
75
  expect(isEqual(date, date)).toBe(true);
@@ -135,8 +134,8 @@ describe("useTrackedState [ Utils ]", () => {
135
134
  data: "test-data",
136
135
  status: 200,
137
136
  success: true,
138
- requestTimestamp: new Date().getTime(),
139
- responseTimestamp: new Date().getTime(),
137
+ requestTimestamp: Date.now(),
138
+ responseTimestamp: Date.now(),
140
139
  };
141
140
 
142
141
  const result = getValidCacheData(mockRequest, initialResponse, null);
@@ -162,7 +161,7 @@ describe("useTrackedState [ Utils ]", () => {
162
161
  });
163
162
 
164
163
  it("should return cache data when not stale", () => {
165
- const currentTime = new Date().getTime();
164
+ const currentTime = Date.now();
166
165
  const cacheData = {
167
166
  data: "cached-data",
168
167
  error: null,
@@ -177,7 +176,7 @@ describe("useTrackedState [ Utils ]", () => {
177
176
  });
178
177
 
179
178
  it("should return stale cache data for stale-while-revalidate", () => {
180
- const staleTimestamp = new Date().getTime() - 5000; // Well beyond the 1000ms staleTime
179
+ const staleTimestamp = Date.now() - 5000; // Well beyond the 1000ms staleTime
181
180
  const cacheData = {
182
181
  data: "stale-data",
183
182
  error: null,
@@ -223,7 +222,7 @@ describe("useTrackedState [ Utils ]", () => {
223
222
 
224
223
  describe("when getInitialState handles sync responseMapper", () => {
225
224
  it("should apply sync responseMapper to cache data", () => {
226
- const currentTime = new Date().getTime();
225
+ const currentTime = Date.now();
227
226
  const cacheData = {
228
227
  data: "original-data",
229
228
  error: null,
@@ -242,7 +241,7 @@ describe("useTrackedState [ Utils ]", () => {
242
241
  });
243
242
 
244
243
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
245
- // @ts-ignore
244
+ // @ts-expect-error
246
245
  client.cache = {
247
246
  get: vi.fn().mockReturnValue(cacheData),
248
247
  version: "1",
@@ -1,15 +1,14 @@
1
- /* eslint-disable react/jsx-fragments */
2
- /* eslint-disable react/jsx-no-useless-fragment */
3
- import { Fragment } from "react";
4
1
  import type { HttpAdapterExtraType } from "@hyper-fetch/core";
5
2
  import { Client } from "@hyper-fetch/core";
6
3
  import { render, waitFor } from "@testing-library/react";
7
-
8
4
  import type { UseFetchReturnType } from "hooks/use-fetch";
9
5
  import { useFetch } from "hooks/use-fetch";
10
6
  import type { UseSubmitReturnType } from "hooks/use-submit";
11
7
  import { useSubmit } from "hooks/use-submit";
12
8
  import { Provider } from "provider";
9
+ /* eslint-disable react/jsx-fragments */
10
+ /* eslint-disable react/jsx-no-useless-fragment */
11
+ import { Fragment } from "react";
13
12
 
14
13
  describe("Provider [ Hydration ]", () => {
15
14
  const data = [1, 2, 3, 4, 5];
@@ -1,5 +1,4 @@
1
1
  import { act, render, screen, waitFor } from "@testing-library/react";
2
-
3
2
  import type { ProviderValueType } from "provider";
4
3
  import { Provider, useProvider } from "provider";
5
4
 
@@ -32,7 +31,7 @@ describe("useProvider [ Base ]", () => {
32
31
  });
33
32
  });
34
33
  it("should allow to modify received values", async () => {
35
- const customConfig = { useFetchConfig: { bounceTime: 99999 } };
34
+ const customConfig = { useFetchConfig: { bounceTime: 99_999 } };
36
35
  render(<App />);
37
36
 
38
37
  act(() => {
@@ -1,5 +1,5 @@
1
- import { act } from "@testing-library/react";
2
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
2
+ import { act } from "@testing-library/react";
3
3
 
4
4
  import { client, renderUseAppManager } from "../../utils";
5
5
 
@@ -1,10 +1,10 @@
1
- import { act } from "@testing-library/react";
2
1
  import type { CacheValueType } from "@hyper-fetch/core";
3
2
  import { createHttpMockingServer } from "@hyper-fetch/testing";
3
+ import { act } from "@testing-library/react";
4
4
 
5
+ import { testInitialState, testSuccessState } from "../../shared";
5
6
  import { client, createRequest } from "../../utils";
6
7
  import { renderUseCache } from "../../utils/use-cache.utils";
7
- import { testInitialState, testSuccessState } from "../../shared";
8
8
 
9
9
  const { resetMocks, startServer, stopServer } = createHttpMockingServer();
10
10
 
@@ -21,10 +21,10 @@ describe("useCache [ Base ]", () => {
21
21
  },
22
22
  },
23
23
  retries: 0,
24
- requestTimestamp: +new Date(),
25
- responseTimestamp: +new Date(),
26
- addedTimestamp: +new Date(),
27
- triggerTimestamp: +new Date(),
24
+ requestTimestamp: Date.now(),
25
+ responseTimestamp: Date.now(),
26
+ addedTimestamp: Date.now(),
27
+ triggerTimestamp: Date.now(),
28
28
  cacheKey: request.cacheKey,
29
29
  scope: request.scope,
30
30
  isCanceled: false,
@@ -1,6 +1,5 @@
1
- import { expectType, expectNotType, expectFunctionParametersType } from "@hyper-fetch/testing";
2
1
  import { Client } from "@hyper-fetch/core";
3
-
2
+ import { expectType, expectNotType, expectFunctionParametersType } from "@hyper-fetch/testing";
4
3
  import type { UseCacheReturnType } from "hooks/use-cache";
5
4
 
6
5
  const client = new Client({
@@ -1,6 +1,6 @@
1
1
  import { Socket } from "@hyper-fetch/sockets";
2
- import { act, waitFor } from "@testing-library/react";
3
2
  import { createWebsocketMockingServer, sleep, waitForConnection } from "@hyper-fetch/testing";
3
+ import { act, waitFor } from "@testing-library/react";
4
4
 
5
5
  import { renderUseEmitter } from "../../utils/use-emitter.utils";
6
6
 
@@ -1,10 +1,10 @@
1
- import { act, waitFor } from "@testing-library/react";
2
1
  import type { AdapterInstance, ResponseType } from "@hyper-fetch/core";
3
2
  import { xhrExtra } from "@hyper-fetch/core";
4
3
  import { createHttpMockingServer, sleep } from "@hyper-fetch/testing";
4
+ import { act, waitFor } from "@testing-library/react";
5
5
 
6
- import { createRequest, renderUseFetch, createCacheData, client } from "../../utils";
7
6
  import { testSuccessState, testErrorState, testInitialState, testCacheState, testClientIsolation } from "../../shared";
7
+ import { createRequest, renderUseFetch, createCacheData, client } from "../../utils";
8
8
 
9
9
  const { resetMocks, startServer, stopServer, mockRequest } = createHttpMockingServer();
10
10
 
@@ -47,8 +47,8 @@ describe("useFetch [ Base ]", () => {
47
47
  status: 200,
48
48
  success: true,
49
49
  extra: xhrExtra,
50
- responseTimestamp: +new Date(),
51
- requestTimestamp: +new Date(),
50
+ responseTimestamp: Date.now(),
51
+ requestTimestamp: Date.now(),
52
52
  },
53
53
  details: {
54
54
  retries: 2,
@@ -59,7 +59,7 @@ describe("useFetch [ Base ]", () => {
59
59
  });
60
60
  it("should show stale cache data while revalidating", async () => {
61
61
  await testClientIsolation(client);
62
- const timestamp = +new Date() - 11;
62
+ const timestamp = Date.now() - 11;
63
63
  const mock = mockRequest(request, { delay: 50 });
64
64
  act(() => {
65
65
  createCacheData(request, {
@@ -104,8 +104,8 @@ describe("useFetch [ Base ]", () => {
104
104
  status: 200,
105
105
  success: true,
106
106
  extra: { headers: { "content-type": "application/json" } },
107
- responseTimestamp: +new Date(),
108
- requestTimestamp: +new Date(),
107
+ responseTimestamp: Date.now(),
108
+ requestTimestamp: Date.now(),
109
109
  };
110
110
  const view = renderUseFetch(request, { disabled: true, initialResponse });
111
111
 
@@ -121,8 +121,8 @@ describe("useFetch [ Base ]", () => {
121
121
  status: 200,
122
122
  success: true,
123
123
  extra: { headers: { "content-type": "application/json" } },
124
- responseTimestamp: +new Date(),
125
- requestTimestamp: +new Date(),
124
+ responseTimestamp: Date.now(),
125
+ requestTimestamp: Date.now(),
126
126
  };
127
127
  const view = renderUseFetch(request, { initialResponse });
128
128
  expect(view.result.current.data).toEqual(initialResponse.data);
@@ -153,11 +153,15 @@ describe("useFetch [ Base ]", () => {
153
153
  });
154
154
  it("should map the data on deps change", async () => {
155
155
  mockRequest(request);
156
+ // Distinct queries need distinct queryKeys: deduplication joins concurrent
157
+ // requests within one queryKey queue, regardless of their cacheKey.
156
158
  const request1 = request
157
159
  .setCacheKey("request1")
160
+ .setQueryKey("request1")
158
161
  .setResponseMapper((response) => ({ ...response, data: 1 }) as typeof response);
159
162
  const request2 = request
160
163
  .setCacheKey("request2")
164
+ .setQueryKey("request2")
161
165
  .setResponseMapper((response) => ({ ...response, data: 2 }) as typeof response);
162
166
 
163
167
  const { result, rerender } = renderUseFetch(request1);
@@ -1,6 +1,6 @@
1
1
  import { getErrorMessage } from "@hyper-fetch/core";
2
- import { act, waitFor } from "@testing-library/react";
3
2
  import { createHttpMockingServer } from "@hyper-fetch/testing";
3
+ import { act, waitFor } from "@testing-library/react";
4
4
 
5
5
  import { testErrorState } from "../../shared";
6
6
  import { client, createRequest, renderUseFetch, waitForRender } from "../../utils";
@@ -1,5 +1,5 @@
1
- import { act, waitFor } from "@testing-library/react";
2
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
2
+ import { act, waitFor } from "@testing-library/react";
3
3
 
4
4
  import { client, createRequest, renderUseFetch } from "../../utils";
5
5
 
@@ -1,5 +1,5 @@
1
- import { act } from "@testing-library/react";
2
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
2
+ import { act } from "@testing-library/react";
3
3
 
4
4
  import { testSuccessState } from "../../shared";
5
5
  import { client, createRequest, renderUseFetch, waitForRender } from "../../utils";
@@ -1,5 +1,5 @@
1
- import { waitFor, act } from "@testing-library/react";
2
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
2
+ import { waitFor, act } from "@testing-library/react";
3
3
 
4
4
  import { client, createRequest, renderUseFetch, waitForRender } from "../../utils";
5
5
 
@@ -1,8 +1,8 @@
1
- import { useState, StrictMode } from "react";
2
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
3
2
  import { fireEvent, render, screen, waitFor } from "@testing-library/react";
4
-
5
3
  import { useFetch } from "hooks/use-fetch";
4
+ import { useState, StrictMode } from "react";
5
+
6
6
  import { createRequest, waitForRender } from "../../utils";
7
7
 
8
8
  const { resetMocks, startServer, stopServer, mockRequest } = createHttpMockingServer();
@@ -1,5 +1,5 @@
1
- import { waitFor } from "@testing-library/react";
2
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
2
+ import { waitFor } from "@testing-library/react";
3
3
 
4
4
  import { createRequest, renderUseFetch, client } from "../../utils";
5
5
 
@@ -1,5 +1,5 @@
1
- import { act, waitFor } from "@testing-library/react";
2
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
2
+ import { act, waitFor } from "@testing-library/react";
3
3
 
4
4
  import { testErrorState, testSuccessState } from "../../shared";
5
5
  import { client, createRequest, renderUseFetch } from "../../utils";
@@ -1,5 +1,5 @@
1
- import { waitFor, act } from "@testing-library/react";
2
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
2
+ import { waitFor, act } from "@testing-library/react";
3
3
 
4
4
  import { testErrorState, testSuccessState } from "../../shared";
5
5
  import { client, createRequest, renderUseFetch, waitForRender } from "../../utils";
@@ -1,7 +1,7 @@
1
- import { render, screen, waitFor } from "@testing-library/react";
2
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
3
-
2
+ import { render, screen, waitFor } from "@testing-library/react";
4
3
  import { useFetch } from "hooks/use-fetch";
4
+
5
5
  import { client, createRequest } from "../../utils";
6
6
 
7
7
  const { resetMocks, startServer, stopServer, mockRequest } = createHttpMockingServer();
@@ -1,5 +1,5 @@
1
- import { act } from "@testing-library/react";
2
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
2
+ import { act } from "@testing-library/react";
3
3
 
4
4
  import { client, createRequest, renderUseFetch, waitForRender } from "../../utils";
5
5
 
@@ -110,7 +110,8 @@ describe("useFetch [ Refreshing ]", () => {
110
110
  it("should refetch when tab is focused and refetchOnFocus is true", async () => {
111
111
  const spy = vi.fn();
112
112
  mockRequest(request);
113
- const { result } = renderUseFetch(request, { ...hookOptions });
113
+ // Deduplication would collapse the focus refetch into the still-running initial fetch
114
+ const { result } = renderUseFetch(request.setDeduplicate(false), { ...hookOptions });
114
115
 
115
116
  act(() => {
116
117
  result.current.onRequestStart(spy);