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.

wasm: save notebook for when exporting as html (#3413)

Myles Scolnick3b9944448c60
diff --git a/frontend/src/core/wasm/bridge.ts b/frontend/src/core/wasm/bridge.ts
index 806b58ddb7..b9dbf2b7e9 100644
--- a/frontend/src/core/wasm/bridge.ts
+++ b/frontend/src/core/wasm/bridge.ts
@@ -213,6 +213,12 @@ export class PyodideBridge implements RunRequests, EditRequests {
notebookFileStore.saveFile(code.contents);
fallbackFileStore.saveFile(code.contents);
}
+ // Also save to the other worker, since this is needed for
+ // exporting to HTML
+ // Fire-and-forget
+ void this.rpc.proxy.request.saveNotebook(request).catch((error) => {
+ Logger.error(error);
+ });
return null;
};
diff --git a/frontend/src/core/wasm/worker/worker.ts b/frontend/src/core/wasm/worker/worker.ts
index ff6b64d7d9..7061fa7b81 100644
--- a/frontend/src/core/wasm/worker/worker.ts
+++ b/frontend/src/core/wasm/worker/worker.ts
@@ -26,6 +26,7 @@ import { getController } from "./getController";
import type {
ListPackagesResponse,
PackageOperationResponse,
+ SaveNotebookRequest,
} from "@/core/network/types";
import { decodeUtf8 } from "@/utils/strings";
@@ -230,6 +231,19 @@ const requestHandler = createRPCRequestHandler({
};
},
+ /**
+ * Save the notebook
+ */
+ saveNotebook: async (opts: SaveNotebookRequest) => {
+ // Partially duplicated from save-worker.ts
+ await pyodideReadyPromise; // Make sure loading is done
+ const saveFile = self.pyodide.runPython(`
+ from marimo._pyodide.bootstrap import save_file
+ save_file
+ `);
+ await saveFile(JSON.stringify(opts), WasmFileSystem.NOTEBOOK_FILENAME);
+ },
+
/**
* Call a function on the bridge
*/