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.

improvement: add experimental support for Layouts in wasm (#1767)

Myles Scolnickeef4464ac0a0
diff --git a/frontend/src/components/app-config/user-config-form.tsx b/frontend/src/components/app-config/user-config-form.tsx
index 19542f3aec..bc76b19030 100644
--- a/frontend/src/components/app-config/user-config-form.tsx
+++ b/frontend/src/components/app-config/user-config-form.tsx
@@ -12,7 +12,7 @@ import {
} from "@/components/ui/form";
import {
APP_WIDTHS,
- UserConfig,
+ type UserConfig,
UserConfigSchema,
} from "../../core/config/config-schema";
import { Checkbox } from "../ui/checkbox";
@@ -24,7 +24,7 @@ import { KEYMAP_PRESETS } from "@/core/codemirror/keymaps/keymaps";
import { CopilotConfig } from "@/core/codemirror/copilot/copilot-config";
import { SettingTitle, SettingDescription, SettingSubtitle } from "./common";
import { THEMES } from "@/theme/useTheme";
-import { isPyodide } from "@/core/pyodide/utils";
+import { isWasm } from "@/core/wasm/utils";
import { PackageManagerNames } from "../../core/config/config-schema";
import { Kbd } from "../ui/kbd";
import { NumberField } from "@/components/ui/number-field";
@@ -52,7 +52,7 @@ export const UserConfigForm: React.FC = () => {
});
};
- const isWasm = isPyodide();
+ const isWasmRuntime = isWasm();
const renderCopilotProvider = () => {
const copilot = form.getValues("completion.copilot");
@@ -402,7 +402,7 @@ export const UserConfigForm: React.FC = () => {
<SettingGroup title="Package Management">
<FormField
control={form.control}
- disabled={isWasm}
+ disabled={isWasmRuntime}
name="package_management.manager"
render={({ field }) => (
<FormItem className={formItemClasses}>
@@ -493,7 +493,7 @@ export const UserConfigForm: React.FC = () => {
data-testid="auto-reload-select"
onChange={(e) => field.onChange(e.target.value)}
value={field.value}
- disabled={isWasm}
+ disabled={isWasmRuntime}
className="inline-flex mr-2"
>
{["off", "lazy", "autorun"].map((option) => (
@@ -530,7 +530,7 @@ export const UserConfigForm: React.FC = () => {
</p>
<FormField
control={form.control}
- disabled={isWasm}
+ disabled={isWasmRuntime}
name="ai.open_ai.base_url"
render={({ field }) => (
<FormItem className={formItemClasses}>
@@ -549,7 +549,7 @@ export const UserConfigForm: React.FC = () => {
/>
<FormField
control={form.control}
- disabled={isWasm}
+ disabled={isWasmRuntime}
name="ai.open_ai.model"
render={({ field }) => (
<FormItem className={formItemClasses}>
diff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsx
index 14757c671e..7db38149ae 100644
--- a/frontend/src/components/editor/actions/useNotebookActions.tsx
+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx
@@ -34,14 +34,14 @@ import {
saveCellConfig,
} from "@/core/network/requests";
import { Objects } from "@/utils/objects";
-import { ActionButton } from "./types";
+import type { ActionButton } from "./types";
import { downloadAsHTML } from "@/core/static/download-html";
import { toast } from "@/components/ui/use-toast";
import { useFilename } from "@/core/saving/filename";
import { useImperativeModal } from "@/components/modal/ImperativeModal";
import { ShareStaticNotebookModal } from "@/components/static-html/share-modal";
import { useRestartKernel } from "./useRestartKernel";
-import { createShareableLink } from "@/core/pyodide/share";
+import { createShareableLink } from "@/core/wasm/share";
import { useChromeActions, useChromeState } from "../chrome/state";
import { PANEL_ICONS, PANEL_TYPES } from "../chrome/types";
import { startCase } from "lodash-es";
diff --git a/frontend/src/components/editor/app-container.tsx b/frontend/src/components/editor/app-container.tsx
index fbb0649546..68dbb3667b 100644
--- a/frontend/src/components/editor/app-container.tsx
+++ b/frontend/src/components/editor/app-container.tsx
@@ -1,11 +1,12 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { WebSocketState } from "@/core/websocket/types";
import { cn } from "@/utils/cn";
-import React, { PropsWithChildren } from "react";
+import type React from "react";
+import type { PropsWithChildren } from "react";
import { StatusOverlay } from "./header/status";
-import { AppConfig } from "@/core/config/config-schema";
+import type { AppConfig } from "@/core/config/config-schema";
import { WrappedWithSidebar } from "./renderers/vertical-layout/sidebar/wrapped-with-sidebar";
-import { PyodideLoader } from "@/core/pyodide/PyodideLoader";
+import { PyodideLoader } from "@/core/wasm/PyodideLoader";
import { DynamicFavicon } from "./dynamic-favicon";
interface Props {
diff --git a/frontend/src/components/editor/chrome/wrapper/machine-stats.tsx b/frontend/src/components/editor/chrome/wrapper/machine-stats.tsx
index db5c28eef3..80d307255e 100644
--- a/frontend/src/components/editor/chrome/wrapper/machine-stats.tsx
+++ b/frontend/src/components/editor/chrome/wrapper/machine-stats.tsx
@@ -3,8 +3,8 @@ import { Spinner } from "@/components/icons/spinner";
import { Tooltip } from "@/components/ui/tooltip";
import { connectionAtom } from "@/core/network/connection";
import { getUsageStats } from "@/core/network/requests";
-import { UsageResponse } from "@/core/network/types";
-import { isPyodide } from "@/core/pyodide/utils";
+import type { UsageResponse } from "@/core/network/types";
+import { isWasm } from "@/core/wasm/utils";
import { WebSocketState } from "@/core/websocket/types";
import { useAsyncData } from "@/hooks/useAsyncData";
import { useInterval } from "@/hooks/useInterval";
@@ -16,7 +16,8 @@ import {
MemoryStickIcon,
PowerOffIcon,
} from "lucide-react";
-import React, { useState } from "react";
+import type React from "react";
+import { useState } from "react";
export const MachineStats: React.FC = (props) => {
const [nonce, setNonce] = useState(0);
@@ -28,7 +29,7 @@ export const MachineStats: React.FC = (props) => {
);
const { data } = useAsyncData(async () => {
- if (isPyodide()) {
+ if (isWasm()) {
return null;
}
if (connection.state !== WebSocketState.OPEN) {
diff --git a/frontend/src/components/editor/file-tree/file-explorer.tsx b/frontend/src/components/editor/file-tree/file-explorer.tsx
index 1fae8464b2..e0c4c13946 100644
--- a/frontend/src/components/editor/file-tree/file-explorer.tsx
+++ b/frontend/src/components/editor/file-tree/file-explorer.tsx
@@ -46,12 +46,12 @@ import { cn } from "@/utils/cn";
import { FileViewer } from "./file-viewer";
import { treeAtom, openStateAtom } from "./state";
import { useFileExplorerUpload } from "./upload";
-import { isPyodide } from "@/core/pyodide/utils";
+import { isWasm } from "@/core/wasm/utils";
import { useAsyncData } from "@/hooks/useAsyncData";
import { ErrorBanner } from "@/plugins/impl/common/error-banner";
import { Spinner } from "@/components/icons/spinner";
import type { RequestingTree } from "./requesting-tree";
-import { FilePath } from "@/utils/paths";
+import type { FilePath } from "@/utils/paths";
const RequestingTreeContext = React.createContext<RequestingTree | null>(null);
@@ -352,8 +352,8 @@ const Node = ({ node, style, dragHandle }: NodeRendererProps<FileInfo>) => {
<CopyIcon className="mr-2" size={14} strokeWidth={1.5} />
Copy snippet to clipboard
</DropdownMenuItem>
- {/* Not shown in Pyodide */}
- {node.data.isMarimoFile && !isPyodide() && (
+ {/* Not shown in WASM */}
+ {node.data.isMarimoFile && !isWasm() && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem onSelect={handleOpenMarimoFile}>
diff --git a/frontend/src/components/editor/package-alert.tsx b/frontend/src/components/editor/package-alert.tsx
index 1247edd62e..96aa8921c2 100644
--- a/frontend/src/components/editor/package-alert.tsx
+++ b/frontend/src/components/editor/package-alert.tsx
@@ -10,7 +10,10 @@ import {
FormMessage,
} from "@/components/ui/form";
import { saveUserConfig } from "@/core/network/requests";
-import { UserConfig, UserConfigSchema } from "../../core/config/config-schema";
+import {
+ type UserConfig,
+ UserConfigSchema,
+} from "../../core/config/config-schema";
import { NativeSelect } from "../ui/native-select";
import { cn } from "@/utils/cn";
import { sendInstallMissingPackages } from "@/core/network/requests";
@@ -29,14 +32,14 @@ import {
PackageCheckIcon,
XIcon,
} from "lucide-react";
-import React from "react";
+import type React from "react";
import { Button } from "../ui/button";
-import { PackageInstallationStatus } from "@/core/kernel/messages";
+import type { PackageInstallationStatus } from "@/core/kernel/messages";
import { logNever } from "@/utils/assertNever";
import { useUserConfig } from "@/core/config/config";
-import { isPyodide } from "@/core/pyodide/utils";
+import { isWasm } from "@/core/wasm/utils";
import {
- PackageManagerName,
+ type PackageManagerName,
PackageManagerNames,
} from "../../core/config/config-schema";
import { Logger } from "@/utils/Logger";
@@ -94,7 +97,7 @@ export const PackageAlert: React.FC = (props) => {
clearPackageAlert={() => clearPackageAlert(packageAlert.id)}
/>
- {isPyodide() ? null : (
+ {isWasm() ? null : (
<>
<span className="px-2 text-sm">with</span>{" "}
<PackageManagerForm />
diff --git a/frontend/src/components/editor/renderers/CellArray.tsx b/frontend/src/components/editor/renderers/CellArray.tsx
index 7c2a53f2ee..2bd424be54 100644
--- a/frontend/src/components/editor/renderers/CellArray.tsx
+++ b/frontend/src/components/editor/renderers/CellArray.tsx
@@ -41,7 +41,7 @@ import { MarkdownLanguageAdapter } from "@/core/codemirror/language/markdown";
import { capabilitiesAtom } from "@/core/config/capabilities";
import { Tooltip } from "@/components/ui/tooltip";
import { Kbd } from "@/components/ui/kbd";
-import { isPyodide } from "@/core/pyodide/utils";
+import { isWasm } from "@/core/wasm/utils";
interface CellArrayProps {
notebook: NotebookState;
@@ -208,7 +208,7 @@ const AddCellButtons: React.FC = () => {
<SquareMIcon className="mr-2 size-4 flex-shrink-0" />
Markdown
</Button>
- {!isPyodide() && (
+ {!isWasm() && (
<Tooltip
content={
sqlCapabilities ? null : (
diff --git a/frontend/src/components/editor/renderers/layout-select.tsx b/frontend/src/components/editor/renderers/layout-select.tsx
index 20b219fb58..8e94cc4ca0 100644
--- a/frontend/src/components/editor/renderers/layout-select.tsx
+++ b/frontend/src/components/editor/renderers/layout-select.tsx
@@ -1,5 +1,5 @@
/* Copyright 2024 Marimo. All rights reserved. */
-import React from "react";
+import type React from "react";
import {
Select,
SelectContent,
@@ -9,24 +9,26 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
-import { LayoutType } from "./types";
+import type { LayoutType } from "./types";
import {
SquareIcon,
Grid3x3Icon,
ListIcon,
PresentationIcon,
} from "lucide-react";
-import { isPyodide } from "@/core/pyodide/utils";
+import { isWasm } from "@/core/wasm/utils";
import { useLayoutActions, useLayoutState } from "@/core/layout/layout";
import { logNever } from "@/utils/assertNever";
+import { getFeatureFlag } from "@/core/config/feature-flag";
export const LayoutSelect: React.FC = () => {
const { selectedLayout } = useLayoutState();
const { setLayoutView } = useLayoutActions();
const layouts: LayoutType[] = ["vertical", "grid", "slides"];
- // Layouts are not supported in Pyodide
- if (isPyodide()) {
+ // Layouts are not supported in WASM mode by default,
+ // unless the feature flag is enabled
+ if (isWasm() && !getFeatureFlag("wasm_layouts")) {
return null;
}
diff --git a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx
index 889a55e209..c7456cfb2f 100644
--- a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx
+++ b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx
@@ -1,13 +1,14 @@
/* Copyright 2024 Marimo. All rights reserved. */
-import React, { memo, useRef, useState } from "react";
-import { CellRuntimeState } from "@/core/cells/types";
-import { CellId, HTMLCellId } from "@/core/cells/ids";
+import type React from "react";
+import { memo, useRef, useState } from "react";
+import type { CellRuntimeState } from "@/core/cells/types";
+import { type CellId, HTMLCellId } from "@/core/cells/ids";
import { OutputArea } from "@/components/editor/Output";
-import { ICellRendererPlugin, ICellRendererProps } from "../types";
+import type { ICellRendererPlugin, ICellRendererProps } from "../types";
import { VerticalLayoutWrapper } from "./vertical-layout-wrapper";
import { z } from "zod";
import { useDelayVisibility } from "./useDelayVisibility";
-import { AppMode, kioskModeAtom } from "@/core/mode";
+import { type AppMode, kioskModeAtom } from "@/core/mode";
import { ReadonlyPythonCode } from "@/components/editor/code/readonly-python-code";
import {
ChevronDown,
@@ -29,8 +30,8 @@ import {
} from "@/components/ui/dropdown-menu";
import { downloadHTMLAsImage } from "@/utils/download";
import { downloadAsHTML } from "@/core/static/download-html";
-import { isPyodide } from "@/core/pyodide/utils";
-import { CellConfig } from "@/core/network/types";
+import { isWasm } from "@/core/wasm/utils";
+import type { CellConfig } from "@/core/network/types";
import { useAtomValue } from "jotai";
type VerticalLayout = null;
@@ -47,9 +48,9 @@ const VerticalLayoutRenderer: React.FC<VerticalLayoutProps> = ({
const urlParams = new URLSearchParams(window.location.search);
const showCodeDefault = urlParams.get("show-code");
const [showCode, setShowCode] = useState(() => {
- // Default to showing code if the notebook is static
+ // Default to showing code if the notebook is static or wasm
return showCodeDefault === null
- ? isStaticNotebook() || isPyodide()
+ ? isStaticNotebook() || isWasm()
: showCodeDefault === "true";
});
diff --git a/frontend/src/components/static-html/static-banner.tsx b/frontend/src/components/static-html/static-banner.tsx
index 4d7352766d..112dcba6c9 100644
--- a/frontend/src/components/static-html/static-banner.tsx
+++ b/frontend/src/components/static-html/static-banner.tsx
@@ -3,7 +3,7 @@
/* eslint-disable react/jsx-no-target-blank */
import { isStaticNotebook } from "@/core/static/static-state";
-import React from "react";
+import type React from "react";
import { Button } from "../ui/button";
import { toast } from "../ui/use-toast";
import { getMarimoCode } from "@/core/dom/marimo-tag";
@@ -18,7 +18,7 @@ import {
DialogTrigger,
} from "../ui/dialog";
import { CopyIcon, DownloadIcon } from "lucide-react";
-import { createShareableLink } from "@/core/pyodide/share";
+import { createShareableLink } from "@/core/wasm/share";
export const StaticBanner: React.FC = () => {
if (!isStaticNotebook()) {
@@ -38,6 +38,7 @@ export const StaticBanner: React.FC = () => {
href="https://github.com/marimo-team/marimo"
target="_blank"
className="underline"
+ rel="noreferrer"
>
marimo
</a>
@@ -82,6 +83,7 @@ const StaticBannerDialog = ({ code }: { code: string }) => {
href="https://github.com/marimo-team/marimo"
target="_blank"
className="text-link hover:underline"
+ rel="noreferrer"
>
marimo
</a>
@@ -109,6 +111,7 @@ const StaticBannerDialog = ({ code }: { code: string }) => {
href={wasmLink}
target="_blank"
className="text-link hover:underline"
+ rel="noreferrer"
>
{wasmLink.slice(0, 40)}...
</a>
diff --git a/frontend/src/core/config/feature-flag.ts b/frontend/src/core/config/feature-flag.ts
index 80aaf0cbf1..eab29159bf 100644
--- a/frontend/src/core/config/feature-flag.ts
+++ b/frontend/src/core/config/feature-flag.ts
@@ -1,18 +1,20 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { repl } from "@/utils/repl";
-import { UserConfig } from "vite";
+import type { UserConfig } from "vite";
import { saveUserConfig } from "../network/requests";
import { getUserConfig } from "./config";
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ExperimentalFeatures {
- // Add new feature flags here
markdown: boolean;
+ wasm_layouts: boolean;
+ // Add new feature flags here
}
const defaultValues: ExperimentalFeatures = {
markdown: true,
+ wasm_layouts: false,
};
export function getFeatureFlag<T extends keyof ExperimentalFeatures>(
diff --git a/frontend/src/core/dom/htmlUtils.ts b/frontend/src/core/dom/htmlUtils.ts
index 53df80742b..9772772551 100644
--- a/frontend/src/core/dom/htmlUtils.ts
+++ b/frontend/src/core/dom/htmlUtils.ts
@@ -4,8 +4,8 @@ import type { UIElementRegistry } from "./uiregistry";
import { jsonParseWithSpecialChar } from "@/utils/json/json-parser";
import { Objects } from "@/utils/objects";
import { UIElementId } from "../cells/ids";
-import { isPyodide } from "../pyodide/utils";
-import { PyodideRouter } from "../pyodide/router";
+import { isWasm } from "../wasm/utils";
+import { PyodideRouter } from "../wasm/router";
/**
* Parse an attribute value as JSON.
@@ -50,8 +50,8 @@ export function serializeInitialValue(value: unknown) {
}
export function getFilenameFromDOM() {
- // If we are running in Pyodide, we can get the filename from the URL
- if (isPyodide()) {
+ // If we are running in WASM, we can get the filename from the URL
+ if (isWasm()) {
const filename = PyodideRouter.getFilename();
if (filename) {
return filename;
diff --git a/frontend/src/core/islands/bridge.ts b/frontend/src/core/islands/bridge.ts
index 39f60115e2..67b781668c 100644
--- a/frontend/src/core/islands/bridge.ts
+++ b/frontend/src/core/islands/bridge.ts
@@ -1,11 +1,11 @@
/* Copyright 2024 Marimo. All rights reserved. */
/* eslint-disable @typescript-eslint/no-explicit-any */
-import { EditRequests, RunRequests } from "../network/types";
+import type { EditRequests, RunRequests } from "../network/types";
import { Deferred } from "@/utils/Deferred";
import { getMarimoVersion } from "../dom/marimo-tag";
-import { getWorkerRPC } from "@/core/pyodide/rpc";
-import { OperationMessage } from "../kernel/messages";
-import { JsonString } from "@/utils/json/base64";
+import { getWorkerRPC } from "@/core/wasm/rpc";
+import type { OperationMessage } from "../kernel/messages";
+import type { JsonString } from "@/utils/json/base64";
import { throwNotImplemented } from "@/utils/functions";
import type { WorkerSchema } from "./worker/worker";
import workerUrl from "./worker/worker.tsx?worker&url";
diff --git a/frontend/src/core/islands/worker/controller.ts b/frontend/src/core/islands/worker/controller.ts
index fb122fb771..6fc2858ebe 100644
--- a/frontend/src/core/islands/worker/controller.ts
+++ b/frontend/src/core/islands/worker/controller.ts
@@ -2,11 +2,11 @@
import type { PyodideInterface } from "pyodide";
import { Logger } from "../../../utils/Logger";
import { defaultUserConfig } from "@/core/config/config-schema";
-import { SerializedBridge } from "@/core/pyodide/worker/types";
-import { OperationMessage } from "@/core/kernel/messages";
-import { JsonString } from "@/utils/json/base64";
-import { DefaultWasmController } from "@/core/pyodide/worker/bootstrap";
-import { WasmFileSystem } from "@/core/pyodide/worker/fs";
+import type { SerializedBridge } from "@/core/wasm/worker/types";
+import type { OperationMessage } from "@/core/kernel/messages";
+import type { JsonString } from "@/utils/json/base64";
+import { DefaultWasmController } from "@/core/wasm/worker/bootstrap";
+import { WasmFileSystem } from "@/core/wasm/worker/fs";
export class ReadonlyWasmController extends DefaultWasmController {
override async bootstrap(opts: {
diff --git a/frontend/src/core/islands/worker/worker.tsx b/frontend/src/core/islands/worker/worker.tsx
index 96d3836d78..a84d4d182a 100644
--- a/frontend/src/core/islands/worker/worker.tsx
+++ b/frontend/src/core/islands/worker/worker.tsx
@@ -10,18 +10,18 @@ import {
type RPCSchema,
} from "rpc-anywhere";
import { invariant } from "../../../utils/invariant";
-import { ParentSchema } from "@/core/pyodide/rpc";
-import { TRANSPORT_ID } from "@/core/pyodide/worker/constants";
-import { MessageBuffer } from "@/core/pyodide/worker/message-buffer";
-import { SerializedBridge, RawBridge } from "@/core/pyodide/worker/types";
+import type { ParentSchema } from "@/core/wasm/rpc";
+import { TRANSPORT_ID } from "@/core/wasm/worker/constants";
+import { MessageBuffer } from "@/core/wasm/worker/message-buffer";
+import type { SerializedBridge, RawBridge } from "@/core/wasm/worker/types";
import { ReadonlyWasmController } from "./controller";
-import { OperationMessage } from "@/core/kernel/messages";
-import { JsonString } from "@/utils/json/base64";
+import type { OperationMessage } from "@/core/kernel/messages";
+import type { JsonString } from "@/utils/json/base64";
import { Logger } from "@/utils/Logger";
import {
getPyodideVersion,
importPyodide,
-} from "@/core/pyodide/worker/getPyodideVersion";
+} from "@/core/wasm/worker/getPyodideVersion";
declare const self: Window & {
pyodide: PyodideInterface;
diff --git a/frontend/src/core/network/requests.ts b/frontend/src/core/network/requests.ts
index 9e2e4c4bb1..1e71a35862 100644
--- a/frontend/src/core/network/requests.ts
+++ b/frontend/src/core/network/requests.ts
@@ -1,13 +1,13 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { IslandsPyodideBridge } from "../islands/bridge";
import { isIslands } from "../islands/utils";
-import { PyodideBridge } from "../pyodide/bridge";
-import { isPyodide } from "../pyodide/utils";
+import { PyodideBridge } from "../wasm/bridge";
+import { isWasm } from "../wasm/utils";
import { isStaticNotebook } from "../static/static-state";
import { createNetworkRequests } from "./requests-network";
import { createStaticRequests } from "./requests-static";
import { createErrorToastingRequests } from "./requests-toasting";
-import { EditRequests, RunRequests } from "./types";
+import type { EditRequests, RunRequests } from "./types";
function getRequest(): EditRequests & RunRequests {
if (isIslands()) {
@@ -16,7 +16,7 @@ function getRequest(): EditRequests & RunRequests {
return IslandsPyodideBridge.INSTANCE;
}
- const base = isPyodide()
+ const base = isWasm()
? PyodideBridge.INSTANCE
: isStaticNotebook()
? createStaticRequests()
diff --git a/frontend/src/core/vscode/vscode-bindings.ts b/frontend/src/core/vscode/vscode-bindings.ts
index 30f5197e13..bc6679ab00 100644
--- a/frontend/src/core/vscode/vscode-bindings.ts
+++ b/frontend/src/core/vscode/vscode-bindings.ts
@@ -1,7 +1,7 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { Logger } from "@/utils/Logger";
-import { isPyodide } from "../pyodide/utils";
+import { isWasm } from "../wasm/utils";
import { isPlatformMac } from "../hotkeys/shortcuts";
export const isEmbedded =
@@ -12,7 +12,7 @@ export const isEmbedded =
// we have to dispatch keyboard events in the parent window.
// See https://github.com/microsoft/vscode/issues/65452#issuecomment-586036474
export function maybeRegisterVSCodeBindings() {
- if (!isEmbedded || isPyodide()) {
+ if (!isEmbedded || isWasm()) {
return;
}
Logger.log("Registering VS Code bindings");
diff --git a/frontend/src/core/pyodide/PyodideLoader.tsx b/frontend/src/core/wasm/PyodideLoader.tsx
similarity index 85%
rename from frontend/src/core/pyodide/PyodideLoader.tsx
rename to frontend/src/core/wasm/PyodideLoader.tsx
index 38ffa1ff51..a2f0031c7c 100644
--- a/frontend/src/core/pyodide/PyodideLoader.tsx
+++ b/frontend/src/core/wasm/PyodideLoader.tsx
@@ -1,7 +1,8 @@
/* Copyright 2024 Marimo. All rights reserved. */
-import React, { PropsWithChildren } from "react";
+import type React from "react";
+import type { PropsWithChildren } from "react";
import { useAsyncData } from "@/hooks/useAsyncData";
-import { isPyodide } from "./utils";
+import { isWasm } from "./utils";
import { PyodideBridge } from "./bridge";
import { LargeSpinner } from "@/components/icons/large-spinner";
@@ -9,7 +10,7 @@ import { LargeSpinner } from "@/components/icons/large-spinner";
* HOC to load Pyodide before rendering children, if necessary.
*/
export const PyodideLoader: React.FC<PropsWithChildren> = ({ children }) => {
- if (!isPyodide()) {
+ if (!isWasm()) {
return children;
}
diff --git a/frontend/src/core/pyodide/__tests__/router.test.ts b/frontend/src/core/wasm/__tests__/router.test.ts
similarity index 100%
rename from frontend/src/core/pyodide/__tests__/router.test.ts
rename to frontend/src/core/wasm/__tests__/router.test.ts
diff --git a/frontend/src/core/pyodide/__tests__/share.test.ts b/frontend/src/core/wasm/__tests__/share.test.ts
similarity index 100%
rename from frontend/src/core/pyodide/__tests__/share.test.ts
rename to frontend/src/core/wasm/__tests__/share.test.ts
diff --git a/frontend/src/core/pyodide/__tests__/store.test.ts b/frontend/src/core/wasm/__tests__/store.test.ts
similarity index 100%
rename from frontend/src/core/pyodide/__tests__/store.test.ts
rename to frontend/src/core/wasm/__tests__/store.test.ts
diff --git a/frontend/src/core/pyodide/bridge.ts b/frontend/src/core/wasm/bridge.ts
similarity index 88%
rename from frontend/src/core/pyodide/bridge.ts
rename to frontend/src/core/wasm/bridge.ts
index ea7810f630..13b293eae3 100644
--- a/frontend/src/core/pyodide/bridge.ts
+++ b/frontend/src/core/wasm/bridge.ts
@@ -18,7 +18,7 @@ import type {
} from "../network/types";
import type { IReconnectingWebSocket } from "../websocket/types";
import { fallbackFileStore, notebookFileStore } from "./store";
-import { isPyodide } from "./utils";
+import { isWasm } from "./utils";
import { Deferred } from "@/utils/Deferred";
import { createShareableLink } from "./share";
import { PyodideRouter } from "./router";
@@ -52,59 +52,61 @@ export class PyodideBridge implements RunRequests, EditRequests {
public initialized = new Deferred<void>();
private constructor() {
- if (isPyodide()) {
- // Create a worker
- const worker = new Worker(
- // eslint-disable-next-line unicorn/relative-url-style
- new URL("./worker/worker.ts", import.meta.url),
- {
- type: "module",
- // Pass the version to the worker
- /* @vite-ignore */
- name: getMarimoVersion(),
- },
- );
+ if (!isWasm()) {
+ return;
+ }
- // Create save worker
- const saveWorker = new Worker(
- // eslint-disable-next-line unicorn/relative-url-style
- new URL("./worker/save-worker.ts", import.meta.url),
- {
- type: "module",
- // Pass the version
- /* @vite-ignore */
- name: getMarimoVersion(),
- },
- );
+ // Create a worker
+ const worker = new Worker(
+ // eslint-disable-next-line unicorn/relative-url-style
+ new URL("./worker/worker.ts", import.meta.url),
+ {
+ type: "module",
+ // Pass the version to the worker
+ /* @vite-ignore */
+ name: getMarimoVersion(),
+ },
+ );
- // Create the RPC
- this.rpc = getWorkerRPC<WorkerSchema>(worker);
- this.saveRpc = getWorkerRPC<SaveWorkerSchema>(saveWorker);
+ // Create save worker
+ const saveWorker = new Worker(
+ // eslint-disable-next-line unicorn/relative-url-style
+ new URL("./worker/save-worker.ts", import.meta.url),
+ {
+ type: "module",
+ // Pass the version
+ /* @vite-ignore */
+ name: getMarimoVersion(),
+ },
+ );
- // Listeners
- this.rpc.addMessageListener("ready", () => {
- this.startSession();
- });
- this.rpc.addMessageListener("initialized", () => {
- this.setInterruptBuffer();
- this.initialized.resolve();
- });
- this.rpc.addMessageListener("initializedError", ({ error }) => {
- // If already resolved, show a toast
- if (this.initialized.status === "resolved") {
- Logger.error(error);
- toast({
- title: "Error initializing",
- description: error,
- variant: "danger",
- });
- }
- this.initialized.reject(new Error(error));
- });
- this.rpc.addMessageListener("kernelMessage", ({ message }) => {
- this.messageConsumer?.(message);
- });
- }
+ // Create the RPC
+ this.rpc = getWorkerRPC<WorkerSchema>(worker);
+ this.saveRpc = getWorkerRPC<SaveWorkerSchema>(saveWorker);
+
+ // Listeners
+ this.rpc.addMessageListener("ready", () => {
+ this.startSession();
+ });
+ this.rpc.addMessageListener("initialized", () => {
+ this.setInterruptBuffer();
+ this.initialized.resolve();
+ });
+ this.rpc.addMessageListener("initializedError", ({ error }) => {
+ // If already resolved, show a toast
+ if (this.initialized.status === "resolved") {
+ Logger.error(error);
+ toast({
+ title: "Error initializing",
+ description: error,
+ variant: "danger",
+ });
+ }
+ this.initialized.reject(new Error(error));
+ });
+ this.rpc.addMessageListener("kernelMessage", ({ message }) => {
+ this.messageConsumer?.(message);
+ });
}
private async startSession() {
diff --git a/frontend/src/core/pyodide/router.ts b/frontend/src/core/wasm/router.ts
similarity index 100%
rename from frontend/src/core/pyodide/router.ts
rename to frontend/src/core/wasm/router.ts
diff --git a/frontend/src/core/pyodide/rpc.ts b/frontend/src/core/wasm/rpc.ts
similarity index 100%
rename from frontend/src/core/pyodide/rpc.ts
rename to frontend/src/core/wasm/rpc.ts
diff --git a/frontend/src/core/pyodide/share.ts b/frontend/src/core/wasm/share.ts
similarity index 100%
rename from frontend/src/core/pyodide/share.ts
rename to frontend/src/core/wasm/share.ts
diff --git a/frontend/src/core/pyodide/store.ts b/frontend/src/core/wasm/store.ts
similarity index 100%
rename from frontend/src/core/pyodide/store.ts
rename to frontend/src/core/wasm/store.ts
diff --git a/frontend/src/core/pyodide/utils.ts b/frontend/src/core/wasm/utils.ts
similarity index 84%
rename from frontend/src/core/pyodide/utils.ts
rename to frontend/src/core/wasm/utils.ts
index 93549753f6..5cb8bebf95 100644
--- a/frontend/src/core/pyodide/utils.ts
+++ b/frontend/src/core/wasm/utils.ts
@@ -3,6 +3,6 @@
/**
* Whether the current environment is Pyodide/WASM
*/
-export function isPyodide() {
+export function isWasm() {
return document.querySelector("marimo-wasm") !== null;
}
diff --git a/frontend/src/core/pyodide/worker/bootstrap.ts b/frontend/src/core/wasm/worker/bootstrap.ts
similarity index 100%
rename from frontend/src/core/pyodide/worker/bootstrap.ts
rename to frontend/src/core/wasm/worker/bootstrap.ts
diff --git a/frontend/src/core/pyodide/worker/constants.ts b/frontend/src/core/wasm/worker/constants.ts
similarity index 100%
rename from frontend/src/core/pyodide/worker/constants.ts
rename to frontend/src/core/wasm/worker/constants.ts
diff --git a/frontend/src/core/pyodide/worker/fs.ts b/frontend/src/core/wasm/worker/fs.ts
similarity index 100%
rename from frontend/src/core/pyodide/worker/fs.ts
rename to frontend/src/core/wasm/worker/fs.ts
diff --git a/frontend/src/core/pyodide/worker/getController.ts b/frontend/src/core/wasm/worker/getController.ts
similarity index 100%
rename from frontend/src/core/pyodide/worker/getController.ts
rename to frontend/src/core/wasm/worker/getController.ts
diff --git a/frontend/src/core/pyodide/worker/getFS.ts b/frontend/src/core/wasm/worker/getFS.ts
similarity index 100%
rename from frontend/src/core/pyodide/worker/getFS.ts
rename to frontend/src/core/wasm/worker/getFS.ts
diff --git a/frontend/src/core/pyodide/worker/getMarimoWheel.ts b/frontend/src/core/wasm/worker/getMarimoWheel.ts
similarity index 100%
rename from frontend/src/core/pyodide/worker/getMarimoWheel.ts
rename to frontend/src/core/wasm/worker/getMarimoWheel.ts
diff --git a/frontend/src/core/pyodide/worker/getPyodideVersion.ts b/frontend/src/core/wasm/worker/getPyodideVersion.ts
similarity index 100%
rename from frontend/src/core/pyodide/worker/getPyodideVersion.ts
rename to frontend/src/core/wasm/worker/getPyodideVersion.ts
diff --git a/frontend/src/core/pyodide/worker/message-buffer.ts b/frontend/src/core/wasm/worker/message-buffer.ts
similarity index 100%
rename from frontend/src/core/pyodide/worker/message-buffer.ts
rename to frontend/src/core/wasm/worker/message-buffer.ts
diff --git a/frontend/src/core/pyodide/worker/save-worker.ts b/frontend/src/core/wasm/worker/save-worker.ts
similarity index 100%
rename from frontend/src/core/pyodide/worker/save-worker.ts
rename to frontend/src/core/wasm/worker/save-worker.ts
diff --git a/frontend/src/core/pyodide/worker/tracer.ts b/frontend/src/core/wasm/worker/tracer.ts
similarity index 100%
rename from frontend/src/core/pyodide/worker/tracer.ts
rename to frontend/src/core/wasm/worker/tracer.ts
diff --git a/frontend/src/core/pyodide/worker/types.ts b/frontend/src/core/wasm/worker/types.ts
similarity index 100%
rename from frontend/src/core/pyodide/worker/types.ts
rename to frontend/src/core/wasm/worker/types.ts
diff --git a/frontend/src/core/pyodide/worker/worker.ts b/frontend/src/core/wasm/worker/worker.ts
similarity index 100%
rename from frontend/src/core/pyodide/worker/worker.ts
rename to frontend/src/core/wasm/worker/worker.ts
diff --git a/frontend/src/core/websocket/useWebSocket.tsx b/frontend/src/core/websocket/useWebSocket.tsx
index cb42703c05..5dee7275fb 100644
--- a/frontend/src/core/websocket/useWebSocket.tsx
+++ b/frontend/src/core/websocket/useWebSocket.tsx
@@ -3,8 +3,8 @@ import { useEffect, useState } from "react";
import ReconnectingWebSocket from "partysocket/ws";
import type { IReconnectingWebSocket } from "./types";
import { StaticWebsocket } from "./StaticWebsocket";
-import { isPyodide } from "../pyodide/utils";
-import { PyodideBridge, PyodideWebsocket } from "../pyodide/bridge";
+import { isWasm } from "../wasm/utils";
+import { PyodideBridge, PyodideWebsocket } from "../wasm/bridge";
import { Logger } from "@/utils/Logger";
interface UseWebSocketOptions {
@@ -26,7 +26,7 @@ export function useWebSocket(options: UseWebSocketOptions) {
// eslint-disable-next-line react/hook-use-state
const [ws] = useState<IReconnectingWebSocket>(() => {
- const socket: IReconnectingWebSocket = isPyodide()
+ const socket: IReconnectingWebSocket = isWasm()
? new PyodideWebsocket(PyodideBridge.INSTANCE)
: options.static
? new StaticWebsocket()