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: fix remounting of editor, remove initialContents (#133)

Myles Scolnick12389ce7f42a
diff --git a/frontend/src/core/model/cells.ts b/frontend/src/core/model/cells.ts
index 89e8e50551..ee4e624d4e 100644
--- a/frontend/src/core/model/cells.ts
+++ b/frontend/src/core/model/cells.ts
@@ -30,7 +30,6 @@ export function createCell({
key,
ref = createRef(),
name = DEFAULT_CELL_NAME,
- initialContents = "",
code = "",
output = null,
consoleOutputs = [],
@@ -50,7 +49,6 @@ export function createCell({
ref: ref,
config: config,
name: name,
- initialContents: initialContents,
output: output,
code: code,
status: status,
@@ -71,8 +69,6 @@ export interface CellState {
key: CellId;
/** user-given name, or default */
name: string;
- /** initial contents of the editor */
- initialContents: string;
/** current contents of the editor */
code: string;
/** a message encoding the cell's output */
diff --git a/frontend/src/core/state/__tests__/__snapshots__/cells.test.ts.snap b/frontend/src/core/state/__tests__/__snapshots__/cells.test.ts.snap
index b32bedabc1..ce29be02ed 100644
--- a/frontend/src/core/state/__tests__/__snapshots__/cells.test.ts.snap
+++ b/frontend/src/core/state/__tests__/__snapshots__/cells.test.ts.snap
@@ -7,7 +7,6 @@ exports[`cell reducer > can run cell a stale cell 1`] = `
"consoleOutputs": [],
"edited": false,
"errored": false,
- "initialContents": "",
"interrupted": false,
"key": "1",
"lastCodeRun": "mo.slider()",
@@ -31,7 +30,6 @@ exports[`cell reducer > can run cell a stale cell 2`] = `
"consoleOutputs": [],
"edited": false,
"errored": false,
- "initialContents": "",
"interrupted": false,
"key": "1",
"lastCodeRun": "mo.slider()",
@@ -55,7 +53,6 @@ exports[`cell reducer > can run cell and receive cell messages 1`] = `
"consoleOutputs": [],
"edited": false,
"errored": false,
- "initialContents": "",
"interrupted": false,
"key": "0",
"lastCodeRun": null,
@@ -79,7 +76,6 @@ exports[`cell reducer > can run cell and receive cell messages 2`] = `
"consoleOutputs": [],
"edited": true,
"errored": false,
- "initialContents": "",
"interrupted": false,
"key": "0",
"lastCodeRun": null,
@@ -103,7 +99,6 @@ exports[`cell reducer > can run cell and receive cell messages 3`] = `
"consoleOutputs": [],
"edited": false,
"errored": false,
- "initialContents": "",
"interrupted": false,
"key": "0",
"lastCodeRun": "import marimo as mo",
@@ -127,7 +122,6 @@ exports[`cell reducer > can run cell and receive cell messages 4`] = `
"consoleOutputs": [],
"edited": false,
"errored": false,
- "initialContents": "",
"interrupted": false,
"key": "0",
"lastCodeRun": "import marimo as mo",
@@ -151,7 +145,6 @@ exports[`cell reducer > can run cell and receive cell messages 5`] = `
"consoleOutputs": [],
"edited": false,
"errored": false,
- "initialContents": "",
"interrupted": false,
"key": "0",
"lastCodeRun": "import marimo as mo",
@@ -182,7 +175,6 @@ exports[`cell reducer > can run cell and receive cell messages 6`] = `
],
"edited": false,
"errored": false,
- "initialContents": "",
"interrupted": false,
"key": "0",
"lastCodeRun": "import marimo as mo",
@@ -213,7 +205,6 @@ exports[`cell reducer > can run cell and receive cell messages 7`] = `
],
"edited": false,
"errored": false,
- "initialContents": "",
"interrupted": false,
"key": "0",
"lastCodeRun": "import marimo as mo",
@@ -250,7 +241,6 @@ import numpy",
],
"edited": true,
"errored": false,
- "initialContents": "",
"interrupted": false,
"key": "0",
"lastCodeRun": "import marimo as mo",
@@ -286,7 +276,6 @@ exports[`cell reducer > can run cell and receive cell messages 9`] = `
],
"edited": false,
"errored": false,
- "initialContents": "",
"interrupted": false,
"key": "0",
"lastCodeRun": "import marimo as mo",
@@ -323,7 +312,6 @@ import numpy",
],
"edited": true,
"errored": false,
- "initialContents": "",
"interrupted": false,
"key": "0",
"lastCodeRun": "import marimo as mo",
@@ -360,7 +348,6 @@ import numpy",
],
"edited": false,
"errored": true,
- "initialContents": "",
"interrupted": false,
"key": "0",
"lastCodeRun": "import marimo as mo
@@ -404,7 +391,6 @@ import numpy",
],
"edited": false,
"errored": false,
- "initialContents": "",
"interrupted": true,
"key": "0",
"lastCodeRun": null,
diff --git a/frontend/src/core/state/cells.ts b/frontend/src/core/state/cells.ts
index 4efafe96f0..cf2192686e 100644
--- a/frontend/src/core/state/cells.ts
+++ b/frontend/src/core/state/cells.ts
@@ -198,7 +198,6 @@ const { reducer, createActions } = createReducer(initialCellState, {
const undoCell = createCell({
key: CellId.create(),
name,
- initialContents: serializedEditorState.doc,
code: serializedEditorState.doc,
edited: serializedEditorState.doc.trim().length > 0,
serializedEditorState,
diff --git a/frontend/src/core/websocket/useMarimoWebSocket.tsx b/frontend/src/core/websocket/useMarimoWebSocket.tsx
index 59d334b54d..2952ba03be 100644
--- a/frontend/src/core/websocket/useMarimoWebSocket.tsx
+++ b/frontend/src/core/websocket/useMarimoWebSocket.tsx
@@ -68,7 +68,6 @@ export function useMarimoWebSocket(opts: {
createCell({
key: CellId.create(),
code,
- initialContents: code,
name: names[i],
config: configs[i],
})
diff --git a/frontend/src/editor/Cell.tsx b/frontend/src/editor/Cell.tsx
index 57cd9c9d0c..8ec70ed057 100644
--- a/frontend/src/editor/Cell.tsx
+++ b/frontend/src/editor/Cell.tsx
@@ -64,7 +64,7 @@ export interface CellProps
| "consoleOutputs"
| "status"
| "output"
- | "initialContents"
+ | "code"
| "edited"
| "errored"
| "interrupted"
@@ -105,7 +105,7 @@ const CellComponent = (
showPlaceholder,
allowFocus,
cellId,
- initialContents,
+ code,
output,
consoleOutputs,
status,
@@ -251,7 +251,7 @@ const CellComponent = (
// Otherwise, create a new editor.
editorView.current = new EditorView({
state: EditorState.create({
- doc: initialContents,
+ doc: code,
extensions: extensions,
}),
});
@@ -267,7 +267,7 @@ const CellComponent = (
state: EditorState.fromJSON(
serializedEditorState,
{
- doc: initialContents,
+ doc: code,
extensions: extensions,
},
{ history: historyField }
@@ -294,7 +294,7 @@ const CellComponent = (
});
}
- // We don't want to re-run this effect when `allowFocus` changes.
+ // We don't want to re-run this effect when `allowFocus` or `code` changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
cellId,
@@ -302,7 +302,6 @@ const CellComponent = (
userConfig.keymap,
theme,
showPlaceholder,
- initialContents,
createAbove,
createBelow,
deleteCell,
diff --git a/frontend/src/editor/renderers/CellArray.tsx b/frontend/src/editor/renderers/CellArray.tsx
index e227158ef7..3bfd15cdae 100644
--- a/frontend/src/editor/renderers/CellArray.tsx
+++ b/frontend/src/editor/renderers/CellArray.tsx
@@ -94,7 +94,7 @@ export const CellArray: React.FC<CellArrayProps> = ({
showPlaceholder={cells.present.length === 1}
allowFocus={!invisible}
cellId={cell.key}
- initialContents={cell.initialContents}
+ code={cell.code}
output={cell.output}
consoleOutputs={cell.consoleOutputs}
status={cell.status}
diff --git a/frontend/src/stories/cell.stories.tsx b/frontend/src/stories/cell.stories.tsx
index 19b25e17bb..d58aeefb42 100644
--- a/frontend/src/stories/cell.stories.tsx
+++ b/frontend/src/stories/cell.stories.tsx
@@ -17,7 +17,7 @@ const props: CellProps = {
theme: "light",
showPlaceholder: false,
cellId: "1" as CellId,
- initialContents: "import marimo as mo",
+ code: "import marimo as mo",
output: null,
consoleOutputs: [],
status: "idle",