@chromahq/react 1.0.14 → 1.0.15
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 +14 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -346,16 +346,26 @@ const BridgeProvider = ({
|
|
|
346
346
|
updateStatus("connecting");
|
|
347
347
|
connect();
|
|
348
348
|
}, [connect, updateStatus]);
|
|
349
|
+
const statusRef = useRef(status);
|
|
350
|
+
const bridgeRef = useRef(bridge);
|
|
351
|
+
useEffect(() => {
|
|
352
|
+
statusRef.current = status;
|
|
353
|
+
}, [status]);
|
|
354
|
+
useEffect(() => {
|
|
355
|
+
bridgeRef.current = bridge;
|
|
356
|
+
}, [bridge]);
|
|
349
357
|
useEffect(() => {
|
|
350
358
|
connect();
|
|
351
359
|
const handleVisibilityChange = () => {
|
|
352
360
|
if (document.visibilityState === "visible") {
|
|
353
|
-
|
|
361
|
+
const currentStatus = statusRef.current;
|
|
362
|
+
const currentBridge = bridgeRef.current;
|
|
363
|
+
if (currentStatus === "disconnected" || currentStatus === "error") {
|
|
354
364
|
console.log("[Bridge] Tab became visible, attempting reconnection...");
|
|
355
365
|
retryCountRef.current = 0;
|
|
356
366
|
connect();
|
|
357
|
-
} else if (
|
|
358
|
-
|
|
367
|
+
} else if (currentStatus === "connected" && currentBridge) {
|
|
368
|
+
currentBridge.ping().then((alive) => {
|
|
359
369
|
if (!alive) {
|
|
360
370
|
console.warn(
|
|
361
371
|
"[Bridge] Tab became visible but service worker unresponsive, reconnecting..."
|
|
@@ -377,7 +387,7 @@ const BridgeProvider = ({
|
|
|
377
387
|
}
|
|
378
388
|
cleanup();
|
|
379
389
|
};
|
|
380
|
-
}, [connect, cleanup
|
|
390
|
+
}, [connect, cleanup]);
|
|
381
391
|
const contextValue = useMemo(
|
|
382
392
|
() => ({
|
|
383
393
|
bridge,
|