@emeryld/rrroutes-client 2.6.9 → 2.6.11

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/dist/index.mjs CHANGED
@@ -1,14 +1,149 @@
1
1
  "use client";
2
2
 
3
- // src/routesV3.client.ts
3
+ // src/routesV3.client.batch.ts
4
4
  import {
5
- lowProfileParse as lowProfileParse5
5
+ lowProfileParse
6
6
  } from "@emeryld/rrroutes-contract";
7
7
  import {
8
- keepPreviousData as keepPreviousData3,
9
- useQuery as useQuery2
8
+ keepPreviousData,
9
+ useQuery
10
10
  } from "@tanstack/react-query";
11
- import { useCallback as useCallback4, useRef as useRef4 } from "react";
11
+ import { useCallback, useRef } from "react";
12
+ function buildBatchBranch(leaves, options, deps) {
13
+ const {
14
+ fetchRaw,
15
+ queryClient,
16
+ validateResponses,
17
+ getBuiltLeaf,
18
+ encodeLeafKey,
19
+ toArgsTuple: toArgsTuple2
20
+ } = deps;
21
+ const batchMethod = options.method ?? "POST";
22
+ const defaultHeaders = options.headers;
23
+ const getQueryKeys = (input) => {
24
+ const out = {};
25
+ const argsByLeaf = input ?? {};
26
+ for (const [alias, built] of Object.entries(leaves)) {
27
+ const args = argsByLeaf[alias];
28
+ out[alias] = built.getQueryKeys(...toArgsTuple2(args));
29
+ }
30
+ return out;
31
+ };
32
+ const invalidateBranch = async (input) => {
33
+ const argsByLeaf = input ?? {};
34
+ await Promise.all(
35
+ Object.entries(leaves).map(([alias, built]) => {
36
+ const args = argsByLeaf[alias];
37
+ return built.invalidate(...toArgsTuple2(args));
38
+ })
39
+ );
40
+ };
41
+ const setDataBranch = (input) => {
42
+ const out = {};
43
+ for (const [alias, def] of Object.entries(input)) {
44
+ if (!def) continue;
45
+ const built = leaves[alias];
46
+ if (!built) continue;
47
+ out[alias] = built.setData(def.updater, ...toArgsTuple2(def.args));
48
+ }
49
+ return out;
50
+ };
51
+ const fetchBranch = async (input) => {
52
+ const payload = {};
53
+ for (const [aliasRaw, built] of Object.entries(leaves)) {
54
+ const leaf = getBuiltLeaf(built);
55
+ const encodedLeaf = encodeLeafKey(leaf);
56
+ const alias = aliasRaw;
57
+ const branchInput = input[alias];
58
+ const query = branchInput?.query;
59
+ const params = branchInput?.params;
60
+ const body = branchInput?.body;
61
+ payload[aliasRaw] = {
62
+ encodedLeaf,
63
+ ...params !== void 0 ? { params } : {},
64
+ ...query !== void 0 ? { query } : {},
65
+ ...body !== void 0 ? { body } : {}
66
+ };
67
+ }
68
+ const batchResponse = await fetchRaw({
69
+ path: options.path,
70
+ method: batchMethod,
71
+ body: payload,
72
+ headers: defaultHeaders
73
+ });
74
+ const rawData = batchResponse.data;
75
+ if (!rawData || typeof rawData !== "object" || Array.isArray(rawData)) {
76
+ throw new Error(
77
+ "Batch response must be a plain object keyed by branch aliases."
78
+ );
79
+ }
80
+ const mapped = {};
81
+ for (const [aliasRaw, built] of Object.entries(leaves)) {
82
+ if (!(aliasRaw in rawData)) {
83
+ throw new Error(`Batch response missing alias "${aliasRaw}".`);
84
+ }
85
+ const leaf = getBuiltLeaf(built);
86
+ const rawLeafData = rawData[aliasRaw];
87
+ const parsedLeafData = validateResponses && leaf.cfg.outputSchema ? lowProfileParse(leaf.cfg.outputSchema, rawLeafData) : rawLeafData;
88
+ if (validateResponses && !leaf.cfg.outputSchema) {
89
+ throw new Error(
90
+ `No output schema defined for leaf ${leaf.method.toUpperCase()} ${leaf.path}, cannot validate batch response.`
91
+ );
92
+ }
93
+ ;
94
+ mapped[aliasRaw] = parsedLeafData;
95
+ }
96
+ return mapped;
97
+ };
98
+ const useEndpoint = (input, rqOpts) => {
99
+ const queryKeys = getQueryKeys(input);
100
+ const branchQueryKey = [
101
+ "batch",
102
+ String(batchMethod).toLowerCase(),
103
+ options.path,
104
+ queryKeys
105
+ ];
106
+ const { onReceive, ...useQueryOptions } = rqOpts ?? {};
107
+ const listenersRef = useRef(/* @__PURE__ */ new Set());
108
+ const notifyOnReceive = useCallback(
109
+ (data) => {
110
+ onReceive?.(data);
111
+ listenersRef.current.forEach((listener) => listener(data));
112
+ },
113
+ [onReceive]
114
+ );
115
+ const registerOnReceive = useCallback(
116
+ (listener) => {
117
+ listenersRef.current.add(listener);
118
+ return () => {
119
+ listenersRef.current.delete(listener);
120
+ };
121
+ },
122
+ []
123
+ );
124
+ const queryResult = useQuery(
125
+ {
126
+ ...useQueryOptions,
127
+ queryKey: branchQueryKey,
128
+ placeholderData: useQueryOptions.placeholderData ?? keepPreviousData,
129
+ queryFn: async () => {
130
+ const result = await fetchBranch(input);
131
+ notifyOnReceive(result);
132
+ return result;
133
+ }
134
+ },
135
+ queryClient
136
+ );
137
+ return { ...queryResult, onReceive: registerOnReceive };
138
+ };
139
+ return {
140
+ fetch: fetchBranch,
141
+ useEndpoint,
142
+ getQueryKeys,
143
+ invalidate: invalidateBranch,
144
+ setData: setDataBranch
145
+ };
146
+ }
12
147
 
