@checkstack/signal-frontend 0.0.15 → 0.1.0
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/CHANGELOG.md +42 -0
- package/package.json +2 -2
- package/src/SignalProvider.tsx +34 -1
- package/src/index.ts +10 -2
- package/src/useSignal.ts +25 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# @checkstack/signal-frontend
|
|
2
2
|
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 208ad71: Centralize realtime cache invalidation: signals now carry their owning `pluginId` end-to-end, and a single `SignalAutoInvalidator` mounted near the React Query client invalidates `[[pluginId]]` for every incoming signal automatically.
|
|
8
|
+
|
|
9
|
+
**Breaking change to `createSignal`** (`@checkstack/signal-common`): the factory now takes a single object argument with `pluginMetadata`, `event`, and `payloadSchema`. The signal id is constructed as `${pluginMetadata.pluginId}.${event}` and the resulting `Signal` carries a `pluginId` field. The `SignalMessage` wire envelope and `ServerToClientMessage` `signal` variant gained a `pluginId` field so the frontend can route invalidations without parsing the id.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// Before
|
|
13
|
+
export const ANOMALY_STATE_CHANGED = createSignal(
|
|
14
|
+
"anomaly.state_changed",
|
|
15
|
+
z.object({ ... }),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
// After
|
|
19
|
+
export const ANOMALY_STATE_CHANGED = createSignal({
|
|
20
|
+
pluginMetadata,
|
|
21
|
+
event: "state_changed",
|
|
22
|
+
payloadSchema: z.object({ ... }),
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**New plugin field**: `FrontendPlugin.foreignSignals?: Signal<unknown>[]` lets a plugin opt its `[[pluginId]]` cache into invalidation when another plugin's signal fires (e.g. `dependency-frontend` declares `[SYSTEM_STATUS_CHANGED]` because dependency payloads embed system status). Same-plugin signals must NOT be listed — they are always auto-invalidated.
|
|
27
|
+
|
|
28
|
+
**Removed boilerplate**: per-component `useSignal(X, () => refetch())` and `useSignal(X, () => queryClient.invalidateQueries(...))` calls have been removed across `incident-frontend`, `maintenance-frontend`, `healthcheck-frontend`, `slo-frontend`, `dependency-frontend`, `satellite-frontend`, `announcement-frontend`, `notification-frontend`, and `dashboard-frontend`. The `NotificationBell` unread count is now derived directly from the `getUnreadCount` query (auto-invalidated) instead of a local state mirror.
|
|
29
|
+
|
|
30
|
+
**User-visible bug fix**: the system detail page anomaly widget (`SystemAnomalyWidget`) now updates in real-time when anomalies change, with no per-widget signal subscription required. The dashboard status page also stays fresh on `ANOMALY_STATE_CHANGED`, `ANOMALY_BASELINE_UPDATED`, and `ANOMALY_TREND_DETECTED`.
|
|
31
|
+
|
|
32
|
+
UI-state consumers that legitimately need a `useSignal` (the dashboard activity terminal, the queue lag alert, and the rolling-preset date refresh in `useHealthCheckData`) keep their handlers; the auto-invalidator runs alongside them.
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- Updated dependencies [208ad71]
|
|
37
|
+
- @checkstack/signal-common@0.2.0
|
|
38
|
+
|
|
39
|
+
## 0.0.16
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- @checkstack/signal-common@0.1.10
|
|
44
|
+
|
|
3
45
|
## 0.0.15
|
|
4
46
|
|
|
5
47
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/signal-frontend",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"react": "^18.0.0"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@checkstack/signal-common": "0.1.
|
|
14
|
+
"@checkstack/signal-common": "0.1.10"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@types/react": "^18.0.0",
|
package/src/SignalProvider.tsx
CHANGED
|
@@ -15,11 +15,27 @@ import type {
|
|
|
15
15
|
// CONTEXT TYPES
|
|
16
16
|
// =============================================================================
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Wildcard subscription callback. Fires for every incoming signal message
|
|
20
|
+
* regardless of signalId, with the pluginId already extracted from the wire envelope.
|
|
21
|
+
* Used by the auto-invalidation layer; not intended for component-level use.
|
|
22
|
+
*/
|
|
23
|
+
export type SignalAllCallback = (props: {
|
|
24
|
+
signalId: string;
|
|
25
|
+
pluginId: string;
|
|
26
|
+
payload: unknown;
|
|
27
|
+
}) => void;
|
|
28
|
+
|
|
18
29
|
interface SignalContextValue {
|
|
19
30
|
/** Whether the WebSocket connection is established */
|
|
20
31
|
isConnected: boolean;
|
|
21
|
-
/** Subscribe to a signal. Returns an unsubscribe function. */
|
|
32
|
+
/** Subscribe to a specific signal. Returns an unsubscribe function. */
|
|
22
33
|
subscribe<T>(signal: Signal<T>, callback: (payload: T) => void): () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Subscribe to ALL incoming signals. Returns an unsubscribe function.
|
|
36
|
+
* Used by the auto-invalidation layer to receive every message.
|
|
37
|
+
*/
|
|
38
|
+
subscribeAll(callback: SignalAllCallback): () => void;
|
|
23
39
|
}
|
|
24
40
|
|
|
25
41
|
const SignalContext = createContext<SignalContextValue | undefined>(undefined);
|
|
@@ -58,6 +74,7 @@ export const SignalProvider: React.FC<SignalProviderProps> = ({
|
|
|
58
74
|
const listenersRef = useRef<Map<string, Set<(payload: unknown) => void>>>(
|
|
59
75
|
new Map()
|
|
60
76
|
);
|
|
77
|
+
const allListenersRef = useRef<Set<SignalAllCallback>>(new Set());
|
|
61
78
|
const reconnectTimeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(
|
|
62
79
|
undefined
|
|
63
80
|
);
|
|
@@ -115,6 +132,14 @@ export const SignalProvider: React.FC<SignalProviderProps> = ({
|
|
|
115
132
|
callback(message.payload);
|
|
116
133
|
}
|
|
117
134
|
}
|
|
135
|
+
// Notify wildcard listeners (auto-invalidator etc.)
|
|
136
|
+
for (const callback of allListenersRef.current) {
|
|
137
|
+
callback({
|
|
138
|
+
signalId: message.signalId,
|
|
139
|
+
pluginId: message.pluginId,
|
|
140
|
+
payload: message.payload,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
118
143
|
}
|
|
119
144
|
// Ignore "connected" and "pong" messages
|
|
120
145
|
} catch (error) {
|
|
@@ -154,9 +179,17 @@ export const SignalProvider: React.FC<SignalProviderProps> = ({
|
|
|
154
179
|
[]
|
|
155
180
|
);
|
|
156
181
|
|
|
182
|
+
const subscribeAll = useCallback((callback: SignalAllCallback) => {
|
|
183
|
+
allListenersRef.current.add(callback);
|
|
184
|
+
return () => {
|
|
185
|
+
allListenersRef.current.delete(callback);
|
|
186
|
+
};
|
|
187
|
+
}, []);
|
|
188
|
+
|
|
157
189
|
const value: SignalContextValue = {
|
|
158
190
|
isConnected,
|
|
159
191
|
subscribe,
|
|
192
|
+
subscribeAll,
|
|
160
193
|
};
|
|
161
194
|
|
|
162
195
|
return (
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
// Provider component
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
SignalProvider,
|
|
4
|
+
useSignalContext,
|
|
5
|
+
type SignalAllCallback,
|
|
6
|
+
} from "./SignalProvider";
|
|
3
7
|
|
|
4
8
|
// Hooks
|
|
5
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
useSignal,
|
|
11
|
+
useSignalConnection,
|
|
12
|
+
useSubscribeAllSignals,
|
|
13
|
+
} from "./useSignal";
|
package/src/useSignal.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef } from "react";
|
|
2
2
|
import type { Signal } from "@checkstack/signal-common";
|
|
3
|
-
import { useSignalContext } from "./SignalProvider";
|
|
3
|
+
import { useSignalContext, type SignalAllCallback } from "./SignalProvider";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Subscribe to a signal and receive typed payloads.
|
|
@@ -65,3 +65,27 @@ export function useSignalConnection(): { isConnected: boolean } {
|
|
|
65
65
|
const { isConnected } = useSignalContext();
|
|
66
66
|
return { isConnected };
|
|
67
67
|
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Subscribe to ALL incoming signals. Used by the auto-invalidation layer.
|
|
71
|
+
*
|
|
72
|
+
* The callback receives `signalId`, `pluginId`, and the raw payload for every
|
|
73
|
+
* signal message that arrives over the WebSocket. Subscriptions are automatically
|
|
74
|
+
* cleaned up on unmount; the latest callback is always used (no stale closures).
|
|
75
|
+
*
|
|
76
|
+
* Component code should prefer the typed `useSignal(signal, ...)` hook over this.
|
|
77
|
+
*/
|
|
78
|
+
export function useSubscribeAllSignals(callback: SignalAllCallback): void {
|
|
79
|
+
const { subscribeAll } = useSignalContext();
|
|
80
|
+
|
|
81
|
+
const callbackRef = useRef(callback);
|
|
82
|
+
callbackRef.current = callback;
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const stableCallback: SignalAllCallback = (props) => {
|
|
86
|
+
callbackRef.current(props);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return subscribeAll(stableCallback);
|
|
90
|
+
}, [subscribeAll]);
|
|
91
|
+
}
|