@chromahq/react 1.0.13 → 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.
Files changed (2) hide show
  1. package/dist/index.js +14 -4
  2. 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
- if (status === "disconnected" || status === "error") {
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 (status === "connected" && bridge) {
358
- bridge.ping().then((alive) => {
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, status, bridge]);
390
+ }, [connect, cleanup]);
381
391
  const contextValue = useMemo(
382
392
  () => ({
383
393
  bridge,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromahq/react",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "React bindings for the Chroma Chrome extension framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",