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: lazy initializing islands again (#2694)
Myles Scolnick177cf2d8b4cd
diff --git a/frontend/src/core/islands/components/web-components.tsx b/frontend/src/core/islands/components/web-components.tsxindex aea1145292..92d9698df0 100644--- a/frontend/src/core/islands/components/web-components.tsx+++ b/frontend/src/core/islands/components/web-components.tsx@@ -11,7 +11,7 @@ import { renderHTML } from "@/plugins/core/RenderHTML";import { TooltipProvider } from "@/components/ui/tooltip";import { ErrorBoundary } from "@/components/editor/boundary/ErrorBoundary";import { UI_ELEMENT_REGISTRY } from "@/core/dom/uiregistry";-import { shouldShowIslandsWarningIndicatorAtom } from "../state";+import { notebookAtom } from "@/core/cells/cells";/*** A custom element that renders the output of a marimo cell@@ -28,16 +28,6 @@ export class MarimoIslandElement extends HTMLElement {constructor() {super();this.classList.add(MarimoIslandElement.styleNamespace);-- // If we warn that islands are still loading, we fade them out.- store.sub(shouldShowIslandsWarningIndicatorAtom, () => {- const loading = store.get(shouldShowIslandsWarningIndicatorAtom);- if (loading) {- this.style.setProperty("opacity", "0.5");- } else {- this.style.removeProperty("opacity");- }- });}get appId(): string {@@ -46,8 +36,13 @@ export class MarimoIslandElement extends HTMLElement {}get cellId(): CellId {- invariant(this.dataset.cellId, "Missing data-cell-id attribute");- return this.dataset.cellId as CellId;+ // Get the cell ID from the code+ invariant(this.dataset.cellIdx, "Missing data-cell-idx attribute");+ const { cellIds } = store.get(notebookAtom);+ const idx = Number.parseInt(this.dataset.cellIdx, 10);+ const cellId = cellIds.inOrderIds.at(idx);+ invariant(cellId, "Missing cell ID");+ return cellId;}get code(): string {diff --git a/frontend/src/core/islands/main.ts b/frontend/src/core/islands/main.tsindex 052a5836ba..eca08cd1a4 100644--- a/frontend/src/core/islands/main.ts+++ b/frontend/src/core/islands/main.ts@@ -59,6 +59,7 @@ export async function initialize() {}// Add 'marimo' class name to all `marimo-island` elements.+ // This makes our styles apply to the islands.for (const island of islands) {island.classList.add(MarimoIslandElement.styleNamespace);}@@ -67,19 +68,22 @@ export async function initialize() {store.set(notebookAtom, (state) => notebookReducer(state, action));});- // Define the custom element for the marimo-island tag.- requestAnimationFrame(() => {- defineCustomElement(MarimoIslandElement.tagName, MarimoIslandElement);- });-// If the user has interacted with the islands before they are initialized,// we show the loading toast.store.sub(shouldShowIslandsWarningIndicatorAtom, () => {const showing = store.get(shouldShowIslandsWarningIndicatorAtom);if (showing) {toastIslandsLoading();+ // For each island, set the opacity to 0.5+ for (const island of islands) {+ island.style.setProperty("opacity", "0.5");+ }} else {dismissIslandsLoadingToast();+ // For each island, remove the opacity+ for (const island of islands) {+ island.style.removeProperty("opacity");+ }}});@@ -110,6 +114,9 @@ export async function initialize() {setCapabilities: Functions.NOOP,onError: Logger.error,});+ // Define the custom element for the marimo-island tag.+ // This comes after initializing since this reads from the store.+ defineCustomElement(MarimoIslandElement.tagName, MarimoIslandElement);return;case "completed-run":return;