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: wasm loading styles and hide save (#3396)
Myles Scolnick9df64ad19123
diff --git a/frontend/src/components/editor/header/filename-input.tsx b/frontend/src/components/editor/header/filename-input.tsxindex d5db97d9b8..3455ebfaba 100644--- a/frontend/src/components/editor/header/filename-input.tsx+++ b/frontend/src/components/editor/header/filename-input.tsx@@ -152,6 +152,7 @@ export const FilenameInput = ({onFocus={onFocus}onBlur={onBlur}shouldFilter={false}+ id="filename-input"className="bg-transparent group filename-input"><CommandList>diff --git a/frontend/src/core/wasm/__tests__/state.test.ts b/frontend/src/core/wasm/__tests__/state.test.tsnew file mode 100644index 0000000000..a3ef32486f--- /dev/null+++ b/frontend/src/core/wasm/__tests__/state.test.ts@@ -0,0 +1,91 @@+/* Copyright 2024 Marimo. All rights reserved. */+import { expect, describe, it } from "vitest";+import { store } from "@/core/state/jotai";+import { hasAnyOutputAtom } from "../state";+import { notebookAtom } from "@/core/cells/cells";+import type { NotebookState } from "@/core/cells/cells";+import { MultiColumn, CollapsibleTree } from "@/utils/id-tree";+import type { OutputMessage } from "@/core/kernel/messages";+import type { CellId } from "@/core/cells/ids";+import { createRef } from "react";+import { createCellRuntimeState } from "@/core/cells/types";+import { createCell } from "@/core/cells/types";++describe("hasAnyOutputAtom", () => {+ const createNotebookState = (+ outputs: Array<OutputMessage | null>,+ ): NotebookState => ({+ cellIds: new MultiColumn([+ CollapsibleTree.from(outputs.map((_, i) => `${i}` as CellId)),+ ]),+ cellData: Object.fromEntries(+ outputs.map((_, i) => [+ `${i}` as CellId,+ createCell({ id: `${i}` as CellId }),+ ]),+ ),+ cellRuntime: Object.fromEntries(+ outputs.map((output, i) => [+ `${i}` as CellId,+ createCellRuntimeState({+ output,+ outline: { items: [] },+ }),+ ]),+ ),+ cellHandles: Object.fromEntries(+ outputs.map((_, i) => [`${i}` as CellId, createRef()]),+ ),+ cellLogs: [],+ scrollKey: null,+ history: [],+ });++ it("should return false when there are no outputs", () => {+ store.set(notebookAtom, createNotebookState([null, null]));+ expect(store.get(hasAnyOutputAtom)).toBe(false);+ });++ it("should return false when all outputs are empty", () => {+ store.set(+ notebookAtom,+ createNotebookState([+ { channel: "output", mimetype: "text/plain", data: "", timestamp: 0 },+ { channel: "output", mimetype: "text/plain", data: "", timestamp: 0 },+ ]),+ );+ expect(store.get(hasAnyOutputAtom)).toBe(false);+ });++ it("should return true when there is at least one non-empty output", () => {+ store.set(+ notebookAtom,+ createNotebookState([+ { channel: "output", mimetype: "text/plain", data: "", timestamp: 0 },+ {+ channel: "output",+ mimetype: "text/plain",+ data: "hello",+ timestamp: 0,+ },+ ]),+ );+ expect(store.get(hasAnyOutputAtom)).toBe(true);+ });++ it("should handle various output types", () => {+ store.set(+ notebookAtom,+ createNotebookState([+ {+ channel: "output",+ mimetype: "application/json",+ data: { foo: "bar" },+ timestamp: 0,+ },+ { channel: "output", mimetype: "text/plain", data: "", timestamp: 0 },+ ]),+ );+ expect(store.get(hasAnyOutputAtom)).toBe(true);+ });+});diff --git a/frontend/src/core/wasm/state.ts b/frontend/src/core/wasm/state.tsindex 4ebfba1bdc..5762b92e3c 100644--- a/frontend/src/core/wasm/state.ts+++ b/frontend/src/core/wasm/state.ts@@ -1,12 +1,13 @@/* Copyright 2024 Marimo. All rights reserved. */import { atom } from "jotai";import { notebookAtom } from "../cells/cells";+import { isOutputEmpty } from "../cells/outputs";export const wasmInitializationAtom = atom<string>("Initializing...");export const hasAnyOutputAtom = atom<boolean>((get) => {const notebook = get(notebookAtom);- return Object.values(notebook.cellRuntime).some((runtime) =>- Boolean(runtime.output),+ return Object.values(notebook.cellRuntime).some(+ (runtime) => !isOutputEmpty(runtime.output),);});diff --git a/marimo/_server/templates/templates.py b/marimo/_server/templates/templates.pyindex f4b0d8d7b5..09ab36514f 100644--- a/marimo/_server/templates/templates.py+++ b/marimo/_server/templates/templates.py@@ -273,6 +273,19 @@ def wasm_notebook_template("""body = body.replace("</head>", f"{warning_script}</head>")+ # Hide save button in WASM mode+ wasm_styles = """+ <style>+ #save-button {+ display: none !important;+ }+ #filename-input {+ display: none !important;+ }+ </style>+ """+ body = body.replace("</head>", f"{wasm_styles}</head>")+# If has custom css, inline the css and add to the headif app_config.css_file:css_contents = read_css_file(app_config.css_file, filename=filename)diff --git a/tests/_server/templates/test_templates.py b/tests/_server/templates/test_templates.pyindex 55fa09cb8f..871ebd8da3 100644--- a/tests/_server/templates/test_templates.py+++ b/tests/_server/templates/test_templates.py@@ -464,5 +464,7 @@ class TestWasmNotebookTemplate(unittest.TestCase):assert head in resultassert '<marimo-wasm hidden="">' in resultassert '<marimo-code hidden="" data-show-code="false">' in result+ assert "#save-button" in result+ assert "#filename-input" in resultfinally:os.remove(head_file)