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: wait for content to render before screenshot (#512)

Myles Scolnick4ba645d23bf2
diff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsx
index 41e279c11b..c355d14ef6 100644
--- a/frontend/src/components/editor/actions/useNotebookActions.tsx
+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx
@@ -40,12 +40,12 @@ export function useNotebookActions() {
icon: <ImageIcon size={14} strokeWidth={1.5} />,
label: "Export as PNG",
handle: async () => {
- await runDuringPresentMode(() => {
+ await runDuringPresentMode(async () => {
const app = document.getElementById("App");
if (!app) {
return;
}
- downloadHTMLAsImage(app, filename || "screenshot.png");
+ await downloadHTMLAsImage(app, filename || "screenshot.png");
});
},
},
diff --git a/frontend/src/core/mode.ts b/frontend/src/core/mode.ts
index ad1c240c3f..6a27e6bd84 100644
--- a/frontend/src/core/mode.ts
+++ b/frontend/src/core/mode.ts
@@ -56,17 +56,21 @@ interface ViewState {
export const initialMode = getInitialAppMode();
-export async function runDuringPresentMode(fn: () => void): Promise<void> {
+export async function runDuringPresentMode(
+ fn: () => void | Promise<void>
+): Promise<void> {
const state = store.get(viewStateAtom);
if (state.mode === "present") {
- return fn();
+ return await fn();
}
store.set(viewStateAtom, { ...state, mode: "present" });
- // wait 2 frames
+ // Wait 100ms to allow the page to render
+ await new Promise((resolve) => setTimeout(resolve, 100));
+ // Wait 2 frames
await new Promise((resolve) => requestAnimationFrame(resolve));
await new Promise((resolve) => requestAnimationFrame(resolve));
- fn();
+ await fn();
store.set(viewStateAtom, { ...state, mode: "edit" });
return undefined;
}