-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(frontend): make disconnect indicator clickable to reconnect #9410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bestvibes
wants to merge
6
commits into
marimo-team:main
Choose a base branch
from
bestvibes:fix/clickable-disconnect-indicator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3e35cd5
chore(frontend): bump partysocket 1.1.10 β 1.1.13
bestvibes 4e03e13
fix(frontend): make disconnect indicator clickable to reconnect
bestvibes f9b01a6
review: address comments on #9410
bestvibes c3552bf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9507678
review: address second round of comments on #9410
bestvibes 25b3133
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
frontend/src/components/editor/header/__tests__/status.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* Copyright 2026 Marimo. All rights reserved. */ | ||
| // @vitest-environment jsdom | ||
|
|
||
| import { fireEvent, render } from "@testing-library/react"; | ||
| import { createStore, Provider as JotaiProvider } from "jotai"; | ||
| import type React from "react"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { TooltipProvider } from "@/components/ui/tooltip"; | ||
| import { viewStateAtom } from "@/core/mode"; | ||
| import { | ||
| type ConnectionStatus, | ||
| WebSocketClosedReason, | ||
| WebSocketState, | ||
| } from "@/core/websocket/types"; | ||
| import { StatusOverlay } from "../status"; | ||
|
|
||
| function renderOverlay( | ||
| connection: ConnectionStatus, | ||
| onReconnect?: () => void, | ||
| ): ReturnType<typeof render> { | ||
| const store = createStore(); | ||
| store.set(viewStateAtom, { mode: "edit", cellAnchor: null }); | ||
| const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => ( | ||
| <JotaiProvider store={store}> | ||
| <TooltipProvider>{children}</TooltipProvider> | ||
| </JotaiProvider> | ||
| ); | ||
| return render( | ||
| <StatusOverlay | ||
| connection={connection} | ||
| isRunning={false} | ||
| onReconnect={onReconnect} | ||
| />, | ||
| { wrapper }, | ||
| ); | ||
| } | ||
|
|
||
| describe("StatusOverlay disconnect indicator", () => { | ||
| it("invokes onReconnect when the disconnect icon is clicked", () => { | ||
| const onReconnect = vi.fn(); | ||
| const { getByTestId } = renderOverlay( | ||
| { | ||
| state: WebSocketState.CLOSED, | ||
| code: WebSocketClosedReason.KERNEL_DISCONNECTED, | ||
| reason: "kernel not found", | ||
| }, | ||
| onReconnect, | ||
| ); | ||
|
|
||
| const icon = getByTestId("disconnected-indicator") as HTMLButtonElement; | ||
| expect(icon.tagName).toBe("BUTTON"); | ||
| expect(icon.disabled).toBe(false); | ||
| expect(icon.getAttribute("aria-label")).toBe("Reconnect to app"); | ||
| fireEvent.click(icon); | ||
| expect(onReconnect).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("renders a disabled button when no onReconnect is provided", () => { | ||
| const { getByTestId } = renderOverlay({ | ||
| state: WebSocketState.CLOSED, | ||
| code: WebSocketClosedReason.KERNEL_DISCONNECTED, | ||
| reason: "kernel not found", | ||
| }); | ||
|
|
||
| const button = getByTestId("disconnected-indicator"); | ||
| expect((button as HTMLButtonElement).disabled).toBe(true); | ||
| }); | ||
|
|
||
| it("does not render the disconnect icon when another tab has taken over", () => { | ||
| const onReconnect = vi.fn(); | ||
| const { queryByTestId } = renderOverlay( | ||
| { | ||
| state: WebSocketState.CLOSED, | ||
| code: WebSocketClosedReason.ALREADY_RUNNING, | ||
| reason: "another browser tab is already connected to the kernel", | ||
| canTakeover: true, | ||
| }, | ||
| onReconnect, | ||
| ); | ||
|
|
||
| expect(queryByTestId("disconnected-indicator")).toBeNull(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
frontend/src/core/websocket/__tests__/close-handler.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| /* Copyright 2026 Marimo. All rights reserved. */ | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
| import { classifyCloseEvent } from "../close-handler"; | ||
| import { WebSocketClosedReason, WebSocketState } from "../types"; | ||
|
|
||
| const MAX_RETRIES = 10; | ||
|
|
||
| function classify( | ||
| reason: string | undefined, | ||
| retryCount = 0, | ||
| maxRetries = MAX_RETRIES, | ||
| ) { | ||
| return classifyCloseEvent({ reason, code: 1006 }, { retryCount, maxRetries }); | ||
| } | ||
|
|
||
| describe("classifyCloseEvent", () => { | ||
| describe("transient closes (default branch)", () => { | ||
| it("retries when retryCount < maxRetries", () => { | ||
| const decision = classify(undefined, 0); | ||
| expect(decision.kind).toBe("retry"); | ||
| expect(decision.status).toEqual({ state: WebSocketState.CONNECTING }); | ||
| }); | ||
|
|
||
| it("retries on each intermediate close event during a retry storm", () => { | ||
| for (let n = 0; n < MAX_RETRIES; n++) { | ||
| const decision = classify(undefined, n); | ||
| expect(decision.kind).toBe("retry"); | ||
| expect(decision.status).toEqual({ state: WebSocketState.CONNECTING }); | ||
| } | ||
| }); | ||
|
|
||
| it("transitions to CLOSED when retryCount reaches maxRetries", () => { | ||
| const decision = classify(undefined, MAX_RETRIES); | ||
| expect(decision.kind).toBe("gave-up"); | ||
| expect(decision.status).toEqual({ | ||
| state: WebSocketState.CLOSED, | ||
| code: WebSocketClosedReason.KERNEL_DISCONNECTED, | ||
| reason: "kernel not found", | ||
| }); | ||
| }); | ||
|
|
||
| it("transitions to CLOSED when retryCount exceeds maxRetries", () => { | ||
| const decision = classify(undefined, MAX_RETRIES + 5); | ||
| expect(decision.kind).toBe("gave-up"); | ||
| }); | ||
|
|
||
| it("treats unknown reason strings as transient", () => { | ||
| const decision = classify("something-else", 3); | ||
| expect(decision.kind).toBe("retry"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("terminal closes (server-initiated)", () => { | ||
| it("MARIMO_ALREADY_CONNECTED β terminal + closeTransport, with takeover", () => { | ||
| const decision = classify("MARIMO_ALREADY_CONNECTED", 0); | ||
| expect(decision.kind).toBe("terminal"); | ||
| expect(decision.status).toMatchObject({ | ||
| state: WebSocketState.CLOSED, | ||
| code: WebSocketClosedReason.ALREADY_RUNNING, | ||
| canTakeover: true, | ||
| }); | ||
| if (decision.kind === "terminal") { | ||
| expect(decision.closeTransport).toBe(true); | ||
| } | ||
| }); | ||
|
|
||
| it.each([ | ||
| "MARIMO_WRONG_KERNEL_ID", | ||
| "MARIMO_NO_FILE_KEY", | ||
| "MARIMO_NO_SESSION_ID", | ||
| "MARIMO_NO_SESSION", | ||
| "MARIMO_SHUTDOWN", | ||
| ])("%s β terminal with KERNEL_DISCONNECTED, closes transport", (reason) => { | ||
| const decision = classify(reason, 0); | ||
| expect(decision.kind).toBe("terminal"); | ||
| expect(decision.status).toMatchObject({ | ||
| state: WebSocketState.CLOSED, | ||
| code: WebSocketClosedReason.KERNEL_DISCONNECTED, | ||
| }); | ||
| if (decision.kind === "terminal") { | ||
| expect(decision.closeTransport).toBe(true); | ||
| } | ||
| }); | ||
|
|
||
| it("MARIMO_MALFORMED_QUERY β terminal but does NOT close transport", () => { | ||
| const decision = classify("MARIMO_MALFORMED_QUERY", 0); | ||
| expect(decision.kind).toBe("terminal"); | ||
| expect(decision.status).toMatchObject({ | ||
| state: WebSocketState.CLOSED, | ||
| code: WebSocketClosedReason.MALFORMED_QUERY, | ||
| }); | ||
| if (decision.kind === "terminal") { | ||
| expect(decision.closeTransport).toBe(false); | ||
| } | ||
| }); | ||
|
|
||
| it("MARIMO_KERNEL_STARTUP_ERROR β terminal + closeTransport", () => { | ||
| const decision = classify("MARIMO_KERNEL_STARTUP_ERROR", 0); | ||
| expect(decision.kind).toBe("terminal"); | ||
| expect(decision.status).toMatchObject({ | ||
| state: WebSocketState.CLOSED, | ||
| code: WebSocketClosedReason.KERNEL_STARTUP_ERROR, | ||
| }); | ||
| if (decision.kind === "terminal") { | ||
| expect(decision.closeTransport).toBe(true); | ||
| } | ||
| }); | ||
|
|
||
| it("terminal closes ignore retryCount entirely", () => { | ||
| const decision = classify("MARIMO_SHUTDOWN", 99); | ||
| expect(decision.kind).toBe("terminal"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("retry budget exhaustion", () => { | ||
| it("yields retry on attempts 1..maxRetries-1 and gave-up on the final close", () => { | ||
| const states: string[] = []; | ||
| for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) { | ||
| states.push(classify(undefined, attempt - 1).kind); | ||
| } | ||
| states.push(classify(undefined, MAX_RETRIES).kind); | ||
|
|
||
| expect(states).toEqual([ | ||
| ...Array.from({ length: MAX_RETRIES }, () => "retry"), | ||
| "gave-up", | ||
| ]); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.