diff --git a/frontend/src/core/wasm/bridge.ts b/frontend/src/core/wasm/bridge.ts index 806b58ddb77..b9dbf2b7e9f 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 ff6b64d7d9f..7061fa7b81c 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 */