File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 11/* Copyright 2024 Marimo. All rights reserved. */
22import type { Extension } from "@codemirror/state" ;
33import { EditorView , keymap , placeholder } from "@codemirror/view" ;
4+ import { isEditorReadonly } from "../readonly/extension" ;
45
56/**
67 * A placeholder that will be shown when the editor is empty and support
@@ -25,6 +26,10 @@ export function smartPlaceholderExtension(text: string): Extension[] {
2526}
2627
2728function acceptPlaceholder ( cm : EditorView , text : string ) {
29+ if ( isEditorReadonly ( cm . state ) ) {
30+ return false ;
31+ }
32+
2833 // if empty, insert the placeholder
2934 const docLength = cm . state . doc . length ;
3035 if ( docLength === 0 ) {
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ import { EditorView } from "@codemirror/view";
55import { createStore } from "jotai" ;
66import { describe , expect , it } from "vitest" ;
77import { WebSocketState } from "@/core/websocket/types" ;
8- import { connectionAtom } from "../../network/connection" ;
9- import { dynamicReadonly , isEditorReadonly } from "./extension" ;
8+ import { connectionAtom } from "../../../ network/connection" ;
9+ import { dynamicReadonly , isEditorReadonly } from ".. /extension" ;
1010
1111function makeStoreWithConnection (
1212 state : WebSocketState . CONNECTING | WebSocketState . OPEN ,
Original file line number Diff line number Diff line change 22
33import { once } from "lodash-es" ;
44import { getRuntimeManager } from "../runtime/config" ;
5+ import { store } from "../state/jotai" ;
56import { API , createClientWithRuntimeManager } from "./api" ;
6- import { waitForConnectionOpen } from "./connection" ;
7+ import { isConnectedAtom , waitForConnectionOpen } from "./connection" ;
78import type { EditRequests , RunRequests } from "./types" ;
89
910const { handleResponse, handleResponseReturnNull } = API ;
@@ -83,7 +84,11 @@ export function createNetworkRequests(): EditRequests & RunRequests {
8384 . then ( handleResponseReturnNull ) ;
8485 } ,
8586 sendRun : async ( request ) => {
86- await waitForConnectionOpen ( ) ;
87+ // Rather than waiting, we just drop all sendRun requests if the connection is not open.
88+ // Otherwise we can get into a weird state of sending requests for cells that no longer exist.
89+ if ( ! store . get ( isConnectedAtom ) ) {
90+ return null ;
91+ }
8792 return getClient ( )
8893 . POST ( "/api/kernel/run" , {
8994 body : request ,
You can’t perform that action at this time.
0 commit comments