Skip to content

Commit

Permalink
wasm: save notebook for when exporting as html (#3413)
Browse files Browse the repository at this point in the history
  • Loading branch information
mscolnick authored Jan 14, 2025
1 parent 4e42824 commit 3b99444
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frontend/src/core/wasm/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
14 changes: 14 additions & 0 deletions frontend/src/core/wasm/worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { getController } from "./getController";
import type {
ListPackagesResponse,
PackageOperationResponse,
SaveNotebookRequest,
} from "@/core/network/types";
import { decodeUtf8 } from "@/utils/strings";

Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 3b99444

Please sign in to comment.