@chromahq/react 1.0.33 → 1.0.35

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.d.ts CHANGED
@@ -32,6 +32,17 @@ interface BridgeProviderProps {
32
32
  onConnectionChange?: (status: ConnectionStatus) => void;
33
33
  /** Callback when an error occurs */
34
34
  onError?: (error: Error) => void;
35
+ /**
36
+ * Optional function to check if health checks should be paused.
37
+ * Return a timestamp (ms) until which health checks are paused, or null/0 if not paused.
38
+ * This allows service workers to pause health monitoring during heavy operations.
39
+ *
40
+ * @example
41
+ * ```tsx
42
+ * <BridgeProvider isHealthPaused={() => store.getState().healthPausedUntil}>
43
+ * ```
44
+ */
45
+ isHealthPausedUntil?: () => number | null | undefined;
35
46
  }
36
47
  declare const BridgeProvider: FC<BridgeProviderProps>;
37
48
 
package/dist/index.js CHANGED
@@ -179,7 +179,8 @@ function startHealthMonitor(deps) {
179
179
  pingInterval,
180
180
  setIsServiceWorkerAlive,
181
181
  onReconnectNeeded,
182
- rejectAllPendingRequests
182
+ rejectAllPendingRequests,
183
+ isHealthPausedUntil
183
184
  } = deps;
184
185
  clearIntervalSafe(pingIntervalRef);
185
186
  consecutivePingFailuresRef.current = 0;
@@ -193,8 +194,24 @@ function startHealthMonitor(deps) {
193
194
  }
194
195
  return;
195
196
  }
197
+ const pausedUntil = isHealthPausedUntil?.() ?? 0;
198
+ if (pausedUntil && Date.now() < pausedUntil) {
199
+ {
200
+ const remainingMs = pausedUntil - Date.now();
201
+ console.log(
202
+ `[Bridge] Health check skipped - paused for ${Math.round(remainingMs / 1e3)}s more`
203
+ );
204
+ }
205
+ consecutivePingFailuresRef.current = 0;
206
+ return;
207
+ }
196
208
  const alive = await bridge.ping();
197
209
  if (!pingIntervalRef.current) return;
210
+ const pausedUntilAfterPing = isHealthPausedUntil?.() ?? 0;
211
+ if (pausedUntilAfterPing && Date.now() < pausedUntilAfterPing) {
212
+ consecutivePingFailuresRef.current = 0;
213
+ return;
214
+ }
198
215
  setIsServiceWorkerAlive(alive);
199
216
  if (alive) {
200
217
  consecutivePingFailuresRef.current = 0;
@@ -224,7 +241,8 @@ const BridgeProvider = ({
224
241
  maxRetryCooldown = CONFIG.MAX_RETRY_COOLDOWN,
225
242
  defaultTimeout = CONFIG.DEFAULT_TIMEOUT,
226
243
  onConnectionChange,
227
- onError
244
+ onError,
245
+ isHealthPausedUntil
228
246
  }) => {
229
247
  const [bridge, setBridge] = useState(null);
230
248
  const [status, setStatus] = useState("connecting");
@@ -539,7 +557,8 @@ const BridgeProvider = ({
539
557
  pingInterval,
540
558
  setIsServiceWorkerAlive,
541
559
  onReconnectNeeded: triggerReconnect,
542
- rejectAllPendingRequests
560
+ rejectAllPendingRequests,
561
+ isHealthPausedUntil
543
562
  });
544
563
  } catch (e) {
545
564
  isConnectingRef.current = false;
@@ -555,7 +574,8 @@ const BridgeProvider = ({
555
574
  scheduleSwRestartReconnect,
556
575
  defaultTimeout,
557
576
  updateStatus,
558
- pingInterval
577
+ pingInterval,
578
+ isHealthPausedUntil
559
579
  ]);
560
580
  const reconnect = useCallback(() => {
561
581
  retryCountRef.current = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromahq/react",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "React bindings for the Chroma Chrome extension framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",