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
fix: skip completing placeholder on readonly editors (#5661)
Myles Scolnick7da44a76e8f5
diff --git a/frontend/src/core/codemirror/placeholder/extensions.ts b/frontend/src/core/codemirror/placeholder/extensions.tsindex 01287c8f44..9ae0c5f13b 100644--- a/frontend/src/core/codemirror/placeholder/extensions.ts+++ b/frontend/src/core/codemirror/placeholder/extensions.ts@@ -1,6 +1,7 @@/* Copyright 2024 Marimo. All rights reserved. */import type { Extension } from "@codemirror/state";import { EditorView, keymap, placeholder } from "@codemirror/view";+import { isEditorReadonly } from "../readonly/extension";/*** A placeholder that will be shown when the editor is empty and support@@ -25,6 +26,10 @@ export function smartPlaceholderExtension(text: string): Extension[] {}function acceptPlaceholder(cm: EditorView, text: string) {+ if (isEditorReadonly(cm.state)) {+ return false;+ }+// if empty, insert the placeholderconst docLength = cm.state.doc.length;if (docLength === 0) {diff --git a/frontend/src/core/codemirror/readonly/extension.test.ts b/frontend/src/core/codemirror/readonly/__tests__/extension.test.tssimilarity index 93%rename from frontend/src/core/codemirror/readonly/extension.test.tsrename to frontend/src/core/codemirror/readonly/__tests__/extension.test.tsindex 56308b4a5d..a4d7d7b9b7 100644--- a/frontend/src/core/codemirror/readonly/extension.test.ts+++ b/frontend/src/core/codemirror/readonly/__tests__/extension.test.ts@@ -5,8 +5,8 @@ import { EditorView } from "@codemirror/view";import { createStore } from "jotai";import { describe, expect, it } from "vitest";import { WebSocketState } from "@/core/websocket/types";-import { connectionAtom } from "../../network/connection";-import { dynamicReadonly, isEditorReadonly } from "./extension";+import { connectionAtom } from "../../../network/connection";+import { dynamicReadonly, isEditorReadonly } from "../extension";function makeStoreWithConnection(state: WebSocketState.CONNECTING | WebSocketState.OPEN,diff --git a/frontend/src/core/network/requests-network.ts b/frontend/src/core/network/requests-network.tsindex b6ef30737f..1c874e3172 100644--- a/frontend/src/core/network/requests-network.ts+++ b/frontend/src/core/network/requests-network.ts@@ -2,8 +2,9 @@import { once } from "lodash-es";import { getRuntimeManager } from "../runtime/config";+import { store } from "../state/jotai";import { API, createClientWithRuntimeManager } from "./api";-import { waitForConnectionOpen } from "./connection";+import { isConnectedAtom, waitForConnectionOpen } from "./connection";import type { EditRequests, RunRequests } from "./types";const { handleResponse, handleResponseReturnNull } = API;@@ -83,7 +84,11 @@ export function createNetworkRequests(): EditRequests & RunRequests {.then(handleResponseReturnNull);},sendRun: async (request) => {- await waitForConnectionOpen();+ // Rather than waiting, we just drop all sendRun requests if the connection is not open.+ // Otherwise we can get into a weird state of sending requests for cells that no longer exist.+ if (!store.get(isConnectedAtom)) {+ return null;+ }return getClient().POST("/api/kernel/run", {body: request,