@web-ts-toolkit/access-router-react 0.42.2 → 0.44.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/index.mjs CHANGED
@@ -53,8 +53,41 @@ function requestConfigKeyInput(requestConfig) {
53
53
  if (!requestConfig) {
54
54
  return void 0;
55
55
  }
56
- const { signal: _signal, ...rest } = requestConfig;
57
- return Object.keys(rest).length === 0 ? void 0 : rest;
56
+ const rest = {};
57
+ let hasContent = false;
58
+ for (const k of Object.keys(requestConfig)) {
59
+ if (k === "signal") {
60
+ continue;
61
+ }
62
+ const desc = Object.getOwnPropertyDescriptor(requestConfig, k);
63
+ if (desc === void 0) {
64
+ throw new RequestKeyError(`requestKeyFor: property ${truncatedKeyLabel(k)} has no descriptor (request key).`);
65
+ }
66
+ if ("get" in desc || "set" in desc) {
67
+ throw new RequestKeyError(
68
+ `requestKeyFor: accessor property ${truncatedKeyLabel(k)} is not supported in request keys; getters/setters must not run during dep-key construction.`
69
+ );
70
+ }
71
+ rest[k] = desc.value;
72
+ hasContent = true;
73
+ }
74
+ for (const s of Object.getOwnPropertySymbols(requestConfig)) {
75
+ if (!Object.prototype.propertyIsEnumerable.call(requestConfig, s)) {
76
+ continue;
77
+ }
78
+ const desc = Object.getOwnPropertyDescriptor(requestConfig, s);
79
+ if (desc === void 0) {
80
+ throw new RequestKeyError("requestKeyFor: symbol-keyed property has no descriptor (request key).");
81
+ }
82
+ if ("get" in desc || "set" in desc) {
83
+ throw new RequestKeyError(
84
+ "requestKeyFor: accessor property (symbol key) is not supported in request keys; getters/setters must not run during dep-key construction."
85
+ );
86
+ }
87
+ rest[s] = desc.value;
88
+ hasContent = true;
89
+ }
90
+ return hasContent ? rest : void 0;
58
91
  }
