Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/__mocks__/executions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export const MockExecutions = {
} satisfies NotebookReplica;
store.set(activeNotebookReplicaAtom, replica);
// Selector tests share current inputs; frame scheduling is tested separately.
store.set(activeNotebookFrameAtom, replica);
store.set(activeNotebookFrameAtom, { ...replica, flush: () => undefined });
return replica;
},
};
24 changes: 3 additions & 21 deletions frontend/src/components/editor/Output.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright 2026 Marimo. All rights reserved. */
import React, { memo, Suspense, useMemo, useRef } from "react";
import React, { memo, useMemo, useRef } from "react";
import { type CellId, CellOutputId } from "@/core/cells/ids";
import type { CellOutput } from "@/core/executions";
import type { OutputMessage } from "@/core/kernel/messages";
Expand All @@ -21,7 +21,6 @@ import {
ExpandIcon,
ShrinkIcon,
} from "lucide-react";
import { tooltipHandler } from "@/components/charts/tooltip";
import { useExpandedOutput } from "@/core/cells/outputs";
import { viewStateAtom } from "@/core/mode";
import { useEventListener } from "@/hooks/useEventListener";
Expand All @@ -30,15 +29,12 @@ import { useOverflowDetection } from "@/hooks/useOverflowDetection";
import { renderHTML } from "@/plugins/core/RenderHTML";
import { Banner } from "@/plugins/impl/common/error-banner";
import type { TopLevelFacetedUnitSpec } from "@/plugins/impl/data-explorer/queries/types";
import { getContainerWidth } from "@/plugins/impl/vega/utils";
import { useTheme } from "@/theme/useTheme";
import { Events } from "@/utils/events";
import { invariant } from "@/utils/invariant";
import { Logger } from "@/utils/Logger";
import { processMimeBundle } from "@/utils/mime-types";
import { Objects } from "@/utils/objects";
import { LazyVegaEmbed } from "../charts/lazy";
import { ChartLoadingState } from "../data-table/charts/components/chart-states";
import { VegaOutput } from "./output/VegaOutput";
import { Button } from "../ui/button";
import { useIsFullScreen } from "../ui/fullscreen";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs";
Expand Down Expand Up @@ -85,7 +81,6 @@ export const OutputRenderer: React.FC<{
metadata,
renderFallback,
} = props;
const { theme } = useTheme();

