@chromahq/react 1.0.16 → 1.0.17

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 (2) hide show
  1. package/dist/index.js +14 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -200,6 +200,7 @@ const BridgeProvider = ({
200
200
  const retryCountRef = useRef(0);
201
201
  const reconnectTimeoutRef = useRef(null);
202
202
  const maxRetryCooldownRef = useRef(null);
203
+ const triggerReconnectTimeoutRef = useRef(null);
203
204
  const pingIntervalRef = useRef(null);
204
205
  const errorCheckIntervalRef = useRef(null);
205
206
  const consecutivePingFailuresRef = useRef(0);
@@ -233,6 +234,7 @@ const BridgeProvider = ({
233
234
  );
234
235
  const cleanup = useCallback(() => {
235
236
  clearTimeoutSafe(reconnectTimeoutRef);
237
+ clearTimeoutSafe(triggerReconnectTimeoutRef);
236
238
  clearIntervalSafe(errorCheckIntervalRef);
237
239
  clearIntervalSafe(pingIntervalRef);
238
240
  if (portRef.current) {
@@ -278,6 +280,7 @@ const BridgeProvider = ({
278
280
  }, []);
279
281
  const scheduleReconnect = useCallback(
280
282
  (connectFn) => {
283
+ if (!isMountedRef.current) return;
281
284
  if (retryCountRef.current < maxRetries) {
282
285
  retryCountRef.current++;
283
286
  const delay = calculateBackoffDelay(
@@ -287,11 +290,14 @@ const BridgeProvider = ({
287
290
  );
288
291
  console.log(`[Bridge] Reconnecting in ${delay}ms (${retryCountRef.current}/${maxRetries})`);
289
292
  updateStatus("reconnecting");
290
- reconnectTimeoutRef.current = setTimeout(connectFn, delay);
293
+ reconnectTimeoutRef.current = setTimeout(() => {
294
+ if (isMountedRef.current) connectFn();
295
+ }, delay);
291
296
  } else {
292
297
  console.warn(`[Bridge] Max retries reached. Cooldown: ${maxRetryCooldown}ms`);
293
298
  clearTimeoutSafe(maxRetryCooldownRef);
294
299
  maxRetryCooldownRef.current = setTimeout(() => {
300
+ if (!isMountedRef.current) return;
295
301
  console.log("[Bridge] Cooldown complete, reconnecting...");
296
302
  retryCountRef.current = 0;
297
303
  connectFn();
@@ -347,14 +353,19 @@ const BridgeProvider = ({
347
353
  updateStatus("disconnected");
348
354
  }
349
355
  cleanup();
350
- scheduleReconnect(connect);
356
+ if (isMountedRef.current) {
357
+ scheduleReconnect(connect);
358
+ }
351
359
  });
352
360
  const triggerReconnect = () => {
361
+ if (!isMountedRef.current) return;
353
362
  setIsServiceWorkerAlive(false);
354
363
  updateStatus("reconnecting");
355
364
  retryCountRef.current = 0;
356
365
  isConnectingRef.current = false;
357
- setTimeout(() => {
366
+ clearTimeoutSafe(triggerReconnectTimeoutRef);
367
+ triggerReconnectTimeoutRef.current = setTimeout(() => {
368
+ if (!isMountedRef.current) return;
358
369
  cleanup();
359
370
  connect();
360
371
  }, CONFIG.RECONNECT_DELAY);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromahq/react",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "React bindings for the Chroma Chrome extension framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",