A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
improvement: connecting indicator and readonly tooltip (#5284)
Myles Scolnicka22cfbb9c1cb
diff --git a/frontend/src/components/editor/alerts/connecting-alert.tsx b/frontend/src/components/editor/alerts/connecting-alert.tsxnew file mode 100644index 0000000000..7e8a8f763d--- /dev/null+++ b/frontend/src/components/editor/alerts/connecting-alert.tsx@@ -0,0 +1,21 @@+/* Copyright 2024 Marimo. All rights reserved. */++import { useAtomValue } from "jotai";+import { FloatingAlert } from "./floating-alert";+import { isConnectingAtom } from "@/core/network/connection";+import { Spinner } from "@/components/icons/spinner";++const DELAY_MS = 1000; // 1 second++export const ConnectingAlert: React.FC = () => {+ const isConnecting = useAtomValue(isConnectingAtom);++ return (+ <FloatingAlert title="Connecting" show={isConnecting} delayMs={DELAY_MS}>+ <div className="flex items-center gap-2">+ <Spinner className="h-4 w-4" />+ <p>Establishing a connection to a marimo runtime...</p>+ </div>+ </FloatingAlert>+ );+};diff --git a/frontend/src/components/editor/alerts/floating-alert.tsx b/frontend/src/components/editor/alerts/floating-alert.tsxnew file mode 100644index 0000000000..e6599dc45b--- /dev/null+++ b/frontend/src/components/editor/alerts/floating-alert.tsx@@ -0,0 +1,45 @@+/* Copyright 2024 Marimo. All rights reserved. */++import { Banner } from "@/plugins/impl/common/error-banner";+import { DelayMount } from "../../utils/delay-mount";+import type { ReactNode } from "react";++interface FloatingAlertProps {+ title: string;+ children: ReactNode;+ show: boolean;+ delayMs?: number;+ kind?: "info" | "warn" | "danger";+}++export const FloatingAlert: React.FC<FloatingAlertProps> = ({+ title,+ children,+ show,+ delayMs = 2000,+ kind = "info",+}) => {+ if (!show) {+ return null;+ }++ const body = (+ <div className="flex flex-col gap-4 mb-5 fixed top-5 left-1/2 transform -translate-x-1/2 z-[200] opacity-95">+ <Banner+ kind={kind}+ className="flex flex-col rounded py-2 px-4 animate-in slide-in-from-top w-fit"+ >+ <div className="flex justify-between">+ <span className="font-bold text-lg flex items-center mb-1">+ {title}+ </span>+ </div>+ <div className="flex flex-col gap-4 justify-between items-start text-muted-foreground text-base">+ <div>{children}</div>+ </div>+ </Banner>+ </div>+ );++ return <DelayMount milliseconds={delayMs}>{body}</DelayMount>;+};diff --git a/frontend/src/components/editor/alerts/stdin-blocking-alert.tsx b/frontend/src/components/editor/alerts/stdin-blocking-alert.tsxnew file mode 100644index 0000000000..1279118507--- /dev/null+++ b/frontend/src/components/editor/alerts/stdin-blocking-alert.tsx@@ -0,0 +1,61 @@+/* Copyright 2024 Marimo. All rights reserved. */++import { Button } from "../../ui/button";+import { notebookAtom } from "@/core/cells/cells";+import { atom, useAtomValue } from "jotai";+import { Logger } from "@/utils/Logger";+import { Kbd } from "../../ui/kbd";+import { FloatingAlert } from "./floating-alert";++// Atom to check if there is a cell with unresolved stdin+const hasBlockingStdinAtom = atom((get) => {+ const notebook = get(notebookAtom);++ // Check each cell in order+ for (const cellId of notebook.cellIds.inOrderIds) {+ // Check if the cell is idle and has unresolved stdin+ const runtime = notebook.cellRuntime[cellId];+ if (runtime.status === "idle") {+ const hasUnresolvedStdin = runtime.consoleOutputs.some(+ (output) => output.channel === "stdin" && output.response === undefined,+ );+ if (hasUnresolvedStdin) {+ return true;+ }+ }+ }++ return false;+});++export const StdinBlockingAlert: React.FC = () => {+ const hasBlockingStdin = useAtomValue(hasBlockingStdinAtom);++ const handleJumpToStdin = () => {+ const el = document.querySelector<HTMLElement>("[data-stdin-blocking]");+ if (el) {+ el.scrollIntoView({ behavior: "smooth", block: "center" });+ requestAnimationFrame(() => {+ el.focus();+ });+ } else {+ Logger.error("No element with data-stdin-blocking found");+ }+ };++ return (+ <FloatingAlert title="Program waiting for input" show={hasBlockingStdin}>+ <p>+ The program is still running, but blocked on{" "}+ <Kbd className="inline">stdin</Kbd>.+ <Button+ variant="link"+ className="h-auto font-normal"+ onClick={handleJumpToStdin}+ >+ Jump to the cell+ </Button>+ </p>+ </FloatingAlert>+ );+};diff --git a/frontend/src/components/editor/chrome/wrapper/footer-items/ai-status.tsx b/frontend/src/components/editor/chrome/wrapper/footer-items/ai-status.tsxindex cabee41fb2..d4fb37e285 100644--- a/frontend/src/components/editor/chrome/wrapper/footer-items/ai-status.tsx+++ b/frontend/src/components/editor/chrome/wrapper/footer-items/ai-status.tsx@@ -18,6 +18,7 @@ export const AIStatusIcon: React.FC = () => {tooltip="Assist is disabled"selected={false}onClick={() => handleClick("ai")}+ data-testid="footer-ai-disabled"><SparklesIcon className="h-4 w-4 opacity-60" /></FooterItem>@@ -33,6 +34,7 @@ export const AIStatusIcon: React.FC = () => {}onClick={() => handleClick("ai")}selected={false}+ data-testid="footer-ai-enabled"><SparklesIcon className="h-4 w-4" /></FooterItem>diff --git a/frontend/src/components/editor/chrome/wrapper/footer-items/backend-status.tsx b/frontend/src/components/editor/chrome/wrapper/footer-items/backend-status.tsxindex f21cc67b9b..99066a03a6 100644--- a/frontend/src/components/editor/chrome/wrapper/footer-items/backend-status.tsx+++ b/frontend/src/components/editor/chrome/wrapper/footer-items/backend-status.tsx@@ -93,6 +93,7 @@ export const BackendConnection: React.FC = () => {}selected={false}onClick={refetch}+ data-testid="footer-backend-status">{getStatusIcon()}</FooterItem>diff --git a/frontend/src/components/editor/chrome/wrapper/footer-items/copilot-status.tsx b/frontend/src/components/editor/chrome/wrapper/footer-items/copilot-status.tsxindex 1f244a7eca..8196eb0fa0 100644--- a/frontend/src/components/editor/chrome/wrapper/footer-items/copilot-status.tsx+++ b/frontend/src/components/editor/chrome/wrapper/footer-items/copilot-status.tsx@@ -108,6 +108,7 @@ const GitHubCopilotStatus: React.FC = () => {}selected={false}onClick={openSettings}+ data-testid="footer-copilot-status"><span>{isLoading ? (diff --git a/frontend/src/components/editor/chrome/wrapper/footer-items/rtc-status.tsx b/frontend/src/components/editor/chrome/wrapper/footer-items/rtc-status.tsxindex 7cfc57c970..ee89a39be2 100644--- a/frontend/src/components/editor/chrome/wrapper/footer-items/rtc-status.tsx+++ b/frontend/src/components/editor/chrome/wrapper/footer-items/rtc-status.tsx@@ -34,7 +34,11 @@ export const RTCStatus: React.FC = () => {return (<Popover open={open} onOpenChange={setOpen}><PopoverTrigger asChild={true}>- <FooterItem tooltip={tooltip} selected={false}>+ <FooterItem+ tooltip={tooltip}+ selected={false}+ data-testid="footer-rtc-status"+ ><UsersIcon className="w-4 h-4" /></FooterItem></PopoverTrigger>diff --git a/frontend/src/components/editor/chrome/wrapper/footer.tsx b/frontend/src/components/editor/chrome/wrapper/footer.tsxindex ab9f35ceec..c44752ac50 100644--- a/frontend/src/components/editor/chrome/wrapper/footer.tsx+++ b/frontend/src/components/editor/chrome/wrapper/footer.tsx@@ -57,6 +57,7 @@ export const Footer: React.FC = () => {tooltip={errorPanel.tooltip}selected={selectedPanel === errorPanel.type}onClick={() => toggleApplication(errorPanel.type)}+ data-testid="footer-errors">{renderIcon(errorPanel, errorCount > 0 ? "text-destructive" : "")}<span className="ml-1 font-mono mt-[0.125rem]">{errorCount}</span>@@ -67,6 +68,7 @@ export const Footer: React.FC = () => {tooltip="Open terminal"selected={isTerminalOpen}onClick={() => toggleTerminal()}+ data-testid="footer-terminal"><TerminalSquareIcon className="h-5 w-5" /></FooterItem>@@ -91,6 +93,7 @@ export const Footer: React.FC = () => {setConfig(newConfig),);}}+ data-testid="footer-autorun-startup"><div className="font-prose text-sm flex items-center gap-1"><span>on startup: </span>@@ -127,6 +130,7 @@ export const Footer: React.FC = () => {setConfig(newConfig),);}}+ data-testid="footer-autorun-cell-change"><div className="font-prose text-sm flex items-center gap-1"><span>on cell change: </span>@@ -142,7 +146,11 @@ export const Footer: React.FC = () => {<div className="border-r border-border h-6 mx-1" />{!isWasm() && (- <FooterItem tooltip={null} selected={false}>+ <FooterItem+ tooltip={null}+ selected={false}+ data-testid="footer-module-reload"+ ><DropdownMenu><DropdownMenuTrigger className="font-prose text-sm flex items-center gap-1"><span>on module change: </span>diff --git a/frontend/src/components/editor/renderers/CellArray.tsx b/frontend/src/components/editor/renderers/CellArray.tsxindex 71236b79b1..4c4587e411 100644--- a/frontend/src/components/editor/renderers/CellArray.tsx+++ b/frontend/src/components/editor/renderers/CellArray.tsx@@ -49,7 +49,8 @@ import { SortableCellsProvider } from "@/components/sort/SortableCellsProvider";import { Column } from "../columns/cell-column";import type { CellColumnId, CollapsibleTree } from "@/utils/id-tree";import type { CellId } from "@/core/cells/ids";-import { StdinBlockingAlert } from "../stdin-blocking-alert";+import { StdinBlockingAlert } from "../alerts/stdin-blocking-alert";+import { ConnectingAlert } from "../alerts/connecting-alert";interface CellArrayProps {mode: AppMode;@@ -125,6 +126,7 @@ const CellArrayInternal: React.FC<CellArrayProps> = ({><PackageAlert /><StdinBlockingAlert />+ <ConnectingAlert /><NotebookBanner width={appConfig.width} /><divclassName={cn(diff --git a/frontend/src/components/editor/stdin-blocking-alert.tsx b/frontend/src/components/editor/stdin-blocking-alert.tsxdeleted file mode 100644index f1068576e4..0000000000--- a/frontend/src/components/editor/stdin-blocking-alert.tsx+++ /dev/null@@ -1,83 +0,0 @@-/* Copyright 2024 Marimo. All rights reserved. */--import { Banner } from "@/plugins/impl/common/error-banner";-import { Button } from "../ui/button";-import { notebookAtom } from "@/core/cells/cells";-import { atom, useAtomValue } from "jotai";-import { Logger } from "@/utils/Logger";-import { Kbd } from "../ui/kbd";-import { DelayMount } from "../utils/delay-mount";--// Atom to check if there is a cell with unresolved stdin-const hasBlockingStdinAtom = atom((get) => {- const notebook = get(notebookAtom);-- // Check each cell in order- for (const cellId of notebook.cellIds.inOrderIds) {- // Check if the cell is idle and has unresolved stdin- const runtime = notebook.cellRuntime[cellId];- if (runtime.status === "idle") {- const hasUnresolvedStdin = runtime.consoleOutputs.some(- (output) => output.channel === "stdin" && output.response === undefined,- );- if (hasUnresolvedStdin) {- return true;- }- }- }-- return false;-});--export const StdinBlockingAlert: React.FC = () => {- const hasBlockingStdin = useAtomValue(hasBlockingStdinAtom);-- const handleJumpToStdin = () => {- const el = document.querySelector<HTMLElement>("[data-stdin-blocking]");- if (el) {- el.scrollIntoView({ behavior: "smooth", block: "center" });- requestAnimationFrame(() => {- el.focus();- });- } else {- Logger.error("No element with data-stdin-blocking found");- }- };-- if (!hasBlockingStdin) {- return null;- }-- const body = (- <div className="flex flex-col gap-4 mb-5 fixed top-5 left-1/2 transform -translate-x-1/2 z-[200] opacity-95">- <Banner- kind="info"- className="flex flex-col rounded py-2 px-4 animate-in slide-in-from-top w-fit"- >- <div className="flex justify-between">- <span className="font-bold text-lg flex items-center mb-1">- Program waiting for input- </span>- </div>- <div className="flex flex-col gap-4 justify-between items-start text-muted-foreground text-base">- <div>- <p>- The program is still running, but blocked on{" "}- <Kbd className="inline">stdin</Kbd>.- <Button- variant="link"- className="h-auto font-normal"- onClick={handleJumpToStdin}- >- Jump to the cell- </Button>- </p>- </div>- </div>- </Banner>- </div>- );-- // Delay the mount to avoid flickering- return <DelayMount milliseconds={2000}>{body}</DelayMount>;-};diff --git a/frontend/src/core/codemirror/cm.ts b/frontend/src/core/codemirror/cm.tsindex 46a0d8fe76..c40e211a03 100644--- a/frontend/src/core/codemirror/cm.ts+++ b/frontend/src/core/codemirror/cm.ts@@ -69,6 +69,8 @@ import { getFeatureFlag } from "../config/feature-flag";import type { CodemirrorCellActions } from "./cells/state";import { cellConfigExtension } from "./config/extension";import { completionKeymap } from "./completion/keymap";+import { dynamicReadonly } from "./readonly/extension";+import { store } from "../state/jotai";export interface CodeMirrorSetupOpts {cellId: CellId;@@ -138,6 +140,8 @@ export const setupCodeMirror = (opts: CodeMirrorSetupOpts): Extension[] => {},}): [],+ // Readonly extension+ dynamicReadonly(store),];};diff --git a/frontend/src/core/codemirror/readonly/extension.test.ts b/frontend/src/core/codemirror/readonly/extension.test.tsnew file mode 100644index 0000000000..3eb9154bba--- /dev/null+++ b/frontend/src/core/codemirror/readonly/extension.test.ts@@ -0,0 +1,54 @@+/* Copyright 2024 Marimo. All rights reserved. */+import { describe, it, expect } from "vitest";+import { EditorView } from "@codemirror/view";+import { EditorState } from "@codemirror/state";+import { dynamicReadonly, isEditorReadonly } from "./extension";+import { connectionAtom } from "../../network/connection";+import { createStore } from "jotai";+import { WebSocketState } from "@/core/websocket/types";++function makeStoreWithConnection(+ state: WebSocketState.CONNECTING | WebSocketState.OPEN,+) {+ const store = createStore();+ store.set(connectionAtom, { state });+ return store;+}++describe("dynamicReadonly", () => {+ it("should be readonly when connection is not OPEN", () => {+ const store = makeStoreWithConnection(WebSocketState.CONNECTING);+ const state = EditorState.create({+ doc: "test",+ extensions: [dynamicReadonly(store)],+ });+ expect(isEditorReadonly(state)).toBe(true);+ });++ it("should be editable when connection is OPEN", async () => {+ const store = makeStoreWithConnection(WebSocketState.OPEN);+ const state = EditorState.create({+ doc: "test",+ extensions: [dynamicReadonly(store)],+ });+ await new Promise((resolve) => setTimeout(resolve, 2));+ expect(isEditorReadonly(state)).toBe(false);+ });++ it("should toggle readonly when connection state changes", () => {+ const store = makeStoreWithConnection(WebSocketState.CONNECTING);+ const state = EditorState.create({+ doc: "test",+ extensions: [dynamicReadonly(store)],+ });+ const view = new EditorView({ state });+ expect(isEditorReadonly(state)).toBe(true);+ // Simulate connection opening+ store.set(connectionAtom, { state: WebSocketState.OPEN });+ // The extension uses a plugin to update the state, so we need to create a view to trigger it+ view.requestMeasure();+ // The state should now be editable+ expect(isEditorReadonly(view.state)).toBe(false);+ view.destroy();+ });+});diff --git a/frontend/src/core/codemirror/readonly/extension.ts b/frontend/src/core/codemirror/readonly/extension.tsnew file mode 100644index 0000000000..abc28869a8--- /dev/null+++ b/frontend/src/core/codemirror/readonly/extension.ts@@ -0,0 +1,187 @@+/* Copyright 2024 Marimo. All rights reserved. */+import { Compartment, EditorState, StateEffect } from "@codemirror/state";+import { ViewPlugin } from "@codemirror/view";+import { WebSocketState } from "../../websocket/types";+import { connectionAtom } from "../../network/connection";+import type { createStore } from "jotai";+import {+ isAppConnected,+ isAppConnecting,+} from "@/core/websocket/connection-utils";++/**+ * State effect for updating readonly status based on connection+ */+const updateReadonlyEffect = StateEffect.define<boolean>();++/**+ * Compartment for managing readonly configuration+ */+const readonlyCompartment = new Compartment();++// Floating indicator plugin+const INDICATOR_ID = "marimo-connecting-indicator";+function getOrCreateIndicator(): HTMLDivElement {+ let indicator = document.getElementById(+ INDICATOR_ID,+ ) as HTMLDivElement | null;+ if (!indicator) {+ indicator = document.createElement("div");+ indicator.id = INDICATOR_ID;+ indicator.textContent = "Connecting…";+ indicator.style.position = "fixed";+ indicator.style.zIndex = "9999";+ indicator.style.background = "#222";+ indicator.style.color = "#fff";+ indicator.style.padding = "2px 8px";+ indicator.style.borderRadius = "6px";+ indicator.style.fontSize = "0.9em";+ indicator.style.boxShadow = "0 2px 8px rgba(0,0,0,0.15)";+ indicator.style.pointerEvents = "none";+ indicator.style.display = "none";+ document.body.append(indicator);+ }+ return indicator;+}++function showIndicatorAt(left: number, top: number) {+ const indicator = getOrCreateIndicator();+ indicator.style.left = `${left}px`;+ indicator.style.top = `${top}px`;+ indicator.style.display = "block";+ indicator.textContent = "Connecting…";+}+function hideIndicator() {+ const indicator = document.getElementById(INDICATOR_ID);+ if (indicator) {+ indicator.style.display = "none";+ }+}++let hideIndicatorTimeout: number | null = null;++/**+ * Creates a dynamic readonly extension that toggles based on WebSocket connection status.+ * When disconnected or connecting, the editor becomes readonly.+ * When connected, the editor becomes editable.+ */+export function dynamicReadonly(store: ReturnType<typeof createStore>) {+ const getConnectionState = () => store.get(connectionAtom).state;++ // Initial readonly state - start as readonly until connected+ let isReadonly = !isAppConnected(getConnectionState());++ const connectingIndicatorPlugin = ViewPlugin.define((view) => {+ let listenersAttached = false;+ const dom = view.dom;++ function showNearCaret() {+ const sel = view.state.selection.main;+ const coords = view.coordsAtPos(sel.head);+ if (coords) {+ showIndicatorAt(coords.left + 2, coords.bottom + 2);+ } else {+ showIndicatorAt(window.innerWidth / 2, window.innerHeight * 0.1);+ }+ if (hideIndicatorTimeout) {+ window.clearTimeout(hideIndicatorTimeout);+ }+ hideIndicatorTimeout = window.setTimeout(hideIndicator, 1500);+ }++ function onUserInput() {+ showNearCaret();+ }++ function attachListeners() {+ if (!listenersAttached) {+ dom.addEventListener("keydown", onUserInput, true);+ dom.addEventListener("paste", onUserInput, true);+ listenersAttached = true;+ }+ }+ function detachListeners() {+ if (listenersAttached) {+ dom.removeEventListener("keydown", onUserInput, true);+ dom.removeEventListener("paste", onUserInput, true);+ listenersAttached = false;+ }+ }++ // Subscribe to connectionAtom and manage listeners+ const unsubscribe = store.sub(connectionAtom, () => {+ const connection = store.get(connectionAtom);+ if (connection.state === WebSocketState.CONNECTING) {+ attachListeners();+ } else {+ detachListeners();+ hideIndicator();+ }+ });++ // On init, check if we should attach+ if (isAppConnecting(getConnectionState())) {+ attachListeners();+ }++ return {+ destroy() {+ detachListeners();+ unsubscribe();+ hideIndicator();+ },+ };+ });++ return [+ // Initial readonly configuration+ readonlyCompartment.of(EditorState.readOnly.of(isReadonly)),++ // Transaction extender to handle readonly updates+ EditorState.transactionExtender.of((tr) => {+ for (const effect of tr.effects) {+ if (effect.is(updateReadonlyEffect)) {+ const newReadonly = effect.value;+ if (newReadonly !== isReadonly) {+ isReadonly = newReadonly;+ return {+ effects: readonlyCompartment.reconfigure(+ EditorState.readOnly.of(newReadonly),+ ),+ };+ }+ }+ }+ return null;+ }),++ // View plugin to manage connection subscription+ ViewPlugin.define((view) => {+ const unsubscribe = store.sub(connectionAtom, () => {+ const connection = store.get(connectionAtom);+ const shouldBeReadonly = !isAppConnected(connection.state);++ // Dispatch effect to update readonly state+ view.dispatch({+ effects: updateReadonlyEffect.of(shouldBeReadonly),+ });+ });++ return {+ destroy() {+ unsubscribe();+ },+ };+ }),++ // Floating indicator plugin+ connectingIndicatorPlugin,+ ];+}++/**+ * Check if the editor is currently readonly+ */+export function isEditorReadonly(state: EditorState): boolean {+ return state.facet(EditorState.readOnly);+}diff --git a/frontend/src/core/network/connection.ts b/frontend/src/core/network/connection.tsindex 604a727f6e..dff8073a89 100644--- a/frontend/src/core/network/connection.ts+++ b/frontend/src/core/network/connection.ts@@ -16,3 +16,8 @@ export function waitForConnectionOpen() {return value.state === WebSocketState.OPEN;});}++export const isConnectingAtom = atom((get) => {+ const connection = get(connectionAtom);+ return connection.state === WebSocketState.CONNECTING;+});diff --git a/frontend/src/core/network/requests-network.ts b/frontend/src/core/network/requests-network.tsindex 1457d24e6a..a0c3d32ff3 100644--- a/frontend/src/core/network/requests-network.ts+++ b/frontend/src/core/network/requests-network.ts@@ -159,10 +159,12 @@ export function createNetworkRequests(): EditRequests & RunRequests {}).then(handleResponseReturnNull);},- readCode: () => {+ readCode: async () => {+ await waitForConnectionOpen();return getClient().POST("/api/kernel/read_code").then(handleResponse);},- readSnippets: () => {+ readSnippets: async () => {+ await waitForConnectionOpen();return getClient().GET("/api/documentation/snippets").then(handleResponse);@@ -196,6 +198,7 @@ export function createNetworkRequests(): EditRequests & RunRequests {.then(handleResponseReturnNull);},openFile: async (request) => {+ await waitForConnectionOpen();await getClient().POST("/api/files/open", {body: request,@@ -203,7 +206,8 @@ export function createNetworkRequests(): EditRequests & RunRequests {.then(handleResponseReturnNull);return null;},- getUsageStats: () => {+ getUsageStats: async () => {+ await waitForConnectionOpen();return getClient().GET("/api/usage").then(handleResponse);},sendPdb: (request) => {@@ -213,42 +217,48 @@ export function createNetworkRequests(): EditRequests & RunRequests {}).then(handleResponseReturnNull);},- sendListFiles: (request) => {+ sendListFiles: async (request) => {+ await waitForConnectionOpen();return getClient().POST("/api/files/list_files", {body: request,}).then(handleResponse);},- sendCreateFileOrFolder: (request) => {+ sendCreateFileOrFolder: async (request) => {+ await waitForConnectionOpen();return getClient().POST("/api/files/create", {body: request,}).then(handleResponse);},- sendDeleteFileOrFolder: (request) => {+ sendDeleteFileOrFolder: async (request) => {+ await waitForConnectionOpen();return getClient().POST("/api/files/delete", {body: request,}).then(handleResponse);},- sendRenameFileOrFolder: (request) => {+ sendRenameFileOrFolder: async (request) => {+ await waitForConnectionOpen();return getClient().POST("/api/files/move", {body: request,}).then(handleResponse);},- sendUpdateFile: (request) => {+ sendUpdateFile: async (request) => {+ await waitForConnectionOpen();return getClient().POST("/api/files/update", {body: request,}).then(handleResponse);},- sendFileDetails: (request) => {+ sendFileDetails: async (request) => {+ await waitForConnectionOpen();return getClient().POST("/api/files/file_details", {body: request,diff --git a/frontend/src/core/websocket/useMarimoWebSocket.tsx b/frontend/src/core/websocket/useMarimoWebSocket.tsxindex 86058b4bb9..73c61fdd3a 100644--- a/frontend/src/core/websocket/useMarimoWebSocket.tsx+++ b/frontend/src/core/websocket/useMarimoWebSocket.tsx@@ -281,9 +281,14 @@ export function useMarimoWebSocket(opts: {/*** Open callback. Set the connection status to open.*/- onOpen: () => {+ onOpen: async () => {// If we are open, we can reset our reconnecting flag.shouldTryReconnecting.current = true;++ // DO NOT COMMIT THIS UNCOMMENTED+ // Uncomment to emulate a slow connection+ // await new Promise((resolve) => setTimeout(resolve, 10_000));+setConnection({ state: WebSocketState.OPEN });},