@marimo-team/islands 0.26.1-dev112 → 0.26.1-dev118

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/{ErrorBoundary-pNKOBKXw.js → ErrorBoundary-Gr2Kt5kj.js} +1 -1
  2. package/dist/{chat-ui-C9NZA-bk.js → chat-ui-CMKYvKUz.js} +3 -3
  3. package/dist/{code-visibility-B9s3Hl8z.js → code-visibility-BFFe0rT7.js} +2 -2
  4. package/dist/{common-Bn3jx0X6.js → common-7eNIhSN-.js} +4766 -4749
  5. package/dist/{data-grid-overlay-editor-mxwwRaQy.js → data-grid-overlay-editor-B37-1-8n.js} +1 -1
  6. package/dist/{error-entries-1DC4BiYB.js → error-entries-B4LgfizR.js} +759 -749
  7. package/dist/{feedback-button-BrzbnRTT.js → feedback-button-CpQcgVuz.js} +3 -3
  8. package/dist/{formats-Y52bg800.js → formats-CeuXJ_1f.js} +32 -25
  9. package/dist/{glide-data-editor-Cnsv3NcI.js → glide-data-editor-BxTlDHV5.js} +3 -3
  10. package/dist/{globals-BGqfFPx8.js → globals-ljOLdTJr.js} +1 -1
  11. package/dist/{html-to-image-CsvAOgd3.js → html-to-image-CIkwg7mv.js} +1 -1
  12. package/dist/main.js +69 -66
  13. package/dist/{number-overlay-editor-DuSCOMTK.js → number-overlay-editor-DGKTstav.js} +1 -1
  14. package/dist/{process-output-CtfJ_Gbp.js → process-output-PS9YSLNu.js} +2 -2
  15. package/dist/{reveal-component-DzmiQyN9.js → reveal-component-BLJMkx2N.js} +2 -2
  16. package/dist/{useDeepCompareMemoize-Dn-ZJVTd.js → semaphore-8KhQouXt.js} +5 -15
  17. package/dist/{vega-component-BIq0qzhQ.js → vega-component-CoJiBCaS.js} +11 -11
  18. package/package.json +1 -1
  19. package/src/__mocks__/executions.ts +1 -1
  20. package/src/__mocks__/intersection-observer.ts +5 -5
  21. package/src/components/editor/Output.tsx +3 -21
  22. package/src/components/editor/actions/__tests__/pair-with-agent-modal.test.tsx +27 -0
  23. package/src/components/editor/actions/pair-with-agent-modal.tsx +8 -1
  24. package/src/components/editor/output/VegaOutput.tsx +35 -0
  25. package/src/components/find-replace/find-replace.tsx +1 -7
  26. package/src/core/cells/__tests__/cell-errors.test.tsx +179 -0
  27. package/src/core/cells/cells.ts +24 -27
  28. package/src/core/codemirror/find-replace/__tests__/navigate.test.ts +18 -15
  29. package/src/core/codemirror/find-replace/__tests__/search-highlight.test.ts +90 -2
  30. package/src/core/codemirror/find-replace/__tests__/unmounted-cells.test.ts +44 -10
  31. package/src/core/codemirror/find-replace/navigate.ts +4 -1
  32. package/src/core/codemirror/find-replace/search-highlight.ts +54 -58
  33. package/src/core/executions/__tests__/atoms.test.ts +0 -2
  34. package/src/core/executions/__tests__/output-lifecycle.test.ts +16 -0
  35. package/src/core/executions/atoms.ts +33 -36
  36. package/src/core/export/__tests__/output-snapshot.test.tsx +240 -0
  37. package/src/core/export/__tests__/output-subscription.test.tsx +79 -0
  38. package/src/core/export/hooks.ts +29 -13
  39. package/src/core/notebook/replica/frame.ts +8 -2
  40. package/src/core/notebook/replica/index.ts +5 -1
  41. package/src/core/notebook/replica/once-per-frame.ts +4 -3
  42. package/src/core/notebook/replica/resources/executions.ts +16 -1
  43. package/src/utils/shared-intersection-observer.ts +2 -1
