Skip to content

Commit 87630f2

Browse files
cliffhallclaude
andcommitted
refactor(web): address review — scope failure UX to connect attempts, dedupe timing (#1621)
Review feedback on #1622: - #1 (medium): `connectionStatus === "error"` also covers a mid-session crash of a previously-connected server, not just a failed connect attempt. Scope the auto-open + failure tab set to connect attempts only: the auto-open effect's error arm now requires the previous status to not be `connected` (connecting/disconnected → error), and `failed` (render) requires `erroredServerId`, which the parent sets only for connect- attempt failures. A mid-session crash now closes the column like any teardown instead of reopening a user-closed column / dropping the live Logs tab. This also aligns the column behavior with the red border. - #3 (minor): extract the column slide duration into a shared `monitorColumnAnimation.ts` (MONITOR_COLUMN_ANIM_MS + FAILED_CARD_SCROLL_DELAY_MS) so InspectorView's Transition and ServerCard's scroll delay can't drift. - #4 (nit): composite key for ConsoleScreen entry rows instead of the array index. Added a mid-session-crash test (connected → error with no erroredServerId closes the column). Verified live: a connect failure still opens the column to Console. Full `npm run ci` passes. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BrihGWcrM9JGRyu41nzZYw
1 parent 71d33d7 commit 87630f2

5 files changed

Lines changed: 87 additions & 26 deletions

File tree

‎clients/web/src/components/groups/ServerCard/ServerCard.tsx‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ServerStatusIndicator } from "../../elements/ServerStatusIndicator/Serv
99
import { TransportBadge } from "../../elements/TransportBadge/TransportBadge";
1010
import { ConnectionToggle } from "../../elements/ConnectionToggle/ConnectionToggle";
1111
import { ContentViewer } from "../../elements/ContentViewer/ContentViewer";
12+
import { FAILED_CARD_SCROLL_DELAY_MS } from "../../views/InspectorView/monitorColumnAnimation";
1213

1314
export interface ServerCardProps extends ServerEntry {
1415
activeServer?: string;
@@ -101,14 +102,6 @@ const RemoveButton = Button.withProps({
101102
color: "red.6",
102103
});
103104

104-
// Delay before scrolling a newly-failed card into view (#1621). A connection
105-
// failure both flags the card and opens the monitoring column, which reflows
106-
// the server grid (fewer, narrower columns) and can push the failed card below
107-
// the fold. Deferring past the column's open lets that reflow settle so
108-
// `scrollIntoView` targets the card's final position rather than its pre-reflow
109-
// one. Kept just above the column's slide duration.
110-
const ERROR_SCROLL_DELAY_MS = 320;
111-
112105
function getTransport(config: MCPServerConfig): ServerType {
113106
return config.type ?? "stdio";
114107
}
@@ -165,17 +158,19 @@ export function ServerCard({
165158
}, [highlighted, scrollOnHighlight]);
166159

167160
// Scroll the failed card into view on the disconnected→errored transition
168-
// (#1621), deferred so the monitoring column's open + grid reflow settle
169-
// first. Guarded by a ref so a re-render while still errored doesn't re-scroll
170-
// and fight the user if they've scrolled away.
161+
// (#1621), deferred past the monitoring column's open (`FAILED_CARD_SCROLL_
162+
// DELAY_MS`, derived from the column's slide duration) so the grid reflow
163+
// settles before `scrollIntoView` measures the card. Guarded by a ref so a
164+
// re-render while still errored doesn't re-scroll and fight the user if they've
165+
// scrolled away.
171166
const wasErroredRef = useRef(errored);
172167
useEffect(() => {
173168
const justErrored = errored && !wasErroredRef.current;
174169
wasErroredRef.current = errored;
175170
if (!justErrored) return;
176171
const timer = setTimeout(() => {
177172
rootRef.current?.scrollIntoView({ behavior: "smooth", block: "center" });
178-
}, ERROR_SCROLL_DELAY_MS);
173+
}, FAILED_CARD_SCROLL_DELAY_MS);
179174
return () => clearTimeout(timer);
180175
}, [errored]);
181176
const transport = getTransport(config);