13
148
  // src/routesV3.client.fetch.ts
14
149
  var HttpError = class extends Error {
@@ -62,15 +197,15 @@ var defaultFetcher = async (req) => {
62
197
  };
63
198
 
64
199
  // src/routesV3.client.get.ts
65
- import { buildCacheKey, lowProfileParse as lowProfileParse2 } from "@emeryld/rrroutes-contract";
200
+ import { buildCacheKey, lowProfileParse as lowProfileParse3 } from "@emeryld/rrroutes-contract";
66
201
  import {
67
- keepPreviousData,
68
- useQuery
202
+ keepPreviousData as keepPreviousData2,
203
+ useQuery as useQuery2
69
204
  } from "@tanstack/react-query";
70
- import { useCallback, useRef } from "react";
205
+ import { useCallback as useCallback2, useRef as useRef2 } from "react";
71
206
 
72
207
  // src/routesV3.client.shared.ts
73
- import { compilePath, lowProfileParse } from "@emeryld/rrroutes-contract";
208
+ import { compilePath, lowProfileParse as lowProfileParse2 } from "@emeryld/rrroutes-contract";
74
209
  var toUpper = (m) => m.toUpperCase();
75
210
  function toSearchString(query) {
76
211
  if (!query) return "";
@@ -120,8 +255,8 @@ function toArgsTuple(args) {
120
255
  return typeof args === "undefined" ? [] : [args];
121
256
  }
122
257
  function buildUrl(leaf, baseUrl, params, query) {
123
- const normalizedParams = leaf.cfg.paramsSchema ? lowProfileParse(leaf.cfg.paramsSchema, params) : {};
124
- const normalizedQuery = leaf.cfg.querySchema ? lowProfileParse(leaf.cfg.querySchema, query) : {};
258
+ const normalizedParams = leaf.cfg.paramsSchema ? lowProfileParse2(leaf.cfg.paramsSchema, params) : {};
259
+ const normalizedQuery = leaf.cfg.querySchema ? lowProfileParse2(leaf.cfg.querySchema, query) : {};
125
260
  const path = compilePath(
126
261
  leaf.path,
127
262
  normalizedParams ?? {}
@@ -356,7 +491,7 @@ function buildGetLeaf(leaf, rqOpts, env) {
356
491
  options.body,
357
492
  leafCfg.bodyFiles
358
493
  );
359
- const normalizedBody = leafCfg.bodySchema ? lowProfileParse2(leafCfg.bodySchema, regularBody) : regularBody;
494
+ const normalizedBody = leafCfg.bodySchema ? lowProfileParse3(leafCfg.bodySchema, regularBody) : regularBody;
360
495
  if (isMultipart && normalizedBody && typeof normalizedBody === "object") {
361
496
  payload = toFormData(
362
497
  {
@@ -413,7 +548,7 @@ function buildGetLeaf(leaf, rqOpts, env) {
413
548
  `No output schema defined for leaf ${leafLabel}, cannot validate response.`
414
549
  );
415
550
  }
416
- out.data = lowProfileParse2(
551
+ out.data = lowProfileParse3(
417
552
  leafCfg.outputSchema,
418
553
  out.data
419
554
  );
@@ -480,12 +615,12 @@ function buildGetLeaf(leaf, rqOpts, env) {
480
615
  keys: queryKeys
481
616
  });
482
617
  const buildOptions = rqOpts ?? {};
483
- const listenersRef = useRef(/* @__PURE__ */ new Set());
484
- const notifyOnReceive = useCallback((data) => {
618
+ const listenersRef = useRef2(/* @__PURE__ */ new Set());
619
+ const notifyOnReceive = useCallback2((data) => {
485
620
  buildOptions?.onReceive?.(data);
486
621
  listenersRef.current.forEach((listener) => listener(data));
487
622
  }, []);
488
- const registerOnReceive = useCallback(
623
+ const registerOnReceive = useCallback2(
489
624
  (listener) => {
490
625
  listenersRef.current.add(listener);
491
626
  return () => {
@@ -494,11 +629,11 @@ function buildGetLeaf(leaf, rqOpts, env) {
494
629
  },
495
630
  []
496
631
  );
497
- const queryResult = useQuery(
632
+ const queryResult = useQuery2(
498
633
  {
499
634
  ...buildOptions,
500
635
  queryKey: getQueryKeys(...tuple),
501
- placeholderData: keepPreviousData,
636
+ placeholderData: keepPreviousData2,
502
637
  queryFn: () => fetchEndpoint(tuple, {
503
638
  onReceive: notifyOnReceive
504
639
  })
@@ -517,12 +652,12 @@ function buildGetLeaf(leaf, rqOpts, env) {
517
652
  }
518
653
 
519
654
  // src/routesV3.client.infiniteGet.ts
520
- import { buildCacheKey as buildCacheKey2, lowProfileParse as lowProfileParse3 } from "@emeryld/rrroutes-contract";
655
+ import { buildCacheKey as buildCacheKey2, lowProfileParse as lowProfileParse4 } from "@emeryld/rrroutes-contract";
521
656
  import {
522
- keepPreviousData as keepPreviousData2,
657
+ keepPreviousData as keepPreviousData3,
523
658
  useInfiniteQuery
524
659
  } from "@tanstack/react-query";
525
- import { useCallback as useCallback2, useRef as useRef2 } from "react";
660
+ import { useCallback as useCallback3, useRef as useRef3 } from "react";
526
661
  function mergePageOutputs(prev, next) {
527
662
  if (prev == null) return next;
528
663
  if (next == null) return prev;
@@ -632,7 +767,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
632
767
  options.body,
633
768
  leafCfg.bodyFiles
634
769
  );
635
- const normalizedBody = leafCfg.bodySchema ? lowProfileParse3(leafCfg.bodySchema, regularBody) : regularBody;
770
+ const normalizedBody = leafCfg.bodySchema ? lowProfileParse4(leafCfg.bodySchema, regularBody) : regularBody;
636
771
  if (isMultipart && normalizedBody && typeof normalizedBody === "object") {
637
772
  payload = toFormData(
638
773
  {
@@ -689,7 +824,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
689
824
  `No output schema defined for leaf ${leafLabel}, cannot validate response.`
690
825
  );
691
826
  }
692
- out.data = lowProfileParse3(
827
+ out.data = lowProfileParse4(
693
828
  leafCfg.outputSchema,
694
829
  out.data
695
830
  );
@@ -758,12 +893,12 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
758
893
  const params = args?.params;
759
894
  const query = args?.query;
760
895
  const buildOptions = feedQueryOptions ?? {};
761
- const listenersRef = useRef2(/* @__PURE__ */ new Set());
762
- const notifyOnReceive = useCallback2((data) => {
896
+ const listenersRef = useRef3(/* @__PURE__ */ new Set());
897
+ const notifyOnReceive = useCallback3((data) => {
763
898
  buildOptions?.onReceive?.(data);
764
899
  listenersRef.current.forEach((listener) => listener(data));
765
900
  }, []);
766
- const registerOnReceive = useCallback2(
901
+ const registerOnReceive = useCallback3(
767
902
  (listener) => {
768
903
  listenersRef.current.add(listener);
769
904
  return () => {
@@ -781,7 +916,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
781
916
  const queryResult = useInfiniteQuery(
782
917
  {
783
918
  ...buildOptions,
784
- placeholderData: buildOptions.placeholderData ?? keepPreviousData2,
919
+ placeholderData: buildOptions.placeholderData ?? keepPreviousData3,
785
920
  initialPageParam: feedInitialPageParam,
786
921
  getNextPageParam: (lastPage) => cursorFromPage(lastPage),
787
922
  queryKey: queryKeys,
@@ -874,11 +1009,11 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
874
1009
  }
875
1010
 
876
1011
  // src/routesV3.client.mutation.ts
877
- import { buildCacheKey as buildCacheKey3, lowProfileParse as lowProfileParse4 } from "@emeryld/rrroutes-contract";
1012
+ import { buildCacheKey as buildCacheKey3, lowProfileParse as lowProfileParse5 } from "@emeryld/rrroutes-contract";
878
1013
  import {
879
1014
  useMutation
880
1015
  } from "@tanstack/react-query";
881
- import { useCallback as useCallback3, useRef as useRef3 } from "react";
1016
+ import { useCallback as useCallback4, useRef as useRef4 } from "react";
882
1017
  function buildMutationLeaf(leaf, rqOpts, env) {
883
1018
  const leafCfg = leaf.cfg;
884
1019
  const method = toUpper(leaf.method);
@@ -942,7 +1077,7 @@ function buildMutationLeaf(leaf, rqOpts, env) {
942
1077
  options.body,
943
1078
  leafCfg.bodyFiles
944
1079
  );
945
- const normalizedBody = leafCfg.bodySchema ? lowProfileParse4(leafCfg.bodySchema, regularBody) : regularBody;
1080
+ const normalizedBody = leafCfg.bodySchema ? lowProfileParse5(leafCfg.bodySchema, regularBody) : regularBody;
946
1081
  if (isMultipart && normalizedBody && typeof normalizedBody === "object") {
947
1082
  payload = toFormData(
948
1083
  {
@@ -999,7 +1134,7 @@ function buildMutationLeaf(leaf, rqOpts, env) {
999
1134
  `No output schema defined for leaf ${leafLabel}, cannot validate response.`
1000
1135
  );
1001
1136
  }
1002
- out.data = lowProfileParse4(
1137
+ out.data = lowProfileParse5(
1003
1138
  leafCfg.outputSchema,
1004
1139
  out.data
1005
1140
  );
@@ -1066,11 +1201,11 @@ function buildMutationLeaf(leaf, rqOpts, env) {
1066
1201
  variant: "mutation",
1067
1202
  keys: mutationKey
1068
1203
  });
1069
- const listenersRef = useRef3(/* @__PURE__ */ new Set());
1070
- const notifyListeners = useCallback3((data) => {
1204
+ const listenersRef = useRef4(/* @__PURE__ */ new Set());
1205
+ const notifyListeners = useCallback4((data) => {
1071
1206
  listenersRef.current.forEach((listener) => listener(data));
1072
1207
  }, []);
1073
- const registerOnReceive = useCallback3(
1208
+ const registerOnReceive = useCallback4(
1074
1209
  (listener) => {
1075
1210
  listenersRef.current.add(listener);
1076
1211
  return () => {
@@ -1309,146 +1444,14 @@ function createRouteClient(opts) {
1309
1444
  throw error;
1310
1445
  }
1311
1446
  };
1312
- const buildBranchInternal = (leaves, options) => {
1313
- const batchMethod = options.method ?? "POST";
1314
- const defaultHeaders = options.headers;
1315
- const getQueryKeys = (input) => {
1316
- const out = {};
1317
- const argsByLeaf = input ?? {};
1318
- for (const [alias, built] of Object.entries(leaves)) {
1319
- const args = argsByLeaf[alias];
1320
- out[alias] = built.getQueryKeys(...toArgsTuple2(args));
1321
- }
1322
- return out;
1323
- };
1324
- const invalidateBranch = async (input) => {
1325
- const argsByLeaf = input ?? {};
1326
- await Promise.all(
1327
- Object.entries(leaves).map(([alias, built]) => {
1328
- const args = argsByLeaf[alias];
1329
- return built.invalidate(...toArgsTuple2(args));
1330
- })
1331
- );
1332
- };
1333
- const setDataBranch = (input) => {
1334
- const out = {};
1335
- for (const [alias, def] of Object.entries(input)) {
1336
- if (!def) continue;
1337
- const built = leaves[alias];
1338
- if (!built) continue;
1339
- out[alias] = built.setData(
1340
- def.updater,
1341
- ...toArgsTuple2(def.args)
1342
- );
1343
- }
1344
- return out;
1345
- };
1346
- const fetchBranch = async (input) => {
1347
- const payload = {};
1348
- const keyByAlias = /* @__PURE__ */ new Map();
1349
- for (const [aliasRaw, built] of Object.entries(leaves)) {
1350
- const alias = aliasRaw;
1351
- const leaf = getBuiltLeaf(built);
1352
- const encodedLeaf = encodeLeafKey(leaf);
1353
- keyByAlias.set(alias, encodedLeaf);
1354
- const branchInput = input[alias];
1355
- const query = branchInput?.query;
1356
- const params = branchInput?.params;
1357
- const body = branchInput?.body;
1358
- payload[encodedLeaf] = {
1359
- ...params !== void 0 ? { params } : {},
1360
- ...query !== void 0 ? { query } : {},
1361
- ...body !== void 0 ? { body } : {}
1362
- };
1363
- }
1364
- const batchResponse = await fetchRaw({
1365
- path: options.path,
1366
- method: batchMethod,
1367
- body: payload,
1368
- headers: defaultHeaders
1369
- });
1370
- const rawData = batchResponse.data;
1371
- if (!rawData || typeof rawData !== "object" || Array.isArray(rawData)) {
1372
- throw new Error(
1373
- "Batch response must be a plain object keyed by encoded route keys."
1374
- );
1375
- }
1376
- const mapped = {};
1377
- for (const [aliasRaw, built] of Object.entries(leaves)) {
1378
- const alias = aliasRaw;
1379
- const encodedLeaf = keyByAlias.get(alias);
1380
- if (!encodedLeaf) {
1381
- throw new Error(
1382
- `Internal batch error: missing encoded key for alias "${String(alias)}".`
1383
- );
1384
- }
1385
- if (!(encodedLeaf in rawData)) {
1386
- throw new Error(`Batch response missing key "${encodedLeaf}".`);
1387
- }
1388
- const leaf = getBuiltLeaf(built);
1389
- const rawLeafData = rawData[encodedLeaf];
1390
- const parsedLeafData = validateResponses && leaf.cfg.outputSchema ? lowProfileParse5(leaf.cfg.outputSchema, rawLeafData) : rawLeafData;
1391
- if (validateResponses && !leaf.cfg.outputSchema) {
1392
- throw new Error(
1393
- `No output schema defined for leaf ${leaf.method.toUpperCase()} ${leaf.path}, cannot validate batch response.`
1394
- );
1395
- }
1396
- ;
1397
- mapped[aliasRaw] = parsedLeafData;
1398
- }
1399
- return mapped;
1400
- };
1401
- const useEndpoint = (input, rqOpts) => {
1402
- const queryKeys = getQueryKeys(input);
1403
- const branchQueryKey = [
1404
- "batch",
1405
- String(batchMethod).toLowerCase(),
1406
- options.path,
1407
- queryKeys
1408
- ];
1409
- const { onReceive, ...useQueryOptions } = rqOpts ?? {};
1410
- const listenersRef = useRef4(
1411
- /* @__PURE__ */ new Set()
1412
- );
1413
- const notifyOnReceive = useCallback4(
1414
- (data) => {
1415
- onReceive?.(data);
1416
- listenersRef.current.forEach((listener) => listener(data));
1417
- },
1418
- [onReceive]
1419
- );
1420
- const registerOnReceive = useCallback4(
1421
- (listener) => {
1422
- listenersRef.current.add(listener);
1423
- return () => {
1424
- listenersRef.current.delete(listener);
1425
- };
1426
- },
1427
- []
1428
- );
1429
- const queryResult = useQuery2(
1430
- {
1431
- ...useQueryOptions,
1432
- queryKey: branchQueryKey,
1433
- placeholderData: useQueryOptions.placeholderData ?? keepPreviousData3,
1434
- queryFn: async () => {
1435
- const result = await fetchBranch(input);
1436
- notifyOnReceive(result);
1437
- return result;
1438
- }
1439
- },
1440
- queryClient
1441
- );
1442
- return { ...queryResult, onReceive: registerOnReceive };
1443
- };
1444
- return {
1445
- fetch: fetchBranch,
1446
- useEndpoint,
1447
- getQueryKeys,
1448
- invalidate: invalidateBranch,
1449
- setData: setDataBranch
1450
- };
1451
- };
1447
+ const buildBranchInternal = (leaves, options) => buildBatchBranch(leaves, options, {
1448
+ fetchRaw,
1449
+ queryClient,
1450
+ validateResponses,
1451
+ getBuiltLeaf,
1452
+ encodeLeafKey,
1453
+ toArgsTuple: toArgsTuple2
1454
+ });
1452
1455
  return {
1453
1456
  queryClient,
1454
1457
  invalidate,
@@ -1474,8 +1477,9 @@ import * as React from "react";
1474
1477
  var SocketCtx = React.createContext(null);
1475
1478
  function useSocketClient() {
1476
1479
  const ctx = React.useContext(SocketCtx);
1477
- if (!ctx)
1478
- throw new Error("SocketClient not found. Wrap with <SocketProvider>.");
1480
+ if (!ctx) {
1481
+ return null;
1482
+ }
1479
1483
  return ctx;
1480
1484
  }
1481
1485
 
@@ -1504,6 +1508,7 @@ function useSocketConnection(args) {
1504
1508
  []
1505
1509
  );
1506
1510
  React2.useEffect(() => {
1511
+ if (!client) return;
1507
1512
  if (autoJoin && normalizedRooms.length > 0)
1508
1513
  void client.joinRooms(normalizedRooms, args.joinMeta).catch((error) => reportAsyncError("joinRooms", error));
1509
1514
  const unsubscribe = client.on(event, (payload, meta) => {
@@ -2693,12 +2698,12 @@ function mergeRoomState(prev, toRoomsResult) {
2693
2698
  leaveMeta: toRoomsResult.leaveMeta ?? prev.leaveMeta
2694
2699
  };
2695
2700
  }
2696
- function roomsFromData(data, toRooms) {
2701
+ function roomsFromData(data, args, toRooms) {
2697
2702
  if (data == null) return { rooms: [] };
2698
2703
  let state = { rooms: [] };
2699
2704
  const add = (input) => {
2700
2705
  const mergeForValue = (value) => {
2701
- state = mergeRoomState(state, toRooms(value));
2706
+ state = mergeRoomState(state, toRooms(value, ...args));
2702
2707
  };
2703
2708
  if (Array.isArray(input)) {
2704
2709
  input.forEach((entry) => mergeForValue(entry));
@@ -2743,7 +2748,11 @@ function buildSocketedRoute(options) {
2743
2748
  );
2744
2749
  const argsKey = useMemo3(() => safeJsonKey(useArgs[0] ?? null), [useArgs]);
2745
2750
  const [roomState, setRoomState] = useState2(
2746
- () => roomsFromData(endpointResult.data, toRooms)
2751
+ () => roomsFromData(
2752
+ endpointResult.data,
2753
+ useArgs,
2754
+ toRooms
2755
+ )
2747
2756
  );
2748
2757
  const renderCountRef = useRef6(0);
2749
2758
  const clientReadyRef = useRef6(null);
@@ -2797,7 +2806,10 @@ function buildSocketedRoute(options) {
2797
2806
  });
2798
2807
  const unsubscribe = endpointResult.onReceive((data) => {
2799
2808
  setRoomState((prev) => {
2800
- const next = mergeRoomState(prev, toRoomsRef.current(data));
2809
+ const next = mergeRoomState(
2810
+ prev,
2811
+ toRoomsRef.current(data, ...useArgs)
2812
+ );
2801
2813
  return roomStateEqual(prev, next) ? prev : next;
2802
2814
  });
2803
2815
  });
@@ -2814,7 +2826,7 @@ function buildSocketedRoute(options) {
2814
2826
  toRoomsRef: describeObjectReference(toRooms)
2815
2827
  }
2816
2828
  });
2817
- const next = roomsFromData(endpointDataRef.current, toRooms);
2829
+ const next = roomsFromData(endpointDataRef.current, useArgs, toRooms);
2818
2830
  setRoomState((prev) => roomStateEqual(prev, next) ? prev : next);
2819
2831
  }, [argsKey, toRooms, debug]);
2820
2832
  useEffect3(() => {
@@ -2944,6 +2956,7 @@ function buildSocketedRoute(options) {
2944
2956
  }
2945
2957
  const nextRoomState = roomsFromData(
2946
2958
  next,
2959
+ useArgs,
2947
2960
  toRooms
2948
2961
  );
2949
2962
  setRoomState(