59
92
  function mergeRequestConfig(requestConfig, signal) {
60
93
  if (signal === void 0) {
@@ -68,6 +101,9 @@ function useAbortManager() {
68
101
  ref.current?.abort();
69
102
  ref.current = next;
70
103
  }, []);
104
+ const abort = useCallback(() => {
105
+ ref.current?.abort();
106
+ }, []);
71
107
  useEffect(() => {
72
108
  return () => {
73
109
  ref.current?.abort();
@@ -76,7 +112,7 @@ function useAbortManager() {
76
112
  }, []);
77
113
  const managerRef = useRef(null);
78
114
  if (managerRef.current === null) {
79
- managerRef.current = { replace };
115
+ managerRef.current = { replace, abort };
80
116
  }
81
117
  return managerRef.current;
82
118
  }
@@ -89,42 +125,106 @@ var RequestKeyError = class extends Error {
89
125
  var REQUEST_KEY_MAX_DEPTH = 64;
90
126
  var REQUEST_KEY_MAX_NODES = 2e4;
91
127
  var REQUEST_KEY_MAX_OUTPUT_LENGTH = 2e5;
128
+ var intrinsicDateGetTime = Date.prototype.getTime;
129
+ function prototypeChainIncludes(value, target) {
130
+ let current = Object.getPrototypeOf(value);
131
+ while (current !== null) {
132
+ if (current === target) {
133
+ return true;
134
+ }
135
+ current = Object.getPrototypeOf(current);
136
+ }
137
+ return false;
138
+ }
139
+ function safePrototypeDisplayName(proto) {
140
+ if (proto === null) {
141
+ return "null";
142
+ }
143
+ const desc = Object.getOwnPropertyDescriptor(proto, "constructor");
144
+ if (desc !== void 0 && "value" in desc && typeof desc.value === "function" && typeof desc.value.name === "string" && desc.value.name.length > 0) {
145
+ return desc.value.name;
146
+ }
147
+ return "unknown";
148
+ }
149
+ function truncatedKeyLabel(k) {
150
+ if (k.length <= 100) {
151
+ return JSON.stringify(k);
152
+ }
153
+ return `${JSON.stringify(k.slice(0, 50))}... (key length ${k.length})`;
154
+ }
92
155
  function requestKeyFor(value) {
93
- return requestKeyForImpl(value, { stack: /* @__PURE__ */ new WeakSet(), cache: /* @__PURE__ */ new WeakMap(), nodesVisited: 0, outputLength: 0 }, 0);
156
+ return requestKeyForImpl(
157
+ value,
158
+ { stack: /* @__PURE__ */ new WeakSet(), cache: /* @__PURE__ */ new WeakMap(), nodesVisited: 0, outputLength: 0 },
159
+ 0,
160
+ false
161
+ );
162
+ }
163
+ function sortKeyFor(value) {
164
+ return requestKeyForImpl(
165
+ value,
166
+ { stack: /* @__PURE__ */ new WeakSet(), cache: /* @__PURE__ */ new WeakMap(), nodesVisited: 0, outputLength: 0 },
167
+ 0,
168
+ true
169
+ );
170
+ }
171
+ function throwRequestKeyDepthError() {
172
+ throw new RequestKeyError(
173
+ `requestKeyFor: request input exceeds the maximum depth of ${REQUEST_KEY_MAX_DEPTH} nested arrays/objects; flatten or normalize the structure before passing it to a query hook.`
174
+ );
94
175
  }
95
- function requestKeyForImpl(value, ctx, depth) {
176
+ function throwRequestKeyNodesError() {
177
+ throw new RequestKeyError(
178
+ `requestKeyFor: request input exceeds the maximum traversal budget of ${REQUEST_KEY_MAX_NODES} nodes; reduce the filter, params, or requestConfig shape before passing it to a query hook.`
179
+ );
180
+ }
181
+ function throwRequestKeyOutputError() {
182
+ throw new RequestKeyError(
183
+ `requestKeyFor: request input exceeds the maximum serialized key length of ${REQUEST_KEY_MAX_OUTPUT_LENGTH} characters; reduce repeated or oversized request data before passing it to a query hook.`
184
+ );
185
+ }
186
+ function requestKeyForImpl(value, ctx, depth, preserveObjectKeyOrder) {
187
+ return serializeRequestKeyNode(value, ctx, depth, preserveObjectKeyOrder).text;
188
+ }
189
+ function serializeRequestKeyNode(value, ctx, depth, preserveObjectKeyOrder) {
96
190
  if (depth > REQUEST_KEY_MAX_DEPTH) {
97
- throw new RequestKeyError(
98
- `requestKeyFor: request input exceeds the maximum depth of ${REQUEST_KEY_MAX_DEPTH} nested arrays/objects; flatten or normalize the structure before passing it to a query hook.`
99
- );
191
+ throwRequestKeyDepthError();
100
192
  }
101
193
  if (value === null) {
102
194
  noteRequestKeyNode(ctx);
103
- return finalizePrimitiveRequestKey(ctx, "n:");
195
+ return { text: finalizePrimitiveRequestKey(ctx, "n:"), height: 0 };
104
196
  }
105
197
  if (value === void 0) {
106
198
  noteRequestKeyNode(ctx);
107
- return finalizePrimitiveRequestKey(ctx, "u:");
199
+ return { text: finalizePrimitiveRequestKey(ctx, "u:"), height: 0 };
108
200
  }
109
201
  if (typeof value === "object") {
110
202
  const cached = ctx.cache.get(value);
111
203
  if (cached !== void 0) {
112
- reserveRequestKeyOutput(ctx, cached.length);
113
- return cached;
204
+ if (depth + cached.height > REQUEST_KEY_MAX_DEPTH) {
205
+ throwRequestKeyDepthError();
206
+ }
207
+ reserveRequestKeyOutput(ctx, cached.key.length);
208
+ return { text: cached.key, height: cached.height };
114
209
  }
115
210
  }
116
211
  noteRequestKeyNode(ctx);
117
212
  const t = typeof value;
118
213
  switch (t) {
119
214
  case "boolean":
120
- return finalizePrimitiveRequestKey(ctx, `b:${value}`);
215
+ return { text: finalizePrimitiveRequestKey(ctx, `b:${value}`), height: 0 };
121
216
  case "number": {
122
- if (Number.isNaN(value)) return finalizePrimitiveRequestKey(ctx, "n:NaN");
123
- if (Object.is(value, -0)) return finalizePrimitiveRequestKey(ctx, "n:-0");
124
- return finalizePrimitiveRequestKey(ctx, `n:${String(value)}`);
217
+ if (Number.isNaN(value)) return { text: finalizePrimitiveRequestKey(ctx, "n:NaN"), height: 0 };
218
+ if (Object.is(value, -0)) return { text: finalizePrimitiveRequestKey(ctx, "n:-0"), height: 0 };
219
+ return { text: finalizePrimitiveRequestKey(ctx, `n:${String(value)}`), height: 0 };
220
+ }
221
+ case "string": {
222
+ const rawLength = value.length;
223
+ if (ctx.outputLength + rawLength + 4 > REQUEST_KEY_MAX_OUTPUT_LENGTH) {
224
+ throwRequestKeyOutputError();
225
+ }
226
+ return { text: finalizePrimitiveRequestKey(ctx, `s:${JSON.stringify(value)}`), height: 0 };
125
227
  }
126
- case "string":
127
- return finalizePrimitiveRequestKey(ctx, `s:${JSON.stringify(value)}`);
128
228
  case "bigint":
129
229
  throw new RequestKeyError(
130
230
  "requestKeyFor: bigint is not supported in request keys; convert to a number or string before passing to a query hook."
@@ -138,12 +238,45 @@ function requestKeyForImpl(value, ctx, depth) {
138
238
  "requestKeyFor: symbol values are not supported in request keys; symbol-keyed properties cannot participate in structural comparison."
139
239
  );
140
240
  case "object": {
141
- if (value instanceof Date) {
142
- return finalizePrimitiveRequestKey(ctx, `d:${value.getTime()}`);
241
+ if (prototypeChainIncludes(value, Date.prototype)) {
242
+ if (typeof intrinsicDateGetTime !== "function") {
243
+ throw new RequestKeyError(
244
+ "requestKeyFor: Date values are not supported in this environment (Date.prototype.getTime is unavailable); pass an epoch-millis number instead."
245
+ );
246
+ }
247
+ let instant;
248
+ try {
249
+ instant = intrinsicDateGetTime.call(value);
250
+ } catch {
251
+ throw new RequestKeyError(
252
+ "requestKeyFor: invalid Date receiver in request keys; pass an epoch-millis number instead."
253
+ );
254
+ }
255
+ return { text: finalizePrimitiveRequestKey(ctx, `d:${instant}`), height: 0 };
143
256
  }
144
- if (value instanceof RegExp || value instanceof Map || value instanceof Set || typeof URL !== "undefined" && value instanceof URL || value instanceof Error) {
257
+ if (prototypeChainIncludes(value, RegExp.prototype)) {
145
258
  throw new RequestKeyError(
146
- `requestKeyFor: instance of ${value.constructor?.name ?? "unknown"} is not supported in request keys; pass its plain-data representation (e.g. a URL string, a sorted array of entries) to the query hook instead.`
259
+ "requestKeyFor: instance of RegExp is not supported in request keys; pass its plain-data representation (e.g. a source/flags string) to the query hook instead."
260
+ );
261
+ }
262
+ if (prototypeChainIncludes(value, Map.prototype)) {
263
+ throw new RequestKeyError(
264
+ "requestKeyFor: instance of Map is not supported in request keys; pass its plain-data representation (e.g. a sorted array of entries) to the query hook instead."
265
+ );
266
+ }
267
+ if (prototypeChainIncludes(value, Set.prototype)) {
268
+ throw new RequestKeyError(
269
+ "requestKeyFor: instance of Set is not supported in request keys; pass its plain-data representation (e.g. a sorted array of entries) to the query hook instead."
270
+ );
271
+ }
272
+ if (typeof URL !== "undefined" && prototypeChainIncludes(value, URL.prototype)) {
273
+ throw new RequestKeyError(
274
+ "requestKeyFor: instance of URL is not supported in request keys; pass its plain-data representation (e.g. a URL string) to the query hook instead."
275
+ );
276
+ }
277
+ if (prototypeChainIncludes(value, Error.prototype)) {
278
+ throw new RequestKeyError(
279
+ "requestKeyFor: instance of Error is not supported in request keys; pass its plain-data representation (e.g. a message string) to the query hook instead."
147
280
  );
148
281
  }
149
282
  if (Array.isArray(value)) {
@@ -153,23 +286,67 @@ function requestKeyForImpl(value, ctx, depth) {
153
286
  ctx.stack.add(value);
154
287
  reserveRequestKeyOutput(ctx, 1);
155
288
  let out2 = "[";
156
- for (let i = 0; i < value.length; i++) {
289
+ const length = value.length;
290
+ if (ctx.nodesVisited + length > REQUEST_KEY_MAX_NODES) {
291
+ throwRequestKeyNodesError();
292
+ }
293
+ let maxChildHeight2 = 0;
294
+ let hasChild2 = false;
295
+ for (let i = 0; i < length; i++) {
157
296
  if (i > 0) {
158
297
  reserveRequestKeyOutput(ctx, 1);
159
298
  out2 += ",";
160
299
  }
161
- out2 += requestKeyForImpl(value[i], ctx, depth + 1);
300
+ const indexKey = String(i);
301
+ const ownDesc = Object.getOwnPropertyDescriptor(value, indexKey);
302
+ let element;
303
+ if (ownDesc !== void 0) {
304
+ if ("get" in ownDesc || "set" in ownDesc) {
305
+ throw new RequestKeyError(
306
+ `requestKeyFor: accessor array element at index ${i} is not supported in request keys; getters/setters must not run during dep-key construction.`
307
+ );
308
+ }
309
+ element = ownDesc.value;
310
+ } else {
311
+ let inherited;
312
+ let proto2 = Object.getPrototypeOf(value);
313
+ while (proto2 !== null) {
314
+ const candidate = Object.getOwnPropertyDescriptor(proto2, indexKey);
315
+ if (candidate !== void 0) {
316
+ inherited = candidate;
317
+ break;
318
+ }
319
+ proto2 = Object.getPrototypeOf(proto2);
320
+ }
321
+ if (inherited !== void 0) {
322
+ if ("get" in inherited || "set" in inherited) {
323
+ throw new RequestKeyError(
324
+ `requestKeyFor: inherited accessor array element at index ${i} is not supported in request keys; getters/setters must not run during dep-key construction.`
325
+ );
326
+ }
327
+ element = inherited.value;
328
+ } else {
329
+ element = void 0;
330
+ }
331
+ }
332
+ const child = serializeRequestKeyNode(element, ctx, depth + 1, preserveObjectKeyOrder);
333
+ hasChild2 = true;
334
+ if (child.height + 1 > maxChildHeight2) {
335
+ maxChildHeight2 = child.height + 1;
336
+ }
337
+ out2 += child.text;
162
338
  }
163
339
  reserveRequestKeyOutput(ctx, 1);
164
340
  out2 += "]";
165
341
  ctx.stack.delete(value);
166
- ctx.cache.set(value, out2);
167
- return out2;
342
+ const height2 = hasChild2 ? maxChildHeight2 : 0;
343
+ ctx.cache.set(value, { key: out2, height: height2 });
344
+ return { text: out2, height: height2 };
168
345
  }
169
346
  const proto = Object.getPrototypeOf(value);
170
347
  if (proto !== null && proto !== Object.prototype) {
171
348
  throw new RequestKeyError(
172
- `requestKeyFor: object with prototype ${proto.constructor?.name ?? "unknown"} is not a plain object; only object literals and Object.create(null) shapes are supported in request keys.`
349
+ `requestKeyFor: object with prototype ${safePrototypeDisplayName(proto)} is not a plain object; only object literals and Object.create(null) shapes are supported in request keys.`
173
350
  );
174
351
  }
175
352
  if (ctx.stack.has(value)) {
@@ -182,9 +359,22 @@ function requestKeyForImpl(value, ctx, depth) {
182
359
  `requestKeyFor: symbol-keyed properties are not supported in request keys; remove symbol keys from the request input before passing it to a query hook.`
183
360
  );
184
361
  }
185
- const keys = Object.keys(value).sort();
362
+ const unsortedKeys = Object.keys(value);
363
+ if (ctx.nodesVisited + unsortedKeys.length > REQUEST_KEY_MAX_NODES) {
364
+ throwRequestKeyNodesError();
365
+ }
366
+ let totalKeyChars = 0;
367
+ for (let i = 0; i < unsortedKeys.length; i++) {
368
+ totalKeyChars += unsortedKeys[i].length;
369
+ }
370
+ if (ctx.outputLength + totalKeyChars + 6 * unsortedKeys.length + 2 > REQUEST_KEY_MAX_OUTPUT_LENGTH) {
371
+ throwRequestKeyOutputError();
372
+ }
373
+ const keys = preserveObjectKeyOrder ? unsortedKeys : unsortedKeys.sort();
186
374
  reserveRequestKeyOutput(ctx, 1);
187
375
  let out = "{";
376
+ let maxChildHeight = 0;
377
+ let hasChild = false;
188
378
  for (let i = 0; i < keys.length; i++) {
189
379
  if (i > 0) {
190
380
  reserveRequestKeyOutput(ctx, 1);
@@ -193,22 +383,36 @@ function requestKeyForImpl(value, ctx, depth) {
193
383
  const k = keys[i];
194
384
  const desc = Object.getOwnPropertyDescriptor(value, k);
195
385
  if (desc === void 0) {
196
- throw new RequestKeyError(`requestKeyFor: property ${JSON.stringify(k)} has no descriptor (request key).`);
386
+ throw new RequestKeyError(`requestKeyFor: property ${truncatedKeyLabel(k)} has no descriptor (request key).`);
197
387
  }
198
388
  if ("get" in desc || "set" in desc) {
199
389
  throw new RequestKeyError(
200
- `requestKeyFor: accessor property ${JSON.stringify(k)} is not supported in request keys; getters/setters must not run during dep-key construction.`
390
+ `requestKeyFor: accessor property ${truncatedKeyLabel(k)} is not supported in request keys; getters/setters must not run during dep-key construction.`
201
391
  );
202
392
  }
393
+ if (ctx.outputLength + k.length + 3 > REQUEST_KEY_MAX_OUTPUT_LENGTH) {
394
+ throwRequestKeyOutputError();
395
+ }
203
396
  const keyText = JSON.stringify(k);
204
397
  reserveRequestKeyOutput(ctx, keyText.length + 1);
205
- out += `${keyText}:${requestKeyForImpl(desc.value, ctx, depth + 1)}`;
398
+ const child = serializeRequestKeyNode(
399
+ desc.value,
400
+ ctx,
401
+ depth + 1,
402
+ preserveObjectKeyOrder
403
+ );
404
+ hasChild = true;
405
+ if (child.height + 1 > maxChildHeight) {
406
+ maxChildHeight = child.height + 1;
407
+ }
408
+ out += `${keyText}:${child.text}`;
206
409
  }
207
410
  reserveRequestKeyOutput(ctx, 1);
208
411
  out += "}";
209
412
  ctx.stack.delete(value);
210
- ctx.cache.set(value, out);
211
- return out;
413
+ const height = hasChild ? maxChildHeight : 0;
414
+ ctx.cache.set(value, { key: out, height });
415
+ return { text: out, height };
212
416
  }
213
417
  default:
214
418
  throw new RequestKeyError(`requestKeyFor: unsupported value of type ${t}.`);
@@ -217,9 +421,7 @@ function requestKeyForImpl(value, ctx, depth) {
217
421
  function noteRequestKeyNode(ctx) {
218
422
  ctx.nodesVisited += 1;
219
423
  if (ctx.nodesVisited > REQUEST_KEY_MAX_NODES) {
220
- throw new RequestKeyError(
221
- `requestKeyFor: request input exceeds the maximum traversal budget of ${REQUEST_KEY_MAX_NODES} nodes; reduce the filter, params, or requestConfig shape before passing it to a query hook.`
222
- );
424
+ throwRequestKeyNodesError();
223
425
  }
224
426
  }
225
427
  function finalizePrimitiveRequestKey(ctx, key) {
@@ -229,9 +431,7 @@ function finalizePrimitiveRequestKey(ctx, key) {
229
431
  function reserveRequestKeyOutput(ctx, length) {
230
432
  ctx.outputLength += length;
231
433
  if (ctx.outputLength > REQUEST_KEY_MAX_OUTPUT_LENGTH) {
232
- throw new RequestKeyError(
233
- `requestKeyFor: request input exceeds the maximum serialized key length of ${REQUEST_KEY_MAX_OUTPUT_LENGTH} characters; reduce repeated or oversized request data before passing it to a query hook.`
234
- );
434
+ throwRequestKeyOutputError();
235
435
  }
236
436
  }
237
437
  function useMountRef() {
@@ -274,8 +474,9 @@ function reportObserverError(error) {
274
474
  throw error;
275
475
  });
276
476
  }
277
- function runObserverSequence(invocations) {
477
+ function runObserverSequence(invocations, isAlive) {
278
478
  for (const invoke of invocations) {
479
+ if (isAlive && !isAlive()) return;
279
480
  try {
280
481
  invoke();
281
482
  } catch (error) {
@@ -318,13 +519,14 @@ function useAutoQuery({
318
519
  );
319
520
  const fireCallbacksSafely = useCallback2(
320
521
  (settle) => {
522
+ const isAlive = () => mountRef.current;
321
523
  if ("result" in settle) {
322
- runObserverSequence([() => onSuccess?.(settle.result), () => onSettled?.(settle.result, null)]);
524
+ runObserverSequence([() => onSuccess?.(settle.result), () => onSettled?.(settle.result, null)], isAlive);
323
525
  return;
324
526
  }
325
- runObserverSequence([() => onError?.(settle.error), () => onSettled?.(null, settle.error)]);
527
+ runObserverSequence([() => onError?.(settle.error), () => onSettled?.(null, settle.error)], isAlive);
326
528
  },
327
- [onSuccess, onError, onSettled]
529
+ [onSuccess, onError, onSettled, mountRef]
328
530
  );
329
531
  const runWithCallbacks = useCallback2(
330
532
  async (abortScope, doFetchOverride) => {
@@ -346,6 +548,7 @@ function useAutoQuery({
346
548
  }
347
549
  return res;
348
550
  }
551
+ if (!mountRef.current) return res;
349
552
  applyResult(res);
350
553
  hasDataRef.current = true;
351
554
  setIsLoading(false);
@@ -364,11 +567,12 @@ function useAutoQuery({
364
567
  }
365
568
  throw err;
366
569
  }
570
+ if (!mountRef.current) throw err;
367
571
  setError(err);
368
572
  if (!hasDataRef.current) setIsLoading(false);
369
573
  setIsFetching(false);
370
- fireCallbacksSafely({ error: err });
371
574
  onFailed?.();
575
+ fireCallbacksSafely({ error: err });
372
576
  throw err;
373
577
  } finally {
374
578
  release();
@@ -378,6 +582,8 @@ function useAutoQuery({
378
582
  );
379
583
  useEffect2(() => {
380
584
  if (!shouldFetch) {
585
+ ownerIdRef.current += 1;
586
+ manager.abort();
381
587
  setIsLoading(false);
382
588
  setIsFetching(false);
383
589
  onDisabled?.();
@@ -448,20 +654,20 @@ function useMutation(execute, applyData, options) {
448
654
  }
449
655
  try {
450
656
  const result = await execute(...args);
451
- if (mountRef.current) {
452
- runObserverSequence([() => onSuccess?.(result), () => onSettled?.(result, null)]);
453
- if (myId === latestIdRef.current) {
454
- setData(applyData(result));
455
- }
657
+ if (!mountRef.current) return result;
658
+ runObserverSequence([() => onSuccess?.(result), () => onSettled?.(result, null)], () => mountRef.current);
659
+ if (!mountRef.current) return result;
660
+ if (myId === latestIdRef.current) {
661
+ setData(applyData(result));
456
662
  }
457
663
  return result;
458
664
  } catch (err) {
459
665
  const svcErr = err;
460
- if (mountRef.current) {
461
- runObserverSequence([() => onError?.(svcErr), () => onSettled?.(null, svcErr)]);
462
- if (myId === latestIdRef.current) {
463
- setError(svcErr);
464
- }
666
+ if (!mountRef.current) throw svcErr;
667
+ runObserverSequence([() => onError?.(svcErr), () => onSettled?.(null, svcErr)], () => mountRef.current);
668
+ if (!mountRef.current) throw svcErr;
669
+ if (myId === latestIdRef.current) {
670
+ setError(svcErr);
465
671
  }
466
672
  throw svcErr;
467
673
  } finally {
@@ -506,11 +712,12 @@ function createModelHooks(config) {
506
712
  setData(res.data);
507
713
  }, []);
508
714
  let requestKey;
715
+ let sortKey;
509
716
  try {
717
+ sortKey = sortKeyFor(sort);
510
718
  requestKey = requestKeyFor({
511
719
  select,
512
720
  populate,
513
- sort,
514
721
  include,
515
722
  tasks,
516
723
  basicOptions,
@@ -545,12 +752,13 @@ function createModelHooks(config) {
545
752
  // objects, the key is unchanged and `doFetchById` keeps the same
546
753
  // identity — the auto-effect's `deps` therefore stays identical
547
754
  // and the network request is not retried. The `requestKey` is a
548
- // structural digest of `select/populate/sort/include/tasks/
549
- // basicOptions/advancedOptions/requestConfig`; the lint rule can-
755
+ // structural digest of `select/populate/include/tasks/
756
+ // basicOptions/advancedOptions/requestConfig`; `sortKey` is the
757
+ // order-preserving digest of `sort` (ARR-B02). The lint rule can-
550
758
  // not see that derivation, so the missing-deps warning is
551
759
  // silenced here intentionally.
552
760
  // eslint-disable-next-line react-hooks/exhaustive-deps
553
- [modelService, advanced, requestKey]
761
+ [modelService, advanced, requestKey, sortKey]
554
762
  );
555
763
  const doFetch = useCallback2(
556
764
  (signal) => {
@@ -576,7 +784,7 @@ function createModelHooks(config) {
576
784
  doFetch,
577
785
  applyResult,
578
786
  shouldFetch,
579
- deps: [id, enabled, advanced, requestKey],
787
+ deps: [id, enabled, advanced, requestKey, sortKey],
580
788
  getRequestSignal,
581
789
  onSuccess: onSuccessStable,
582
790
  onError: onErrorStable,
@@ -621,7 +829,9 @@ function createModelHooks(config) {
621
829
  latestDataRef.current = data;
622
830
  const hasSettledRef = useRef2(false);
623
831
  const applyResult = useCallback2((res) => {
624
- setData(res.data);
832
+ const next = res.data;
833
+ latestDataRef.current = next;
834
+ setData(next);
625
835
  setTotalCount(res.totalCount);
626
836
  setPreviousData(void 0);
627
837
  hasSettledRef.current = true;
@@ -636,7 +846,7 @@ function createModelHooks(config) {
636
846
  try {
637
847
  listParamsKey = requestKeyFor(listParams);
638
848
  filterKey = requestKeyFor(filter);
639
- sortKey = requestKeyFor(sort);
849
+ sortKey = sortKeyFor(sort);
640
850
  requestKey = requestKeyFor({
641
851
  select,
642
852
  populate,
@@ -686,7 +896,8 @@ function createModelHooks(config) {
686
896
  // `previousData` (ARR-08 req 1) but not in the memo identity.
687
897
  // `filterKey`, `sortKey`, `requestKey` are structural digests of
688
898
  // `filter`/`sort`/`{select, populate, include, tasks,
689
- // basicOptions, advancedOptions, requestConfig}`; the lint rule
899
+ // basicOptions, advancedOptions, requestConfig}` (`sortKey` via
900
+ // order-preserving `sortKeyFor`, ARR-B02); the lint rule
690
901
  // cannot see that derivation, so the missing-deps warning is
691
902
  // silenced here intentionally.
692
903
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -729,7 +940,9 @@ function createModelHooks(config) {
729
940
  [runQuery, baseFetch]
730
941
  );
731
942
  const reset = useCallback2(() => {
732
- setData(initialData ?? []);
943
+ const next = initialData ?? [];
944
+ latestDataRef.current = next;
945
+ setData(next);
733
946
  setPreviousData(void 0);
734
947
  setTotalCount(0);
735
948
  hasSettledRef.current = false;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@web-ts-toolkit/access-router-react",
3
3
  "description": "React hooks for @web-ts-toolkit/access-router-client model services",
4
4
  "homepage": "https://web-ts-toolkit.pages.dev/docs/packages/access-router-react",
5
- "version": "0.42.2",
5
+ "version": "0.44.0",
6
6
  "keywords": [
7
7
  "react",
8
8
  "hooks",
@@ -31,7 +31,7 @@
31
31
  "node": ">=20"
32
32
  },
33
33
  "peerDependencies": {
34
- "@web-ts-toolkit/access-router-client": "0.42.2",
34
+ "@web-ts-toolkit/access-router-client": "0.44.0",
35
35
  "react": "^18.0.0 || ^19.0.0"
36
36
  },
37
37
  "files": [