Pull the four session-scoped UI resets (toolCallState / getPromptState / readResourceState panels + optimistic currentLogLevel) out of the disconnect listener into a colocated `resetSessionScopedUiState` useCallback, so there's a single named place to extend as App.tsx accrues more per-session state. The disconnect listener keeps its activeServerId + modal-flag bookkeeping inline and calls the helper. Pure refactor — no behavior change; the existing App.test.tsx disconnect test (asserts all four pieces reset) is unchanged and still passes. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
9e494544e7
commit
8b4375584a
1 changed files with 22 additions and 17 deletions
|
|
@ -342,6 +342,23 @@ function App() {
|
||||||
};
|
};
|
||||||
}, [inspectorClient]);
|
}, [inspectorClient]);
|
||||||
|
|
||||||
|
// Reset the session-scoped UI state that lives in App.tsx (rather than
|
||||||
|
// inside the per-server state managers), so the next server's screens don't
|
||||||
|
// show server A's last result. The per-call panels (`toolCallState` /
|
||||||
|
// `getPromptState` / `readResourceState`) and the optimistic
|
||||||
|
// `currentLogLevel` all survive a disconnect/reconnect cycle otherwise —
|
||||||
|
// see #1368. `latencyMs` is intentionally excluded: it resets via the
|
||||||
|
// `connectionStatus` effect above, which has its own connecting-edge ref to
|
||||||
|
// coordinate with. Colocated with the setters it touches so this is the
|
||||||
|
// single place to extend as App.tsx accrues more per-session state (#1394).
|
||||||
|
// Setters are stable, so the callback identity never changes.
|
||||||
|
const resetSessionScopedUiState = useCallback(() => {
|
||||||
|
setToolCallState(undefined);
|
||||||
|
setGetPromptState(undefined);
|
||||||
|
setReadResourceState(undefined);
|
||||||
|
setCurrentLogLevel("info");
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Reset activeServerId whenever the live session ends. Without this the
|
// Reset activeServerId whenever the live session ends. Without this the
|
||||||
// other ServerCards stay `inert` after disconnect — ServerCard dims any
|
// other ServerCards stay `inert` after disconnect — ServerCard dims any
|
||||||
// card whose id differs from `activeServer`. Subscribing to
|
// card whose id differs from `activeServer`. Subscribing to
|
||||||
|
|
@ -349,16 +366,9 @@ function App() {
|
||||||
// (explicit toggle, header Disconnect button, mid-session transport
|
// (explicit toggle, header Disconnect button, mid-session transport
|
||||||
// failure / process exit) and avoids the first-render-clobbers-new-id
|
// failure / process exit) and avoids the first-render-clobbers-new-id
|
||||||
// trap that watching connectionStatus has (status starts as
|
// trap that watching connectionStatus has (status starts as
|
||||||
// "disconnected" for the new client before connect() runs).
|
// "disconnected" for the new client before connect() runs). The
|
||||||
//
|
// session-scoped panel/level reset rides along here too via
|
||||||
// This is also where session-scoped UI state that lives in App.tsx
|
// `resetSessionScopedUiState`.
|
||||||
// (rather than inside the per-server state managers) gets reset, so the
|
|
||||||
// next server's screens don't show server A's last result. The per-call
|
|
||||||
// panels (`toolCallState` / `getPromptState` / `readResourceState`) and
|
|
||||||
// the optimistic `currentLogLevel` all survive a disconnect/reconnect
|
|
||||||
// cycle otherwise — see #1368. `latencyMs` resets via the
|
|
||||||
// `connectionStatus` effect above instead because it has its own
|
|
||||||
// connecting-edge ref to coordinate with.
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!inspectorClient) return;
|
if (!inspectorClient) return;
|
||||||
const onDisconnect = () => {
|
const onDisconnect = () => {
|
||||||
|
|
@ -366,18 +376,13 @@ function App() {
|
||||||
// Drop the open flag too — without this the modal would pop back the
|
// Drop the open flag too — without this the modal would pop back the
|
||||||
// next time `initializeResult` re-becomes truthy (e.g. reconnect).
|
// next time `initializeResult` re-becomes truthy (e.g. reconnect).
|
||||||
setConnectionInfoModalOpen(false);
|
setConnectionInfoModalOpen(false);
|
||||||
// Clear the per-call result panels so the next session starts empty.
|
resetSessionScopedUiState();
|
||||||
setToolCallState(undefined);
|
|
||||||
setGetPromptState(undefined);
|
|
||||||
setReadResourceState(undefined);
|
|
||||||
// Back to the default level the next session begins at.
|
|
||||||
setCurrentLogLevel("info");
|
|
||||||
};
|
};
|
||||||
inspectorClient.addEventListener("disconnect", onDisconnect);
|
inspectorClient.addEventListener("disconnect", onDisconnect);
|
||||||
return () => {
|
return () => {
|
||||||
inspectorClient.removeEventListener("disconnect", onDisconnect);
|
inspectorClient.removeEventListener("disconnect", onDisconnect);
|
||||||
};
|
};
|
||||||
}, [inspectorClient]);
|
}, [inspectorClient, resetSessionScopedUiState]);
|
||||||
|
|
||||||
// Build the InitializeResult the connected ViewHeader expects from the
|
// Build the InitializeResult the connected ViewHeader expects from the
|
||||||
// hook's split fields. `protocolVersion` is hard-coded for now — the
|
// hook's split fields. `protocolVersion` is hard-coded for now — the
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue