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.

dev: Use islands as local asset server (#5436)

Dylan Madisetti189667475406
diff --git a/frontend/islands/vite.config.mts b/frontend/islands/vite.config.mts
index 00f521e049..6bdb5b529a 100644
--- a/frontend/islands/vite.config.mts
+++ b/frontend/islands/vite.config.mts
@@ -40,7 +40,6 @@ export default defineConfig({
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
- "import.meta.env.VITE_MARIMO_ISLANDS": JSON.stringify(true),
// Precedence: VITE_MARIMO_VERSION > package.json version > "latest"
"import.meta.env.VITE_MARIMO_VERSION": process.env.VITE_MARIMO_VERSION
? JSON.stringify(process.env.VITE_MARIMO_VERSION)
diff --git a/frontend/package.json b/frontend/package.json
index 8fb15abbe1..cfb83c66f9 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -172,6 +172,7 @@
"lint:stylelint": "stylelint src/**/*.css --fix",
"format": "biome format --write .",
"preview": "vite preview",
+ "dev:quarto": "VITE_MARIMO_ISLANDS=true vite",
"dev:islands": "cross-env VITE_MARIMO_ISLANDS=true vite --config islands/vite.config.mts",
"build:islands": "cross-env VITE_MARIMO_ISLANDS=true vite --config islands/vite.config.mts build",
"preview:islands": "cross-env VITE_MARIMO_VERSION='0.4.6' VITE_MARIMO_ISLANDS=true vite --config islands/vite.config.mts build",
diff --git a/frontend/src/core/dom/htmlUtils.ts b/frontend/src/core/dom/htmlUtils.ts
index 43bc216fab..dbb92c2da9 100644
--- a/frontend/src/core/dom/htmlUtils.ts
+++ b/frontend/src/core/dom/htmlUtils.ts
@@ -3,6 +3,7 @@ import { assertExists } from "@/utils/assertExists";
import { jsonParseWithSpecialChar } from "@/utils/json/json-parser";
import { Objects } from "@/utils/objects";
import { UIElementId } from "../cells/ids";
+import { isIslands } from "../islands/utils";
import { PyodideRouter } from "../wasm/router";
import { isWasm } from "../wasm/utils";
import type { UIElementRegistry } from "./uiregistry";
@@ -50,6 +51,10 @@ export function serializeInitialValue(value: unknown) {
}
export function getFilenameFromDOM() {
+ // If running in Islands, just return the window title.
+ if (isIslands()) {
+ return document.title || null;
+ }
// If we are running in WASM, we can get the filename from the URL
if (isWasm()) {
const filename = PyodideRouter.getFilename();
diff --git a/frontend/src/core/islands/utils.ts b/frontend/src/core/islands/utils.ts
index 831bada8c2..2dfc72ee5c 100644
--- a/frontend/src/core/islands/utils.ts
+++ b/frontend/src/core/islands/utils.ts
@@ -1,5 +1,5 @@
/* Copyright 2024 Marimo. All rights reserved. */
export function isIslands() {
- return import.meta.env.VITE_MARIMO_ISLANDS === true;
+ return import.meta.env.VITE_MARIMO_ISLANDS === "true";
}
diff --git a/frontend/src/core/websocket/StaticWebsocket.ts b/frontend/src/core/websocket/StaticWebsocket.ts
index 981a23e297..c838c3f26a 100644
--- a/frontend/src/core/websocket/StaticWebsocket.ts
+++ b/frontend/src/core/websocket/StaticWebsocket.ts
@@ -1,4 +1,6 @@
/* Copyright 2024 Marimo. All rights reserved. */
+
+import { isIslands } from "@/core/islands/utils";
import type { IReconnectingWebSocket } from "./types";
export class StaticWebsocket implements IReconnectingWebSocket {
@@ -24,7 +26,7 @@ export class StaticWebsocket implements IReconnectingWebSocket {
): void {
// Normally this would be a no-op in a mock, but we simulate a synthetic "open" event
// to mimic the WebSocket transitioning from CONNECTING to OPEN state.
- if (type === "open") {
+ if (type === "open" && !isIslands()) {
queueMicrotask(() => {
callback(new Event("open"));
});