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
refactor(wasm): pass version through runtime config (#10920)
Péter Gyarmati397b26bb0b02
diff --git a/frontend/src/core/wasm/__tests__/bridge.test.ts b/frontend/src/core/wasm/__tests__/bridge.test.tsindex 9a0c4769e1..e784022e36 100644--- a/frontend/src/core/wasm/__tests__/bridge.test.ts+++ b/frontend/src/core/wasm/__tests__/bridge.test.ts@@ -126,6 +126,7 @@ describe("PyodideBridge.readCode", () => {await PyodideBridge.INSTANCE.readCode();expect(mockBootstrap).toHaveBeenCalledWith({+ version: "0.0.0-test",pyodideIndexUrl: undefined,pyodideLockfileUrl: undefined,pypiIndexUrl: undefined,@@ -223,21 +224,21 @@ describe("getWasmWorkerName", () => {.__MARIMO_HAS_WASM_CONTROLLER__;});- it("returns the version without suffix by default", () => {- expect(getWasmWorkerName()).toBe("0.0.0-test");+ it("returns the default worker name without suffix", () => {+ expect(getWasmWorkerName()).toBe("marimo");});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");+ expect(getWasmWorkerName()).toBe("marimo::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");+ expect(getWasmWorkerName()).toBe("marimo");});});diff --git a/frontend/src/core/wasm/__tests__/runtime-config.test.ts b/frontend/src/core/wasm/__tests__/runtime-config.test.tsindex 58aa3ab841..4386e64232 100644--- a/frontend/src/core/wasm/__tests__/runtime-config.test.ts+++ b/frontend/src/core/wasm/__tests__/runtime-config.test.ts@@ -1,8 +1,12 @@/* Copyright 2026 Marimo. All rights reserved. */-import { afterEach, assert, describe, expect, it } from "vitest";+import { afterEach, assert, describe, expect, it, vi } from "vitest";import { getWasmRuntimeConfig } from "../runtime-config";+vi.mock("@/core/meta/globals", () => ({+ getMarimoVersion: () => "0.0.0-test",+}));+afterEach(() => {document.head.innerHTML = "";});@@ -10,6 +14,7 @@ afterEach(() => {describe("getWasmRuntimeConfig", () => {it("uses runtime defaults when no URLs are configured", () => {expect(getWasmRuntimeConfig()).toEqual({+ version: "0.0.0-test",pyodideIndexUrl: undefined,pyodideLockfileUrl: undefined,pypiIndexUrl: undefined,@@ -25,6 +30,7 @@ describe("getWasmRuntimeConfig", () => {data-pypi-index-url="https://packages.example.com/{package_name}/json"></marimo-wasm>`;expect(getWasmRuntimeConfig()).toEqual({+ version: "0.0.0-test",pyodideIndexUrl: "https://example.com/blog/runtime/",pyodideLockfileUrl: "https://example.com/locks/pyodide.json?v=1&x=2",pypiIndexUrl: "https://packages.example.com/{package_name}/json",@@ -46,6 +52,7 @@ describe("getWasmRuntimeConfig", () => {element.dataset[key] = "https://invalid host/";expect(getWasmRuntimeConfig()).toEqual({+ version: "0.0.0-test",pyodideIndexUrl: "https://example.com/notebook/pyodide/",pyodideLockfileUrl:"https://example.com/notebook/lockfile/pyodide.json",diff --git a/frontend/src/core/wasm/bridge.ts b/frontend/src/core/wasm/bridge.tsindex edfc4c0003..e3626f2bf2 100644--- a/frontend/src/core/wasm/bridge.ts+++ b/frontend/src/core/wasm/bridge.ts@@ -12,7 +12,6 @@ import { generateUUID } from "@/utils/uuid";import { createModuleWorker } from "@/utils/worker";import { notebookIsRunningAtom } from "../cells/cells";import type { CommandMessage } from "../kernel/messages";-import { getMarimoVersion } from "../meta/globals";import { getInitialAppMode } from "../mode";import { API } from "../network/api";import type {@@ -49,6 +48,7 @@ import { fallbackFileStore, notebookFileStore } from "./store";import { isWasm } from "./utils";import saveWorkerUrl from "./worker/save-worker.ts?worker&url";import workerUrl from "./worker/worker.ts?worker&url";+import { CUSTOM_CONTROLLER_SUFFIX } from "./worker/constants";import type { SaveWorkerSchema } from "./worker/save-worker";import type { WorkerSchema } from "./worker/worker";@@ -91,7 +91,7 @@ export class PyodideBridge implements RunRequests, EditRequests {const saveWorker = createModuleWorker(new URL(saveWorkerUrl, import.meta.url),{- // Pass the version (and optional capability suffix) to the worker+ // Pass the optional custom-controller capability to the worker.name: getWasmWorkerName(),},);@@ -110,7 +110,7 @@ export class PyodideBridge implements RunRequests, EditRequests {// Create a workerconst worker = createModuleWorker(new URL(workerUrl, import.meta.url), {- // Pass the version (and optional capability suffix) to the worker+ // Pass the optional custom-controller capability to the worker.name: getWasmWorkerName(),});@@ -726,10 +726,9 @@ export function createPyodideConnection(): IConnectionTransport {});}-// 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+// Compose the worker name. 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 {@@ -737,5 +736,5 @@ export function getWasmWorkerName(): string {typeof window !== "undefined" &&(window as unknown as { __MARIMO_HAS_WASM_CONTROLLER__?: boolean }).__MARIMO_HAS_WASM_CONTROLLER__ === true;- return getMarimoVersion() + (hasCustomController ? "::controller" : "");+ return `marimo${hasCustomController ? CUSTOM_CONTROLLER_SUFFIX : ""}`;}diff --git a/frontend/src/core/wasm/runtime-config.ts b/frontend/src/core/wasm/runtime-config.tsindex 7461a19818..4ff138e747 100644--- a/frontend/src/core/wasm/runtime-config.ts+++ b/frontend/src/core/wasm/runtime-config.ts@@ -1,6 +1,9 @@/* Copyright 2026 Marimo. All rights reserved. */+import { getMarimoVersion } from "@/core/meta/globals";+export interface WasmRuntimeConfig {+ version: string;pyodideIndexUrl?: string;pyodideLockfileUrl?: string;pypiIndexUrl?: string;@@ -16,6 +19,7 @@ export function getWasmRuntimeConfig(): WasmRuntimeConfig {}};return {+ version: getMarimoVersion(),pyodideIndexUrl: resolve(element?.dataset.pyodideIndexUrl),pyodideLockfileUrl: resolve(element?.dataset.pyodideLockfileUrl),// URL serialization escapes the placeholder understood by micropip.diff --git a/frontend/src/core/wasm/worker/constants.ts b/frontend/src/core/wasm/worker/constants.tsindex 9a281241be..33215a7deb 100644--- a/frontend/src/core/wasm/worker/constants.ts+++ b/frontend/src/core/wasm/worker/constants.ts@@ -1,2 +1,3 @@/* Copyright 2026 Marimo. All rights reserved. */+export const CUSTOM_CONTROLLER_SUFFIX = "::controller";export const TRANSPORT_ID = "marimo-transport";diff --git a/frontend/src/core/wasm/worker/getController.ts b/frontend/src/core/wasm/worker/getController.tsindex eedc619739..f5a5595c87 100644--- a/frontend/src/core/wasm/worker/getController.ts+++ b/frontend/src/core/wasm/worker/getController.ts@@ -1,5 +1,6 @@/* Copyright 2026 Marimo. All rights reserved. */import { DefaultWasmController } from "./bootstrap";+import { CUSTOM_CONTROLLER_SUFFIX } from "./constants";import type { WasmController } from "./types";// Load the controller@@ -8,7 +9,8 @@ export 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;+ const hasCustomController =+ self.name?.includes(CUSTOM_CONTROLLER_SUFFIX) ?? false;if (!hasCustomController) {return new DefaultWasmController();}diff --git a/frontend/src/core/wasm/worker/save-worker.ts b/frontend/src/core/wasm/worker/save-worker.tsindex 51325d6ce3..83defaf286 100644--- a/frontend/src/core/wasm/worker/save-worker.ts+++ b/frontend/src/core/wasm/worker/save-worker.ts@@ -33,15 +33,14 @@ const runtimeConfig = new Deferred<WasmRuntimeConfig>();async function loadPyodideAndPackages() {try {// Import pyodide- const marimoVersion = getMarimoVersion();- const pyodideVersion = getPyodideVersion(marimoVersion);+ const config = await runtimeConfig.promise;+ const pyodideVersion = getPyodideVersion(config.version);// Bootstrap the controller- const controller = await getController(marimoVersion);+ const controller = await getController(config.version);self.controller = controller;self.pyodide = await controller.bootstrap({- ...(await runtimeConfig.promise),- version: marimoVersion,+ ...config,pyodideVersion: pyodideVersion,});@@ -108,8 +107,3 @@ const rpc = createRPC<SaveWorkerSchema, ParentSchema>({rpc.addMessageListener("bootstrap", (config) => runtimeConfig.resolve(config));rpc.send("ready", {});--function getMarimoVersion() {- // Worker name is "<version>" or "<version>::<capability>" — see bridge.ts.- return self.name.split("::")[0];-}diff --git a/frontend/src/core/wasm/worker/types.ts b/frontend/src/core/wasm/worker/types.tsindex ded1150afc..041b95877c 100644--- a/frontend/src/core/wasm/worker/types.ts+++ b/frontend/src/core/wasm/worker/types.ts@@ -46,7 +46,6 @@ export interface WasmController {*/bootstrap(opts: WasmRuntimeConfig & {- version: string;pyodideVersion: string;},): Promise<PyodideInterface>;diff --git a/frontend/src/core/wasm/worker/worker.ts b/frontend/src/core/wasm/worker/worker.tsindex d3c0c2b161..3c24800310 100644--- a/frontend/src/core/wasm/worker/worker.ts+++ b/frontend/src/core/wasm/worker/worker.ts@@ -53,16 +53,15 @@ const runtimeConfig = new Deferred<WasmRuntimeConfig>();// Initialize pyodideasync function loadPyodideAndPackages() {try {- const marimoVersion = getMarimoVersion();- const pyodideVersion = getPyodideVersion(marimoVersion);- const controller = await t.wrapAsync(getController)(marimoVersion);+ const config = await runtimeConfig.promise;+ const pyodideVersion = getPyodideVersion(config.version);+ const controller = await t.wrapAsync(getController)(config.version);self.controller = controller;rpc.send.initializingMessage({message: "Loading marimo...",});self.pyodide = await t.wrapAsync(controller.bootstrap.bind(controller))({- ...(await runtimeConfig.promise),- version: marimoVersion,+ ...config,pyodideVersion: pyodideVersion,});} catch (error) {@@ -380,9 +379,4 @@ const namesThatRequireSync = new Set<keyof RawBridge>(["update_file",]);-function getMarimoVersion() {- // Worker name is "<version>" or "<version>::<capability>" — see bridge.ts.- return self.name.split("::")[0];-}-const pyodideReadyPromise = t.wrapAsync(loadPyodideAndPackages)();