@@ -0,0 +1,79 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { act, render } from "@testing-library/react";
4
+ import { createStore, Provider } from "jotai";
5
+ import { Profiler } from "react";
6
+ import { describe, expect, it, onTestFinished, vi } from "vitest";
7
+ import { MockExecutions } from "@/__mocks__/executions";
8
+ import { MockRequestClient } from "@/__mocks__/requests";
9
+ import { cellId } from "@/__tests__/branded";
10
+ import { createRenderTracker } from "@/__tests__/render-tracker";
11
+ import { pageAppConfigAtom } from "@/core/config/config";
12
+ import { cellOutputsAtom, releaseCellOutputAtoms } from "@/core/executions";
13
+ import { connectionAtom } from "@/core/network/connection";
14
+ import { requestClientAtom } from "@/core/network/requests";
15
+ import { ConnectionState } from "@/core/session/types";
16
+ import { invariant } from "@/utils/invariant";
17
+ import { useAutoExport } from "../hooks";
18
+
19
+ function AutoExportOwner() {
20
+ useAutoExport();
21
+ return null;
22
+ }
23
+
24
+ describe.each([2, 250])("auto-export with %i cells", (size) => {
25
+ it("does no export work when a plain-text output changes", () => {
26
+ const store = createStore();
27
+ const ids = Array.from({ length: size }, (_, i) => cellId(`cell-${i}`));
28
+ const replica = MockExecutions.seed(
29
+ store,
30
+ ids.map((id) =>
31
+ MockExecutions.shown(id, { mimetype: "text/plain", data: id }),
32
+ ),
33
+ );
34
+ store.set(requestClientAtom, MockRequestClient.create());
35
+ store.set(connectionAtom, { state: ConnectionState.OPEN });
36
+ store.set(pageAppConfigAtom, { auto_download: [] });
37
+
38
+ const readOutputs = vi.spyOn(cellOutputsAtom, "read");
39
+ const renders = createRenderTracker();
40
+ const { unmount } = render(
41
+ <Provider store={store}>
42
+ <Profiler id="auto-export" onRender={renders.onRender}>
43
+ <AutoExportOwner />
44
+ </Profiler>
45
+ </Provider>,
46
+ );
47
+ onTestFinished(() => {
48
+ unmount();
49
+ readOutputs.mockRestore();
50
+ ids.forEach(releaseCellOutputAtoms);
51
+ });
52
+
53
+ expect(renders.counts()["auto-export"]).toBeGreaterThan(0);
54
+ expect.soft(readOutputs).toHaveBeenCalledTimes(0);
55
+ readOutputs.mockClear();
56
+ renders.reset();
57
+
58
+ const [changedCell] = ids;
59
+ act(() => {
60
+ store.set(replica.resultsAtom, (results) => {
61
+ const before = results.get(changedCell);
62
+ invariant(before, "The changed cell has a result");
63
+ return new Map(results).set(changedCell, {
64
+ ...before,
65
+ output: MockExecutions.output(before.record, {
66
+ mimetype: "text/plain",
67
+ data: "updated",
68
+ }),
69
+ outputVersion: before.outputVersion + 1,
70
+ });
71
+ });
72
+ });
73
+
74
+ expect({
75
+ aggregateReads: readOutputs.mock.calls.length,
76
+ commits: renders.counts(),
77
+ }).toEqual({ aggregateReads: 0, commits: {} });
78
+ });
79
+ });
@@ -1,5 +1,8 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
- import { useAtomValue } from "jotai";
2
+ import { useAtomValue, useStore } from "jotai";
3
+ // Screenshot capture reads the DOM immediately after publishing a pending frame.
4
+ // react-doctor-disable-next-line react-doctor/no-flush-sync
5
+ import { flushSync } from "react-dom";
3
6
  import type { MimeType } from "@/components/editor/Output";
4
7
  import { toast } from "@/components/ui/use-toast";
5
8
  import { appConfigAtom } from "@/core/config/config";
@@ -9,14 +12,15 @@ import { getImageDataUrlForCell } from "@/utils/download";
9
12
  import { Logger } from "@/utils/Logger";
10
13
  import { Objects } from "@/utils/objects";
11
14
  import { ProgressState } from "@/utils/progress";
12
- import type { CellId } from "../cells/ids";
13
- import { cellOutputsAtom } from "../executions";
15
+ import { type CellId, CellOutputId } from "../cells/ids";
16
+ import { type CellOutput, cellOutputsAtom } from "../executions";
14
17
  import { getExportLayout } from "./layout";
15
18
  import { connectionAtom } from "../network/connection";
16
19
  import { useRequestClient } from "../network/requests";
17
20
  import type { UpdateCellOutputsRequest } from "../network/types";
18
21
  import { VirtualFileTracker } from "../static/virtual-file-tracker";
19
22
  import { ConnectionState } from "../session/types";