// Memoize parsing the json data
const parsedJsonData = useMemo(() => {
Expand Down Expand Up @@ -214,20 +209,7 @@ export const OutputRenderer: React.FC<{
case "application/vnd.vega.v5+json":
case "application/vnd.vegalite.v6+json":
case "application/vnd.vega.v6+json":
return (
<Suspense fallback={<ChartLoadingState />}>
<LazyVegaEmbed
spec={parsedJsonData as TopLevelFacetedUnitSpec}
data-container-width={getContainerWidth(parsedJsonData)}
options={{
theme: theme === "dark" ? "dark" : undefined,
mode: "vega-lite",
tooltip: tooltipHandler.call,
renderer: "canvas",
}}
/>
</Suspense>
);
return <VegaOutput spec={parsedJsonData as TopLevelFacetedUnitSpec} />;
case "application/vnd.marimo+mimebundle":
return (
<MimeBundleOutputRenderer
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/components/editor/output/VegaOutput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Copyright 2026 Marimo. All rights reserved. */

import { Suspense, useState } from "react";
import type { VegaEmbedProps } from "react-vega";
import { LazyVegaEmbed } from "@/components/charts/lazy";
import { tooltipHandler } from "@/components/charts/tooltip";
import { ChartLoadingState } from "@/components/data-table/charts/components/chart-states";
import { useDeepCompareMemoize } from "@/hooks/useDeepCompareMemoize";
import type { TopLevelFacetedUnitSpec } from "@/plugins/impl/data-explorer/queries/types";
import { getContainerWidth } from "@/plugins/impl/vega/utils";
import { useTheme } from "@/theme/useTheme";

export function VegaOutput({ spec }: { spec: TopLevelFacetedUnitSpec }) {
const { theme } = useTheme();
const embed = useDeepCompareMemoize({
spec,
options: {
theme: theme === "dark" ? "dark" : undefined,
mode: "vega-lite",
tooltip: tooltipHandler.call,
renderer: "canvas",
},
} satisfies VegaEmbedProps);
const [rendered, setRendered] = useState<typeof embed>();
return (
<Suspense fallback={<ChartLoadingState />}>
<LazyVegaEmbed
{...embed}
onEmbed={() => setRendered(embed)}
data-marimo-vega-ready={rendered === embed || undefined}
data-container-width={getContainerWidth(spec)}
/>
</Suspense>
);
}
2 changes: 0 additions & 2 deletions frontend/src/core/executions/__tests__/atoms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
cellExecutionInputsAtom,
cellExecutionAtom,
cellOutputAtom,
cellOutputsAtom,
scratchOutputAtom,
cellOutputInputsAtom,
cellOutlineAtom,
Expand Down Expand Up @@ -264,7 +263,6 @@ it.each([25, 500])(
}
onTestFinished(() => releaseCellOutputAtoms(id));
}
onTestFinished(store.sub(cellOutputsAtom, () => undefined));
onTestFinished(store.sub(scratchOutputAtom, () => undefined));
scratchView.mockClear();
executionView.mockClear();
Expand Down
69 changes: 33 additions & 36 deletions frontend/src/core/executions/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import {
ConnectionState,
type Executions,
type NotebookReplica,
type ReplicaFrame,
type FrameSource,
type Results,
} from "@/core/notebook/replica";
import { atomWithSelectedInputs } from "@/core/state/atom-with-selected-inputs";
import { arrayShallowEquals } from "@/utils/arrays";
import {
activeNotebookReplicaAtom,
activeNotebookFrameAtom,
Expand All @@ -26,7 +25,7 @@ import { type CellFreshnessInputs, freshnessOf } from "./freshness";
import {
type CellOutputInputs,
type ClearedOutput,
type CellOutput,
cellOutputsView,
resultOutput,
shownCellExecution,
shownExecution,
Expand Down Expand Up @@ -112,7 +111,7 @@ function current<T>(marks: Marks<T>, shown: ShownNotebook | null, empty: T): T {
: empty;
}

type ReplicaSource = Atom<ReplicaFrame | null>;
type ReplicaSource = Atom<FrameSource | null>;

function createShownNotebookAtom(source: ReplicaSource) {
return atom((get): ShownNotebook | null => {
Expand Down Expand Up @@ -250,41 +249,39 @@ const displayedNotebookAtom = atom((get): ShownNotebook | null => {
};
});

/** What every cell's output derives from. Pair with `cellOutputView`. */
export const cellOutputInputsAtom = atom((get): CellOutputInputs => {
const frame = get(activeNotebookFrameAtom);
return {
executions: frame === null ? NO_EXECUTIONS : get(frame.executionsAtom),
results: frame === null ? NO_RESULTS : get(frame.resultsAtom),
cleared: current(
get(clearedOutputsAtom),
get(displayedNotebookAtom),
NO_CLEARED,
),
cells:
frame === null ? NO_CELLS : (get(frame.documentAtom)?.cells ?? NO_CELLS),
};
});
function createOutputInputsAtom(
source: ReplicaSource,
notebookAtom: Atom<ShownNotebook | null>,
) {
return atom((get): CellOutputInputs => {
const state = get(source);
return {
executions: state === null ? NO_EXECUTIONS : get(state.executionsAtom),
results: state === null ? NO_RESULTS : get(state.resultsAtom),
cleared: current(get(clearedOutputsAtom), get(notebookAtom), NO_CLEARED),
cells:
state === null
? NO_CELLS
: (get(state.documentAtom)?.cells ?? NO_CELLS),
};
});
}

/** What every cell shows, by cell id. Pair with `cellOutputAtom` for one cell. */
const outputCellIdsAtom = selectAtom(
cellOutputInputsAtom,
(inputs) => [
...new Set([...inputs.results.keys(), ...inputs.executions.latest.keys()]),
],
arrayShallowEquals,
/** What each cell shows in the last published frame. */
export const cellOutputInputsAtom = createOutputInputsAtom(
activeNotebookFrameAtom,
displayedNotebookAtom,
);

export const cellOutputsAtom = atom((get) => {
const outputs = new Map<CellId, CellOutput>();
for (const id of get(outputCellIdsAtom)) {
const output = get(cellOutputAtom(id));
if (output !== null) {
outputs.set(id, output);
}
}
return outputs;
});
const immediateOutputInputsAtom = createOutputInputsAtom(
activeNotebookReplicaAtom,
shownNotebookAtom,
);

/** Read at export time, including output received since the last display frame. */
export const cellOutputsAtom = atom((get) =>
cellOutputsView(get(immediateOutputInputsAtom)),
);

function latestFor(executions: Executions, id: Protocol.CellId) {
const latest = executions.latest.get(id);
Expand Down
Loading
Loading