‎clients/web/src/components/screens/ConsoleScreen/ConsoleScreen.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export function ConsoleScreen({
183183
<EmbeddableScrollArea embedded={embedded} viewportRef={viewportRef}>
184184
<Stack gap="xs">
185185
{filteredEntries.map((entry, index) => (
186-
<EntryRow key={index}>
186+
<EntryRow key={`${entry.timestamp.getTime()}-${index}`}>
187187
<TimestampText>
188188
{formatTimestamp(entry.timestamp)}
189189
</TimestampText>

‎clients/web/src/components/views/InspectorView/InspectorView.test.tsx‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,11 +1383,14 @@ describe("InspectorView", () => {
13831383
});
13841384

13851385
// A failed connect leaves the errored server's id set but no
1386-
// initializeResult (capabilities were never negotiated).
1386+
// initializeResult (capabilities were never negotiated). `erroredServerId`
1387+
// is the parent's connect-attempt-failure signal (it survives the failure's
1388+
// `disconnect` clearing `activeServer`), which gates the failure column.
13871389
function failedHttp(overrides: Partial<InspectorViewProps> = {}) {
13881390
return makeProps({
13891391
servers: [httpServer],
13901392
activeServer: "beta",
1393+
erroredServerId: "beta",
13911394
connectionStatus: "error",
13921395
initializeResult: undefined,
13931396
...overrides,
@@ -1498,6 +1501,41 @@ describe("InspectorView", () => {
14981501
).toBeNull();
14991502
});
15001503

1504+
it("does not treat a mid-session crash as a connect-attempt failure (#1621)", async () => {
1505+
// A previously-connected server that crashes settles to `error` too, but
1506+
// with no `erroredServerId` (the parent sets that only for connect
1507+
// attempts). That must NOT reorganize the column into the failure tab set
1508+
// — it closes like any session teardown, so a user who closed the column
1509+
// mid-session isn't reopened onto diagnostics.
1510+
monitorWide.value = true;
1511+
window.localStorage.setItem("inspector.monitor.pinned", "true");
1512+
const { rerender } = renderWithMantine(
1513+
<StatefulInspectorViewHost {...connectedHttp()} />,
1514+
);
1515+
// Connected + pinned: the column is open with the live monitor tabs.
1516+
expect(
1517+
await screen.findByRole("button", { name: "Close monitoring column" }),
1518+
).toBeInTheDocument();
1519+
1520+
// Crash: connected → error, activeServer cleared, NO erroredServerId.
1521+
rerender(
1522+
<StatefulInspectorViewHost
1523+
{...makeProps({
1524+
servers: [httpServer],
1525+
activeServer: undefined,
1526+
connectionStatus: "error",
1527+
})}
1528+
/>,
1529+
);
1530+
// The column closes (after its slide-out) rather than switching to the
1531+
// failure tabs.
1532+
await waitFor(() =>
1533+
expect(
1534+
screen.queryByRole("button", { name: "Close monitoring column" }),
1535+
).toBeNull(),
1536+
);
1537+
});
1538+
15011539
const stdioServer: ServerEntry = {
15021540
id: "gamma",
15031541
name: "Gamma",

‎clients/web/src/components/views/InspectorView/InspectorView.tsx‎

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import { MonitoringScreen } from "../../groups/MonitoringScreen/MonitoringScreen
8888
import { ResizeHandle } from "../../elements/ResizeHandle/ResizeHandle";
8989
import { getServerType } from "@inspector/core/mcp/config.js";
9090
import { INSPECTOR_SERVERS_TAB } from "../../../utils/inspectorTabs";
91+
import { MONITOR_COLUMN_ANIM_MS } from "./monitorColumnAnimation";
9192

9293
const SORT_DEFAULT: SortDirection = "newest-first";
9394

@@ -283,8 +284,9 @@ const MonitoringColumn = Stack.withProps({
283284
// side column sliding open rather than snapping in. The primary screen keeps its
284285
// standard `ScreenStage` transition. Mantine plays `out → in` on enter and
285286
// `in → out` on exit. `AppShell.Main`'s `overflow: hidden` clips the off-screen
286-
// portion during the slide.
287-
const COLUMN_ANIM_MS = 300;
287+
// portion during the slide. The duration is shared (`ServerCard` waits on it
288+
// before scrolling a failed card into view) so the two can't drift.
289+
const COLUMN_ANIM_MS = MONITOR_COLUMN_ANIM_MS;
288290
const columnSlide: MantineTransition = {
289291
in: { opacity: 1, transform: "translateX(0)" },
290292
out: { opacity: 0, transform: "translateX(100%)" },
@@ -695,22 +697,30 @@ export function InspectorView({
695697
});
696698

697699
// Open the monitoring column when a connection is established (#1616) OR when a
698-
// connection attempt fails (#1621). Gated on the *transition into* the target
700+
// connect *attempt* fails (#1621). Gated on the *transition into* the target
699701
// status (via the ref) rather than the status itself, so it fires once on an
700702
// actual connect/failure — not on every render, and not on a mount that starts
701703
// already in that status (which would fight a user who closed it). On success
702-
// the column surfaces the live stream; on failure it surfaces the History /
703-
// Network entries that explain what went wrong. The column still only *appears*
704-
// when wide + a monitor tab is available (`effectivePinned`); this just sets the
705-
// preference. Closing it stays closed until the next connect/failure, since this
706-
// effect only re-runs when `connectionStatus` changes.
704+
// the column surfaces the live stream; on failure it surfaces the diagnostics
705+
// that explain what went wrong. The column still only *appears* when wide + a
706+
// monitor tab is available (`effectivePinned`); this just sets the preference.
707+
//
708+
// `"error"` is also the resting status of a *mid-session crash* of a
709+
// previously-connected server (per isTerminalStatus/#1490), but that is NOT a
710+
// connect attempt: reopening a column the user closed mid-session (and swapping
711+
// their live tab set for the failure set) would be surprising. So the error
712+
// arm requires the previous status to NOT be `connected` — i.e. we went
713+
// connecting/disconnected → error, never connected → error. This keeps the
714+
// auto-open aligned with the red-border (`erroredServerId`), which the parent
715+
// also sets only for connect-attempt failures.
707716
const prevStatusRef = useRef(connectionStatus);
708717
useEffect(() => {
709718
const prev = prevStatusRef.current;
710719
prevStatusRef.current = connectionStatus;
711720
const becameConnected =
712721
connectionStatus === "connected" && prev !== "connected";
713-
const becameError = connectionStatus === "error" && prev !== "error";
722+
const becameError =
723+
connectionStatus === "error" && prev !== "error" && prev !== "connected";
714724
if (becameConnected || becameError) {
715725
setMonitorPinned(true);
716726
}
@@ -797,9 +807,12 @@ export function InspectorView({
797807
// `monitorPinned`, so it re-opens when the condition returns. Only the column's
798808
// close button writes `monitorPinned = false`.
799809
const connected = connectionStatus === "connected";
800-
// A failed connection attempt (#1621) keeps the column available so the user
801-
// can see why, even though no live session exists.
802-
const failed = connectionStatus === "error";
810+
// A failed connection *attempt* (#1621) keeps the column available so the user
811+
// can see why, even though no live session exists. Gated on `erroredServerId`
812+
// (set by the parent only for connect-attempt failures, not mid-session
813+
// crashes) so a crash of a previously-connected server doesn't reorganize the
814+
// column into the failure tab set — matching the auto-open effect above.
815+
const failed = connectionStatus === "error" && erroredServerId !== undefined;
803816
const monitorAvailable = useMemo<string[]>(() => {
804817
if (connected) return availableTabs.filter((t) => MONITOR_TABS.includes(t));
805818
if (failed) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Duration (ms) of the monitoring column's open/close slide (#1616). Shared so
3+
* dependent timings can't silently drift from the animation:
4+
* - `InspectorView` drives the column's Mantine `Transition` with it.
5+
* - `ServerCard` waits just past it before scrolling a newly-failed card into
6+
* view (#1621), so the column's open + the resulting grid reflow settle
7+
* before `scrollIntoView` measures the card's position.
8+
*/
9+
export const MONITOR_COLUMN_ANIM_MS = 300;
10+
11+
/**
12+
* Delay (ms) before scrolling a newly-failed server card into view — the column
13+
* animation plus a small buffer for the reflow to commit.
14+
*/
15+
export const FAILED_CARD_SCROLL_DELAY_MS = MONITOR_COLUMN_ANIM_MS + 20;

0 commit comments

Comments
 (0)