@emeryld/rrroutes-client 2.1.1 → 2.1.3

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.cjs CHANGED
@@ -475,7 +475,6 @@ var buildRoomPayloadSchema = (metaSchema) => import_zod.z.object({
475
475
 
476
476
  // src/sockets/socket.client.context.tsx
477
477
  var React = __toESM(require("react"), 1);
478
- var import_socket = require("socket.io-client");
479
478
  var import_jsx_runtime = require("react/jsx-runtime");
480
479
  var SocketCtx = React.createContext(null);
481
480
  function dbg(dbgOpts, e) {
@@ -483,16 +482,31 @@ function dbg(dbgOpts, e) {
483
482
  if (!dbgOpts[e.type]) return;
484
483
  dbgOpts.logger(e);
485
484
  }
485
+ function isProbablySocket(value) {
486
+ if (!value || typeof value !== "object") return false;
487
+ const anyVal = value;
488
+ const ctorName = anyVal.constructor?.name;
489
+ if (ctorName === "Socket") return true;
490
+ return ("connected" in anyVal || "recovered" in anyVal) && typeof anyVal.on === "function" && typeof anyVal.emit === "function";
491
+ }
492
+ function describeSocketLike(value) {
493
+ if (!value) return null;
494
+ const id = value.id ?? "unknown";
495
+ const connected = value.connected ?? false;
496
+ const recovered = typeof value.recovered === "boolean" ? ` recovered=${value.recovered}` : "";
497
+ return `[Socket id=${id} connected=${connected}${recovered}]`;
498
+ }
486
499
  function safeDescribeHookValue(value) {
487
500
  if (value == null) return value;
488
501
  const valueType = typeof value;
489
- if (valueType === "string" || valueType === "number" || valueType === "boolean") return value;
502
+ if (valueType === "string" || valueType === "number" || valueType === "boolean") {
503
+ return value;
504
+ }
490
505
  if (valueType === "bigint" || valueType === "symbol") return String(value);
491
506
  if (valueType === "function") return `[function ${value.name || "anonymous"}]`;
492
507
  if (Array.isArray(value)) return `[array length=${value.length}]`;
493
- if (value instanceof import_socket.Socket) {
494
- const socket = value;
495
- return `[Socket id=${socket.id ?? "unknown"} connected=${socket.connected ?? false}]`;
508
+ if (isProbablySocket(value)) {
509
+ return describeSocketLike(value);
496
510
  }
497
511
  const ctorName = value.constructor?.name ?? "object";
498
512
  const keys = Object.keys(value);
@@ -500,20 +514,56 @@ function safeDescribeHookValue(value) {
500
514
  const suffix = keys.length > 4 ? ",\u2026" : "";
501
515
  return `[${ctorName} keys=${keyPreview}${suffix}]`;
502
516
  }
517
+ function summarizeEvents(events) {
518
+ if (!events || typeof events !== "object") return safeDescribeHookValue(events);
519
+ const keys = Object.keys(events);
520
+ if (!keys.length) return "[events empty]";
521
+ const preview = keys.slice(0, 4).join(",");
522
+ const suffix = keys.length > 4 ? ",\u2026" : "";
523
+ return `[events count=${keys.length} keys=${preview}${suffix}]`;
524
+ }
525
+ function summarizeBaseOptions(options) {
526
+ if (!options || typeof options !== "object") return safeDescribeHookValue(options);
527
+ const obj = options;
528
+ const keys = Object.keys(obj);
529
+ if (!keys.length) return "[baseOptions empty]";
530
+ const preview = keys.slice(0, 4).join(",");
531
+ const suffix = keys.length > 4 ? ",\u2026" : "";
532
+ const hasDebug = "debug" in obj;
533
+ return `[baseOptions keys=${preview}${suffix} debug=${hasDebug}]`;
534
+ }
535
+ function summarizeMeta(meta, label) {
536
+ if (meta == null) return null;
537
+ if (typeof meta !== "object") return safeDescribeHookValue(meta);
538
+ const keys = Object.keys(meta);
539
+ if (!keys.length) return `[${label} empty]`;
540
+ const preview = keys.slice(0, 4).join(",");
541
+ const suffix = keys.length > 4 ? ",\u2026" : "";
542
+ return `[${label} keys=${preview}${suffix}]`;
543
+ }
503
544
  function createHookDebugEvent(prev, next, hook) {
504
545
  const reason = prev ? "change" : "init";
505
546
  const changed = Object.keys(next).reduce((acc, dependency) => {
506
547
  const prevValue = prev ? prev[dependency] : void 0;
507
548
  const nextValue = next[dependency];
508
549
  if (!prev || !Object.is(prevValue, nextValue)) {
509
- acc.push({ dependency, previous: safeDescribeHookValue(prevValue), next: safeDescribeHookValue(nextValue) });
550
+ acc.push({
551
+ dependency,
552
+ previous: safeDescribeHookValue(prevValue),
553
+ next: safeDescribeHookValue(nextValue)
554
+ });
510
555
  }
511
556
  return acc;
512
557
  }, []);
513
558
  if (!changed.length) return null;
514
- return { type: "hook", hook, reason, changes: changed };
559
+ return { type: "hook", phase: hook, reason, changes: changed };
515
560
  }
516
- function trackHookTrigger({ ref, hook, providerDebug, snapshot }) {
561
+ function trackHookTrigger({
562
+ ref,
563
+ hook,
564
+ providerDebug,
565
+ snapshot
566
+ }) {
517
567
  const prev = ref.current;
518
568
  ref.current = snapshot;
519
569
  if (!providerDebug?.logger || !providerDebug?.hook) return;
@@ -550,7 +600,9 @@ function SocketProvider(props) {
550
600
  ref: resolveEffectDebugRef,
551
601
  hook: "resolve_effect",
552
602
  providerDebug: providerDebugRef.current,
553
- snapshot: { resolvedSocket }
603
+ snapshot: {
604
+ resolvedSocket: describeSocketLike(resolvedSocket)
605
+ }
554
606
  });
555
607
  if (!("getSocket" in props)) return;
556
608
  let cancelled = false;
@@ -580,7 +632,11 @@ function SocketProvider(props) {
580
632
  ref: clientMemoDebugRef,
581
633
  hook: "client_memo",
582
634
  providerDebug: providerDebugRef.current,
583
- snapshot: { events, baseOptions, socket }
635
+ snapshot: {
636
+ events: summarizeEvents(events),
637
+ baseOptions: summarizeBaseOptions(baseOptions),
638
+ socket: describeSocketLike(socket)
639
+ }
584
640
  });
585
641
  const client = React.useMemo(() => {
586
642
  if (!socket) {
@@ -591,20 +647,27 @@ function SocketProvider(props) {
591
647
  dbg(providerDebugRef.current, { type: "client", phase: "init", missing: false });
592
648
  return c;
593
649
  }, [events, baseOptions, socket]);
650
+ const destroyLeaveMetaRef = React.useRef(destroyLeaveMeta);
651
+ React.useEffect(() => {
652
+ destroyLeaveMetaRef.current = destroyLeaveMeta;
653
+ }, [destroyLeaveMeta]);
594
654
  React.useEffect(() => {
595
655
  trackHookTrigger({
596
656
  ref: destroyEffectDebugRef,
597
657
  hook: "destroy_effect",
598
658
  providerDebug: providerDebugRef.current,
599
- snapshot: { client, destroyLeaveMeta }
659
+ snapshot: {
660
+ hasClient: !!client,
661
+ destroyLeaveMeta: summarizeMeta(destroyLeaveMetaRef.current, "destroyLeaveMeta")
662
+ }
600
663
  });
601
664
  return () => {
602
665
  if (client) {
603
- client.destroy(destroyLeaveMeta);
666
+ client.destroy(destroyLeaveMetaRef.current);
604
667
  dbg(providerDebugRef.current, { type: "client", phase: "destroy" });
605
668
  }
606
669
  };
607
- }, [client, destroyLeaveMeta]);
670
+ }, [client]);
608
671
  dbg(providerDebugRef.current, { type: "render", hasClient: !!client });
609
672
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SocketCtx.Provider, { value: client, children: client == null ? fallback ?? children : children });
610
673
  }
@@ -991,7 +1054,12 @@ var SocketClient = class {
991
1054
  socket: this.socket,
992
1055
  client: this
993
1056
  })) {
994
- this.dbg({ type: "room", phase: "join", rooms: this.toArray(rooms), err: "sys:room_join handler aborted join" });
1057
+ this.dbg({
1058
+ type: "room",
1059
+ phase: "join",
1060
+ rooms: this.toArray(rooms),
1061
+ err: "sys:room_join handler aborted join"
1062
+ });
995
1063
  return;
996
1064
  }
997
1065
  const list = this.toArray(rooms);
@@ -1034,7 +1102,12 @@ var SocketClient = class {
1034
1102
  socket: this.socket,
1035
1103
  client: this
1036
1104
  })) {
1037
- this.dbg({ type: "room", phase: "leave", rooms: this.toArray(rooms), err: "sys:room_leave handler aborted leave" });
1105
+ this.dbg({
1106
+ type: "room",
1107
+ phase: "leave",
1108
+ rooms: this.toArray(rooms),
1109
+ err: "sys:room_leave handler aborted leave"
1110
+ });
1038
1111
  return;
1039
1112
  }
1040
1113
  const list = this.toArray(rooms);