@calimero-network/mero-react 9.14.0 → 9.14.1

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
@@ -4364,23 +4364,25 @@ function useJoinSync({
4364
4364
  settled,
4365
4365
  active
4366
4366
  }) {
4367
- const [tick, setTick] = react.useState(0);
4367
+ const [, storeChanged] = react.useReducer((n) => n + 1, 0);
4368
+ react.useEffect(() => {
4369
+ const unsubscribe = subscribeJustJoined(storeChanged);
4370
+ storeChanged();
4371
+ return unsubscribe;
4372
+ }, []);
4373
+ const flagged = isNamespaceJustJoined(namespaceId);
4368
4374
  const firstSeen = react.useRef(/* @__PURE__ */ new Map());
4375
+ if (namespaceId && flagged && !firstSeen.current.has(namespaceId)) {
4376
+ firstSeen.current.set(namespaceId, Date.now());
4377
+ } else if (namespaceId && !flagged) {
4378
+ firstSeen.current.delete(namespaceId);
4379
+ }
4369
4380
  const activeRef = react.useRef(active);
4370
4381
  activeRef.current = active;
4371
- const flagged = react.useMemo(() => {
4372
- if (!namespaceId) return false;
4373
- if (!isNamespaceJustJoined(namespaceId)) return false;
4374
- if (!firstSeen.current.has(namespaceId)) {
4375
- firstSeen.current.set(namespaceId, Date.now());
4376
- }
4377
- return true;
4378
- }, [namespaceId, tick]);
4379
4382
  react.useEffect(() => {
4380
- if (!namespaceId || !flagged || !settled) return;
4383
+ if (!namespaceId || !settled || !isNamespaceJustJoined(namespaceId)) return;
4381
4384
  clearNamespaceJustJoined(namespaceId);
4382
- setTick((t) => t + 1);
4383
- }, [namespaceId, flagged, settled]);
4385
+ });
4384
4386
  react.useEffect(() => {
4385
4387
  if (!namespaceId || !flagged || settled) return;
4386
4388
  const since = firstSeen.current.get(namespaceId) ?? Date.now();
@@ -4390,7 +4392,6 @@ function useJoinSync({
4390
4392
  const giveUp = elapsed >= JOIN_SYNC_MAX_MS || elapsed >= JOIN_SYNC_WATCHDOG_MS && !activeRef.current;
4391
4393
  if (giveUp) {
4392
4394
  clearNamespaceJustJoined(namespaceId);
4393
- setTick((t) => t + 1);
4394
4395
  return;
4395
4396
  }
4396
4397
  timer = setTimeout(check, JOIN_SYNC_POLL_MS);
@@ -4403,7 +4404,6 @@ function useJoinSync({
4403
4404
  dismiss: () => {
4404
4405
  if (!namespaceId) return;
4405
4406
  clearNamespaceJustJoined(namespaceId);
4406
- setTick((t) => t + 1);
4407
4407
  }
4408
4408
  };
4409
4409
  }