Skip to content

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.

fix: cell run button in present (#1707)

Myles Scolnicka2aa9b94682e
diff --git a/frontend/src/components/editor/cell/useRunCells.ts b/frontend/src/components/editor/cell/useRunCells.ts
index 9741ae65af..bd1ab30b4d 100644
--- a/frontend/src/components/editor/cell/useRunCells.ts
+++ b/frontend/src/components/editor/cell/useRunCells.ts
@@ -1,8 +1,7 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { CellId } from "@/core/cells/ids";
import { sendRun } from "@/core/network/requests";
-import { staleCellIds, useNotebook } from "@/core/cells/cells";
-import { derefNotNull } from "@/utils/dereference";
+import { staleCellIds, useCellActions, useNotebook } from "@/core/cells/cells";
import useEvent from "react-use-event-hook";
import { getEditorCodeAsPython } from "@/core/codemirror/language/utils";
import { Logger } from "@/utils/Logger";
@@ -36,19 +35,25 @@ export function useRunCell(cellId: CellId | undefined) {
*/
function useRunCells() {
const notebook = useNotebook();
+ const { prepareForRun } = useCellActions();
const runCells = useEvent(async (cellIds: CellId[]) => {
if (cellIds.length === 0) {
return;
}
- const { cellHandles } = notebook;
+ const { cellHandles, cellData } = notebook;
const codes: string[] = [];
for (const cellId of cellIds) {
- const ref = derefNotNull(cellHandles[cellId]);
- codes.push(getEditorCodeAsPython(ref.editorView));
- ref.registerRun();
+ const ref = cellHandles[cellId];
+ if (ref.current) {
+ codes.push(getEditorCodeAsPython(ref.current.editorView));
+ ref.current.registerRun();
+ } else {
+ prepareForRun({ cellId });
+ codes.push(cellData[cellId].code);
+ }
}
await sendRun({ cellIds: cellIds, codes: codes }).catch((error) => {