@chromahq/react 1.0.34 → 1.0.36
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 +6 -0
- package/dist/index.js +28 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,12 @@ interface Bridge {
|
|
|
8
8
|
off: (key: string, handler: (payload: unknown) => void) => void;
|
|
9
9
|
isConnected: boolean;
|
|
10
10
|
ping: () => Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Pause health checks for the specified duration.
|
|
13
|
+
* Use this before calling a message that triggers heavy/blocking operations in the SW.
|
|
14
|
+
* @param durationMs - How long to pause health checks in milliseconds
|
|
15
|
+
*/
|
|
16
|
+
pauseHealthChecks: (durationMs: number) => void;
|
|
11
17
|
}
|
|
12
18
|
interface BridgeContextValue {
|
|
13
19
|
bridge: Bridge | null;
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,7 @@ function createBridgeInstance(deps) {
|
|
|
50
50
|
isConnectedRef,
|
|
51
51
|
consecutiveTimeoutsRef,
|
|
52
52
|
reconnectionGracePeriodRef,
|
|
53
|
+
healthPausedUntilRef,
|
|
53
54
|
defaultTimeout,
|
|
54
55
|
onReconnectNeeded
|
|
55
56
|
} = deps;
|
|
@@ -167,6 +168,13 @@ function createBridgeInstance(deps) {
|
|
|
167
168
|
} catch {
|
|
168
169
|
return false;
|
|
169
170
|
}
|
|
171
|
+
},
|
|
172
|
+
pauseHealthChecks: (durationMs) => {
|
|
173
|
+
const pauseUntil = Date.now() + durationMs;
|
|
174
|
+
healthPausedUntilRef.current = pauseUntil;
|
|
175
|
+
{
|
|
176
|
+
console.log(`[Bridge] Health checks paused for ${Math.round(durationMs / 1e3)}s`);
|
|
177
|
+
}
|
|
170
178
|
}
|
|
171
179
|
};
|
|
172
180
|
return bridge;
|
|
@@ -176,6 +184,7 @@ function startHealthMonitor(deps) {
|
|
|
176
184
|
bridge,
|
|
177
185
|
pingIntervalRef,
|
|
178
186
|
consecutivePingFailuresRef,
|
|
187
|
+
healthPausedUntilRef,
|
|
179
188
|
pingInterval,
|
|
180
189
|
setIsServiceWorkerAlive,
|
|
181
190
|
onReconnectNeeded,
|
|
@@ -193,8 +202,24 @@ function startHealthMonitor(deps) {
|
|
|
193
202
|
}
|
|
194
203
|
return;
|
|
195
204
|
}
|
|
205
|
+
const pausedUntil = healthPausedUntilRef.current;
|
|
206
|
+
if (pausedUntil && Date.now() < pausedUntil) {
|
|
207
|
+
{
|
|
208
|
+
const remainingMs = pausedUntil - Date.now();
|
|
209
|
+
console.log(
|
|
210
|
+
`[Bridge] Health check skipped - paused for ${Math.round(remainingMs / 1e3)}s more`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
consecutivePingFailuresRef.current = 0;
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
196
216
|
const alive = await bridge.ping();
|
|
197
217
|
if (!pingIntervalRef.current) return;
|
|
218
|
+
const pausedUntilAfterPing = healthPausedUntilRef.current;
|
|
219
|
+
if (pausedUntilAfterPing && Date.now() < pausedUntilAfterPing) {
|
|
220
|
+
consecutivePingFailuresRef.current = 0;
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
198
223
|
setIsServiceWorkerAlive(alive);
|
|
199
224
|
if (alive) {
|
|
200
225
|
consecutivePingFailuresRef.current = 0;
|
|
@@ -242,6 +267,7 @@ const BridgeProvider = ({
|
|
|
242
267
|
const errorCheckIntervalRef = useRef(null);
|
|
243
268
|
const consecutivePingFailuresRef = useRef(0);
|
|
244
269
|
const consecutiveTimeoutsRef = useRef(0);
|
|
270
|
+
const healthPausedUntilRef = useRef(0);
|
|
245
271
|
const reconnectionGracePeriodRef = useRef(false);
|
|
246
272
|
const pendingRequestsRef = useRef(/* @__PURE__ */ new Map());
|
|
247
273
|
const eventListenersRef = useRef(/* @__PURE__ */ new Map());
|
|
@@ -496,6 +522,7 @@ const BridgeProvider = ({
|
|
|
496
522
|
isConnectedRef,
|
|
497
523
|
consecutiveTimeoutsRef,
|
|
498
524
|
reconnectionGracePeriodRef,
|
|
525
|
+
healthPausedUntilRef,
|
|
499
526
|
defaultTimeout,
|
|
500
527
|
onReconnectNeeded: triggerReconnect
|
|
501
528
|
});
|
|
@@ -536,6 +563,7 @@ const BridgeProvider = ({
|
|
|
536
563
|
bridge: bridgeInstance,
|
|
537
564
|
pingIntervalRef,
|
|
538
565
|
consecutivePingFailuresRef,
|
|
566
|
+
healthPausedUntilRef,
|
|
539
567
|
pingInterval,
|
|
540
568
|
setIsServiceWorkerAlive,
|
|
541
569
|
onReconnectNeeded: triggerReconnect,
|