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: WASM app with print() finish loading (#4144)

Myles Scolnick5462437938a5
diff --git a/frontend/src/core/wasm/__tests__/state.test.ts b/frontend/src/core/wasm/__tests__/state.test.ts
index a3ef32486f..cfdb680378 100644
--- a/frontend/src/core/wasm/__tests__/state.test.ts
+++ b/frontend/src/core/wasm/__tests__/state.test.ts
@@ -29,6 +29,7 @@ describe("hasAnyOutputAtom", () => {
`${i}` as CellId,
createCellRuntimeState({
output,
+ status: "queued",
outline: { items: [] },
}),
]),
@@ -88,4 +89,38 @@ describe("hasAnyOutputAtom", () => {
);
expect(store.get(hasAnyOutputAtom)).toBe(true);
});
+
+ it("should return true when all outputs are idle", () => {
+ const notebookState = createNotebookState([null, null]);
+ const cellId0 = "0" as CellId;
+ const cellId1 = "1" as CellId;
+ // Some idle cell, so returns false
+ store.set(notebookAtom, {
+ ...notebookState,
+ cellRuntime: {
+ ...notebookState.cellRuntime,
+ [cellId0]: {
+ ...notebookState.cellRuntime[cellId0],
+ status: "idle",
+ },
+ },
+ });
+ expect(store.get(hasAnyOutputAtom)).toBe(false);
+
+ // All cells are idle, so returns true
+ store.set(notebookAtom, {
+ ...notebookState,
+ cellRuntime: {
+ [cellId0]: {
+ ...notebookState.cellRuntime[cellId0],
+ status: "idle",
+ },
+ [cellId1]: {
+ ...notebookState.cellRuntime[cellId1],
+ status: "idle",
+ },
+ },
+ });
+ expect(store.get(hasAnyOutputAtom)).toBe(true);
+ });
});
diff --git a/frontend/src/core/wasm/state.ts b/frontend/src/core/wasm/state.ts
index 5762b92e3c..8c8934561a 100644
--- a/frontend/src/core/wasm/state.ts
+++ b/frontend/src/core/wasm/state.ts
@@ -7,7 +7,15 @@ export const wasmInitializationAtom = atom<string>("Initializing...");
export const hasAnyOutputAtom = atom<boolean>((get) => {
const notebook = get(notebookAtom);
- return Object.values(notebook.cellRuntime).some(
+ const runtimeStates = Object.values(notebook.cellRuntime);
+ // First check if there is any output
+ const hasOutput = runtimeStates.some(
(runtime) => !isOutputEmpty(runtime.output),
);
+ if (hasOutput) {
+ return true;
+ }
+ // If there is no output, check if they have all run to completion
+ // in case this notebook doesn't contain outputs
+ return runtimeStates.every((runtime) => runtime.status === "idle");
});