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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: skip wasm controller dynamic import unless host opts in (#9467)
Myles Scolnick31d54e003d8d
diff --git a/frontend/src/core/wasm/__tests__/bridge.test.ts b/frontend/src/core/wasm/__tests__/bridge.test.tsindex fe0c4ef85c..4c4393cd5b 100644--- a/frontend/src/core/wasm/__tests__/bridge.test.ts+++ b/frontend/src/core/wasm/__tests__/bridge.test.ts@@ -58,7 +58,7 @@ vi.mock("@/core/wasm/store", () => ({// Import after all mocks are set upimport { store } from "@/core/state/jotai";import { initialModeAtom } from "@/core/mode";-import { PyodideBridge } from "../bridge";+import { getWasmWorkerName, PyodideBridge } from "../bridge";// Access INSTANCE once at module level so the constructor runs (and// addMessageListener populates rpcListeners) before any test executes.@@ -111,3 +111,28 @@ describe("PyodideBridge.readCode", () => {expect(mockNotebookReadFile).not.toHaveBeenCalled();});});++describe("getWasmWorkerName", () => {+ afterEach(() => {+ delete (window as unknown as { __MARIMO_HAS_WASM_CONTROLLER__?: boolean })+ .__MARIMO_HAS_WASM_CONTROLLER__;+ });++ it("returns the version without suffix by default", () => {+ expect(getWasmWorkerName()).toBe("0.0.0-test");+ });++ it("appends ::controller when the host opts in", () => {+ (+ window as unknown as { __MARIMO_HAS_WASM_CONTROLLER__?: boolean }+ ).__MARIMO_HAS_WASM_CONTROLLER__ = true;+ expect(getWasmWorkerName()).toBe("0.0.0-test::controller");+ });++ it("does not append the suffix for non-true values", () => {+ (+ window as unknown as { __MARIMO_HAS_WASM_CONTROLLER__?: unknown }+ ).__MARIMO_HAS_WASM_CONTROLLER__ = "true";+ expect(getWasmWorkerName()).toBe("0.0.0-test");+ });+});diff --git a/frontend/src/core/wasm/bridge.ts b/frontend/src/core/wasm/bridge.tsindex 8ae6875f14..f59e463c59 100644--- a/frontend/src/core/wasm/bridge.ts+++ b/frontend/src/core/wasm/bridge.ts@@ -81,9 +81,9 @@ export class PyodideBridge implements RunRequests, EditRequests {new URL("./worker/save-worker.ts", import.meta.url),{type: "module",- // Pass the version to the worker+ // Pass the version (and optional capability suffix) to the worker/* @vite-ignore */- name: getMarimoVersion(),+ name: getWasmWorkerName(),},);@@ -101,9 +101,9 @@ export class PyodideBridge implements RunRequests, EditRequests {new URL("./worker/worker.ts", import.meta.url),{type: "module",- // Pass the version to the worker+ // Pass the version (and optional capability suffix) to the worker/* @vite-ignore */- name: getMarimoVersion(),+ name: getWasmWorkerName(),},);@@ -634,3 +634,17 @@ export function createPyodideConnection(): IConnectionTransport {PyodideBridge.INSTANCE.attachMessageConsumer(callback);});}++// Compose the worker name. The version prefix is read by getMarimoVersion()+// in the worker; the optional "::controller" suffix tells getController.ts+// that the host page provides a custom /wasm/controller.js and that the+// dynamic import should be attempted. Hosts opt in by setting+// `window.__MARIMO_HAS_WASM_CONTROLLER__ = true` before+// PyodideBridge/worker initialization.+export function getWasmWorkerName(): string {+ const hasCustomController =+ typeof window !== "undefined" &&+ (window as unknown as { __MARIMO_HAS_WASM_CONTROLLER__?: boolean })+ .__MARIMO_HAS_WASM_CONTROLLER__ === true;+ return getMarimoVersion() + (hasCustomController ? "::controller" : "");+}diff --git a/frontend/src/core/wasm/worker/getController.ts b/frontend/src/core/wasm/worker/getController.tsindex 8dbf862179..eedc619739 100644--- a/frontend/src/core/wasm/worker/getController.ts+++ b/frontend/src/core/wasm/worker/getController.ts@@ -5,6 +5,13 @@ import type { WasmController } from "./types";// Load the controller// Falls back to the default controllerexport async function getController(version: string): Promise<WasmController> {+ // Hosts that provide a custom /wasm/controller.js opt in via the worker+ // name (see bridge.ts). Default: skip the dynamic import to avoid a+ // guaranteed-404 round trip on the standard build.+ const hasCustomController = self.name?.includes("::controller") ?? false;+ if (!hasCustomController) {+ return new DefaultWasmController();+ }try {const controller = await import(/* @vite-ignore */ `/wasm/controller.js?version=${version}`diff --git a/frontend/src/core/wasm/worker/save-worker.ts b/frontend/src/core/wasm/worker/save-worker.tsindex 484eba94fc..b211d7bd18 100644--- a/frontend/src/core/wasm/worker/save-worker.ts+++ b/frontend/src/core/wasm/worker/save-worker.ts@@ -103,5 +103,6 @@ const rpc = createRPC<SaveWorkerSchema, ParentSchema>({rpc.send("ready", {});function getMarimoVersion() {- return self.name; // We store the version in the worker name+ // Worker name is "<version>" or "<version>::<capability>" — see bridge.ts.+ return self.name.split("::")[0];}diff --git a/frontend/src/core/wasm/worker/worker.ts b/frontend/src/core/wasm/worker/worker.tsindex ac7eca9096..e7890c9d0b 100644--- a/frontend/src/core/wasm/worker/worker.ts+++ b/frontend/src/core/wasm/worker/worker.ts@@ -375,7 +375,8 @@ const namesThatRequireSync = new Set<keyof RawBridge>([]);function getMarimoVersion() {- return self.name; // We store the version in the worker name+ // Worker name is "<version>" or "<version>::<capability>" — see bridge.ts.+ return self.name.split("::")[0];}const pyodideReadyPromise = t.wrapAsync(loadPyodideAndPackages)();