@chromahq/react 1.0.21 → 1.0.23
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.js +51 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -174,8 +174,16 @@ function startHealthMonitor(deps) {
|
|
|
174
174
|
} = deps;
|
|
175
175
|
clearIntervalSafe(pingIntervalRef);
|
|
176
176
|
consecutivePingFailuresRef.current = 0;
|
|
177
|
+
{
|
|
178
|
+
console.log(`[Bridge] Starting health monitor (ping every ${pingInterval}ms)`);
|
|
179
|
+
}
|
|
177
180
|
pingIntervalRef.current = setInterval(async () => {
|
|
178
|
-
if (!bridge.isConnected)
|
|
181
|
+
if (!bridge.isConnected) {
|
|
182
|
+
{
|
|
183
|
+
console.log("[Bridge] Health check skipped - not connected");
|
|
184
|
+
}
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
179
187
|
const alive = await bridge.ping();
|
|
180
188
|
if (!pingIntervalRef.current) return;
|
|
181
189
|
setIsServiceWorkerAlive(alive);
|
|
@@ -228,6 +236,12 @@ const BridgeProvider = ({
|
|
|
228
236
|
const statusRef = useRef(status);
|
|
229
237
|
const bridgeRef = useRef(bridge);
|
|
230
238
|
const isMountedRef = useRef(true);
|
|
239
|
+
useEffect(() => {
|
|
240
|
+
isMountedRef.current = true;
|
|
241
|
+
return () => {
|
|
242
|
+
isMountedRef.current = false;
|
|
243
|
+
};
|
|
244
|
+
}, []);
|
|
231
245
|
useEffect(() => {
|
|
232
246
|
statusRef.current = status;
|
|
233
247
|
}, [status]);
|
|
@@ -335,7 +349,15 @@ const BridgeProvider = ({
|
|
|
335
349
|
);
|
|
336
350
|
const scheduleSwRestartReconnect = useCallback(
|
|
337
351
|
(connectFn) => {
|
|
338
|
-
|
|
352
|
+
{
|
|
353
|
+
console.log("[Bridge] scheduleSwRestartReconnect called, isMounted:", isMountedRef.current);
|
|
354
|
+
}
|
|
355
|
+
if (!isMountedRef.current) {
|
|
356
|
+
{
|
|
357
|
+
console.log("[Bridge] Not mounted, skipping SW restart reconnect");
|
|
358
|
+
}
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
339
361
|
swRestartRetryCountRef.current++;
|
|
340
362
|
const delay = calculateBackoffDelay(
|
|
341
363
|
swRestartRetryCountRef.current,
|
|
@@ -349,13 +371,24 @@ const BridgeProvider = ({
|
|
|
349
371
|
}
|
|
350
372
|
updateStatus("reconnecting");
|
|
351
373
|
reconnectTimeoutRef.current = setTimeout(() => {
|
|
374
|
+
{
|
|
375
|
+
console.log("[Bridge] SW restart timeout fired, isMounted:", isMountedRef.current);
|
|
376
|
+
}
|
|
352
377
|
if (isMountedRef.current) connectFn();
|
|
353
378
|
}, delay);
|
|
354
379
|
},
|
|
355
380
|
[updateStatus]
|
|
356
381
|
);
|
|
357
382
|
const connect = useCallback(() => {
|
|
358
|
-
|
|
383
|
+
{
|
|
384
|
+
console.log("[Bridge] connect() called, isConnecting:", isConnectingRef.current);
|
|
385
|
+
}
|
|
386
|
+
if (isConnectingRef.current) {
|
|
387
|
+
{
|
|
388
|
+
console.log("[Bridge] Already connecting, skipping...");
|
|
389
|
+
}
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
359
392
|
isConnectingRef.current = true;
|
|
360
393
|
cleanup();
|
|
361
394
|
if (!chrome?.runtime?.connect) {
|
|
@@ -364,9 +397,15 @@ const BridgeProvider = ({
|
|
|
364
397
|
return;
|
|
365
398
|
}
|
|
366
399
|
try {
|
|
400
|
+
if (BRIDGE_ENABLE_LOGS) {
|
|
401
|
+
console.log("[Bridge] Attempting chrome.runtime.connect...");
|
|
402
|
+
}
|
|
367
403
|
const port = chrome.runtime.connect({ name: CONFIG.PORT_NAME });
|
|
368
404
|
const immediateError = consumeRuntimeError();
|
|
369
405
|
if (immediateError) throw new Error(immediateError);
|
|
406
|
+
if (BRIDGE_ENABLE_LOGS) {
|
|
407
|
+
console.log("[Bridge] Port created successfully:", port.name);
|
|
408
|
+
}
|
|
370
409
|
portRef.current = port;
|
|
371
410
|
let errorChecks = 0;
|
|
372
411
|
errorCheckIntervalRef.current = setInterval(() => {
|
|
@@ -391,20 +430,25 @@ const BridgeProvider = ({
|
|
|
391
430
|
port.onMessage.addListener(handleMessage);
|
|
392
431
|
port.onDisconnect.addListener(() => {
|
|
393
432
|
if (BRIDGE_ENABLE_LOGS) {
|
|
394
|
-
console.warn("[Bridge]
|
|
433
|
+
console.warn("[Bridge] *** onDisconnect FIRED ***");
|
|
395
434
|
}
|
|
396
435
|
isConnectingRef.current = false;
|
|
397
436
|
const disconnectError = consumeRuntimeError();
|
|
398
|
-
if (
|
|
399
|
-
console.warn("[Bridge] Disconnect error:", disconnectError);
|
|
437
|
+
if (BRIDGE_ENABLE_LOGS) {
|
|
438
|
+
console.warn("[Bridge] Disconnect error:", disconnectError || "(none)");
|
|
439
|
+
console.warn("[Bridge] isMounted:", isMountedRef.current);
|
|
400
440
|
}
|
|
401
441
|
updateStatus("disconnected");
|
|
402
442
|
cleanup();
|
|
403
443
|
if (isMountedRef.current) {
|
|
404
444
|
if (BRIDGE_ENABLE_LOGS) {
|
|
405
|
-
console.log("[Bridge]
|
|
445
|
+
console.log("[Bridge] Scheduling SW restart reconnect...");
|
|
406
446
|
}
|
|
407
447
|
scheduleSwRestartReconnect(connect);
|
|
448
|
+
} else {
|
|
449
|
+
if (BRIDGE_ENABLE_LOGS) {
|
|
450
|
+
console.log("[Bridge] Not mounted, NOT scheduling reconnect");
|
|
451
|
+
}
|
|
408
452
|
}
|
|
409
453
|
});
|
|
410
454
|
const triggerReconnect = () => {
|
|
@@ -511,7 +555,6 @@ const BridgeProvider = ({
|
|
|
511
555
|
};
|
|
512
556
|
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
513
557
|
return () => {
|
|
514
|
-
isMountedRef.current = false;
|
|
515
558
|
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
516
559
|
clearTimeoutSafe(maxRetryCooldownRef);
|
|
517
560
|
cleanup();
|