23
+ import { activeNotebookFrameAtom } from "../session/active-notebook";
20
24
 
21
25
  const DELAY = 5000; // 5 seconds;
22
26
 
@@ -91,9 +95,7 @@ export function useAutoExport() {
91
95
  );
92
96
  }
93
97
 
94
- // MIME types to capture screenshots for
95
- const MIME_TYPES_TO_CAPTURE_SCREENSHOTS = new Set<MimeType>([
96
- "text/html",
98
+ const VEGA_MIME_TYPES = new Set<MimeType>([
97
99
  "application/vnd.vegalite.v5+json",
98
100
  "application/vnd.vega.v5+json",
99
101
  "application/vnd.vegalite.v6+json",
@@ -122,17 +124,18 @@ interface UseEnrichCellOutputsOptions {
122
124
  export function useEnrichCellOutputs(): (
123
125
  opts: UseEnrichCellOutputsOptions,
124
126
  ) => Promise<ScreenshotResults> {
125
- const outputs = useAtomValue(cellOutputsAtom);
127
+ const store = useStore();
126
128
 
127
129
  return async (
128
130
  opts: UseEnrichCellOutputsOptions,
129
131
  ): Promise<ScreenshotResults> => {
130
132
  const { progress } = opts;
133
+ const outputs = store.get(cellOutputsAtom);
131
134
 
132
135
  // Prune tracked state for cells that no longer show anything
133
136
  captureTracker.prune(new Set(outputs.keys()));
134
137
 
135
- const cellsToCaptureScreenshot: [CellId, unknown][] = [];
138
+ const cellsToCaptureScreenshot: [CellId, CellOutput][] = [];
136
139
  const inFlightWaiters: {
137
140
  cellId: CellId;
138
141
  promise: Promise<ScreenshotResult | undefined>;
@@ -141,11 +144,12 @@ export function useEnrichCellOutputs(): (
141
144
  for (const [cellId, output] of outputs) {
142
145
  const outputData = output.data;
143
146
  if (
144
- MIME_TYPES_TO_CAPTURE_SCREENSHOTS.has(output.mimetype) &&
147
+ (output.mimetype === "text/html" ||
148
+ VEGA_MIME_TYPES.has(output.mimetype)) &&
145
149
  outputData
146
150
  ) {
147
151
  if (captureTracker.needsCapture(cellId, outputData)) {
148
- cellsToCaptureScreenshot.push([cellId, outputData]);
152
+ cellsToCaptureScreenshot.push([cellId, output]);
149
153
  } else {
150
154
  // If already in-flight with the same value, await its result
151
155
  const promise = captureTracker.waitForInFlight(cellId, outputData);
@@ -160,17 +164,29 @@ export function useEnrichCellOutputs(): (
160
164
  return {};
161
165
  }
162
166
 
163
- // Start the progress bar for new captures only
164
167
  if (cellsToCaptureScreenshot.length > 0) {
168
+ const frame = store.get(activeNotebookFrameAtom);
169
+ if (frame) {
170
+ flushSync(frame.flush);
171
+ }
165
172
  progress.addTotal(cellsToCaptureScreenshot.length);
166
173
  }
167
174
 
168
175
  // Capture screenshots — each key gets its own AbortSignal so
169
176
  // aborting one cell does not affect the others.
170
177
  const results: ScreenshotResults = {};
171
- for (const [cellId, outputData] of cellsToCaptureScreenshot) {
172
- const handle = captureTracker.startCapture(cellId, outputData);
178
+ for (const [cellId, output] of cellsToCaptureScreenshot) {
179
+ const handle = captureTracker.startCapture(cellId, output.data);
173
180
  try {
181
+ if (
182
+ VEGA_MIME_TYPES.has(output.mimetype) &&
183
+ !document
184
+ .getElementById(CellOutputId.create(cellId))
185
+ ?.querySelector("[data-marimo-vega-ready]")
186
+ ) {
187
+ handle.markFailed();
188
+ continue;
189
+ }
174
190
  const dataUrl = await getImageDataUrlForCell(cellId);
175
191
  if (handle.signal.aborted) {
176
192
  continue;
@@ -4,7 +4,7 @@ import { atom, type createStore } from "jotai/vanilla";
4
4
  import type { NotebookReplica } from "./replica";
5
5
  import { oncePerFrame } from "./once-per-frame";
6
6
 
7
- export type ReplicaFrame = Pick<
7
+ export type FrameSource = Pick<
8
8
  NotebookReplica,
9
9
  | "notebookAtom"
10
10
  | "generationAtom"
@@ -16,10 +16,15 @@ export type ReplicaFrame = Pick<
16
16
  | "runtimeAtom"
17
17
  >;
18
18
 
19
+ export interface ReplicaFrame extends FrameSource {
20
+ /** Publish pending state before an operation reads the rendered notebook. */
21
+ flush(): void;
22
+ }
23
+
19
24
  /** The replica's display atoms, republished together once per frame. */
20
25
  export function createReplicaFrame(
21
26
  store: ReturnType<typeof createStore>,
22
- replica: ReplicaFrame,
27
+ replica: FrameSource,
23
28
  { signal }: { signal: AbortSignal },
24
29
  ): ReplicaFrame {
25
30
  const currentAtom = atom((get) => ({
@@ -42,6 +47,7 @@ export function createReplicaFrame(
42
47
  signal.addEventListener("abort", unsubscribe, { once: true });
43
48
  }
44
49
  return {
50
+ flush: publish.flush,
45
51
  notebookAtom: atom((get) => get(frameAtom).notebook),
46
52
  generationAtom: atom((get) => get(frameAtom).generation),
47
53
  documentAtom: atom((get) => get(frameAtom).document),
@@ -3,7 +3,11 @@
3
3
  /** Backend-confirmed notebook state, independent of React and transports. */
4
4
 
5
5
  export type { NotebookBackend } from "./backend";
6
- export { createReplicaFrame, type ReplicaFrame } from "./frame";
6
+ export {
7
+ createReplicaFrame,
8
+ type FrameSource,
9
+ type ReplicaFrame,
10
+ } from "./frame";
7
11
  export {
8
12
  type CloseDecision,
9
13
  ConnectionClosedReason,
@@ -4,7 +4,7 @@
4
4
  export function oncePerFrame(
5
5
  publish: () => void,
6
6
  { signal }: { signal: AbortSignal },
7
- ): () => void {
7
+ ) {
8
8
  let generation = 0;
9
9
  let cancelScheduled: (() => void) | undefined;
10
10
 
@@ -36,7 +36,7 @@ export function oncePerFrame(
36
36
  );
37
37
  }
38
38
 
39
- return () => {
39
+ function schedule() {
40
40
  if (signal.aborted || cancelScheduled) {
41
41
  return;
42
42
  }
@@ -56,5 +56,6 @@ export function oncePerFrame(
56
56
  const frame = requestAnimationFrame(callback);
57
57
  cancelScheduled = () => cancelAnimationFrame(frame);
58
58
  }
59
- };
59
+ }
60
+ return Object.assign(schedule, { flush: run });
60
61
  }
@@ -251,7 +251,22 @@ function sameShown(
251
251
  a: Pick<Result, "record" | "output">,
252
252
  b: Pick<Result, "record" | "output">,
253
253
  ): boolean {
254
- return JSON.stringify(shown(a)) === JSON.stringify(shown(b));
254
+ const left = shown(a);
255
+ const right = shown(b);
256
+ if (left === right) {
257
+ return true;
258
+ }
259
+ if (left === null || right === null || left.kind !== right.kind) {
260
+ return false;
261
+ }
262
+ if (left.kind === "output" && right.kind === "output") {
263
+ return (
264
+ left.media === right.media ||
265
+ (left.media?.mimetype === right.media?.mimetype &&
266
+ left.media?.data === right.media?.data)
267
+ );
268
+ }
269
+ return JSON.stringify(left) === JSON.stringify(right);
255
270
  }
256
271
 
257
272
  /** Replace an execution and keep its retained copies in step. */
@@ -4,6 +4,7 @@ import { createSharedResource } from "./shared-resource";
4
4
  /** One observer per options set, with independently disposable subscriptions. */
5
5
  export function createSharedIntersectionObserver(
6
6
  options: IntersectionObserverInit,
7
+ isVisible = (entry: IntersectionObserverEntry) => entry.isIntersecting,
7
8
  ) {
8
9
  const subscribers = new Map<Element, Set<(visible: boolean) => void>>();
9
10
  let observer: IntersectionObserver | undefined;
@@ -17,7 +18,7 @@ export function createSharedIntersectionObserver(
17
18
  const snapshot = [...(callbacks ?? [])];
18
19
  for (const callback of snapshot) {
19
20
  if (callbacks?.has(callback)) {
20
- callback(entry.isIntersecting);
21
+ callback(isVisible(entry));
21
22
  }
22
23
  }
23
24
  }