@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.
- package/dist/{ErrorBoundary-pNKOBKXw.js → ErrorBoundary-Gr2Kt5kj.js} +1 -1
- package/dist/{chat-ui-C9NZA-bk.js → chat-ui-CMKYvKUz.js} +3 -3
- package/dist/{code-visibility-B9s3Hl8z.js → code-visibility-BFFe0rT7.js} +2 -2
- package/dist/{common-Bn3jx0X6.js → common-7eNIhSN-.js} +4766 -4749
- package/dist/{data-grid-overlay-editor-mxwwRaQy.js → data-grid-overlay-editor-B37-1-8n.js} +1 -1
- package/dist/{error-entries-1DC4BiYB.js → error-entries-B4LgfizR.js} +759 -749
- package/dist/{feedback-button-BrzbnRTT.js → feedback-button-CpQcgVuz.js} +3 -3
- package/dist/{formats-Y52bg800.js → formats-CeuXJ_1f.js} +32 -25
- package/dist/{glide-data-editor-Cnsv3NcI.js → glide-data-editor-BxTlDHV5.js} +3 -3
- package/dist/{globals-BGqfFPx8.js → globals-ljOLdTJr.js} +1 -1
- package/dist/{html-to-image-CsvAOgd3.js → html-to-image-CIkwg7mv.js} +1 -1
- package/dist/main.js +69 -66
- package/dist/{number-overlay-editor-DuSCOMTK.js → number-overlay-editor-DGKTstav.js} +1 -1
- package/dist/{process-output-CtfJ_Gbp.js → process-output-PS9YSLNu.js} +2 -2
- package/dist/{reveal-component-DzmiQyN9.js → reveal-component-BLJMkx2N.js} +2 -2
- package/dist/{useDeepCompareMemoize-Dn-ZJVTd.js → semaphore-8KhQouXt.js} +5 -15
- package/dist/{vega-component-BIq0qzhQ.js → vega-component-CoJiBCaS.js} +11 -11
- package/package.json +1 -1
- package/src/__mocks__/executions.ts +1 -1
- package/src/__mocks__/intersection-observer.ts +5 -5
- package/src/components/editor/Output.tsx +3 -21
- package/src/components/editor/actions/__tests__/pair-with-agent-modal.test.tsx +27 -0
- package/src/components/editor/actions/pair-with-agent-modal.tsx +8 -1
- package/src/components/editor/output/VegaOutput.tsx +35 -0
- package/src/components/find-replace/find-replace.tsx +1 -7
- package/src/core/cells/__tests__/cell-errors.test.tsx +179 -0
- package/src/core/cells/cells.ts +24 -27
- package/src/core/codemirror/find-replace/__tests__/navigate.test.ts +18 -15
- package/src/core/codemirror/find-replace/__tests__/search-highlight.test.ts +90 -2
- package/src/core/codemirror/find-replace/__tests__/unmounted-cells.test.ts +44 -10
- package/src/core/codemirror/find-replace/navigate.ts +4 -1
- package/src/core/codemirror/find-replace/search-highlight.ts +54 -58
- package/src/core/executions/__tests__/atoms.test.ts +0 -2
- package/src/core/executions/__tests__/output-lifecycle.test.ts +16 -0
- package/src/core/executions/atoms.ts +33 -36
- package/src/core/export/__tests__/output-snapshot.test.tsx +240 -0
- package/src/core/export/__tests__/output-subscription.test.tsx +79 -0
- package/src/core/export/hooks.ts +29 -13
- package/src/core/notebook/replica/frame.ts +8 -2
- package/src/core/notebook/replica/index.ts +5 -1
- package/src/core/notebook/replica/once-per-frame.ts +4 -3
- package/src/core/notebook/replica/resources/executions.ts +16 -1
- package/src/utils/shared-intersection-observer.ts +2 -1
|
@@ -323,7 +323,7 @@ export const MockExecutions = {
|
|
|
323
323
|
} satisfies NotebookReplica;
|
|
324
324
|
store.set(activeNotebookReplicaAtom, replica);
|
|
325
325
|
// Selector tests share current inputs; frame scheduling is tested separately.
|
|
326
|
-
store.set(activeNotebookFrameAtom, replica);
|
|
326
|
+
store.set(activeNotebookFrameAtom, { ...replica, flush: () => undefined });
|
|
327
327
|
return replica;
|
|
328
328
|
},
|
|
329
329
|
};
|
|
@@ -13,16 +13,16 @@ export function mockIntersectionObservers() {
|
|
|
13
13
|
unobserve: vi.fn(),
|
|
14
14
|
disconnect: vi.fn(),
|
|
15
15
|
takeRecords: () => [],
|
|
16
|
-
emit(target: Element, visible: boolean) {
|
|
17
|
-
observer.emitBatch([[target, visible]]);
|
|
16
|
+
emit(target: Element, visible: boolean, intersectionRatio?: number) {
|
|
17
|
+
observer.emitBatch([[target, visible, intersectionRatio]]);
|
|
18
18
|
},
|
|
19
|
-
emitBatch(changes: [Element, boolean][]) {
|
|
19
|
+
emitBatch(changes: [Element, boolean, number?][]) {
|
|
20
20
|
const rect = new DOMRect();
|
|
21
21
|
callback(
|
|
22
|
-
changes.map(([target, isIntersecting]) => ({
|
|
22
|
+
changes.map(([target, isIntersecting, ratio]) => ({
|
|
23
23
|
target,
|
|
24
24
|
isIntersecting,
|
|
25
|
-
intersectionRatio: isIntersecting ? 1 : 0,
|
|
25
|
+
intersectionRatio: ratio ?? (isIntersecting ? 1 : 0),
|
|
26
26
|
time: 0,
|
|
27
27
|
boundingClientRect: rect,
|
|
28
28
|
intersectionRect: rect,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
-
import React, { memo,
|
|
2
|
+
import React, { memo, useMemo, useRef } from "react";
|
|
3
3
|
import { type CellId, CellOutputId } from "@/core/cells/ids";
|
|
4
4
|
import type { CellOutput } from "@/core/executions";
|
|
5
5
|
import type { OutputMessage } from "@/core/kernel/messages";
|
|
@@ -21,7 +21,6 @@ import {
|
|
|
21
21
|
ExpandIcon,
|
|
22
22
|
ShrinkIcon,
|
|
23
23
|
} from "lucide-react";
|
|
24
|
-
import { tooltipHandler } from "@/components/charts/tooltip";
|
|
25
24
|
import { useExpandedOutput } from "@/core/cells/outputs";
|
|
26
25
|
import { viewStateAtom } from "@/core/mode";
|
|
27
26
|
import { useEventListener } from "@/hooks/useEventListener";
|
|
@@ -30,15 +29,12 @@ import { useOverflowDetection } from "@/hooks/useOverflowDetection";
|
|
|
30
29
|
import { renderHTML } from "@/plugins/core/RenderHTML";
|
|
31
30
|
import { Banner } from "@/plugins/impl/common/error-banner";
|
|
32
31
|
import type { TopLevelFacetedUnitSpec } from "@/plugins/impl/data-explorer/queries/types";
|
|
33
|
-
import { getContainerWidth } from "@/plugins/impl/vega/utils";
|
|
34
|
-
import { useTheme } from "@/theme/useTheme";
|
|
35
32
|
import { Events } from "@/utils/events";
|
|
36
33
|
import { invariant } from "@/utils/invariant";
|
|
37
34
|
import { Logger } from "@/utils/Logger";
|
|
38
35
|
import { processMimeBundle } from "@/utils/mime-types";
|
|
39
36
|
import { Objects } from "@/utils/objects";
|
|
40
|
-
import {
|
|
41
|
-
import { ChartLoadingState } from "../data-table/charts/components/chart-states";
|
|
37
|
+
import { VegaOutput } from "./output/VegaOutput";
|
|
42
38
|
import { Button } from "../ui/button";
|
|
43
39
|
import { useIsFullScreen } from "../ui/fullscreen";
|
|
44
40
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs";
|
|
@@ -85,7 +81,6 @@ export const OutputRenderer: React.FC<{
|
|
|
85
81
|
metadata,
|
|
86
82
|
renderFallback,
|
|
87
83
|
} = props;
|
|
88
|
-
const { theme } = useTheme();
|
|
89
84
|
|
|
90
85
|
// Memoize parsing the json data
|
|
91
86
|
const parsedJsonData = useMemo(() => {
|
|
@@ -214,20 +209,7 @@ export const OutputRenderer: React.FC<{
|
|
|
214
209
|
case "application/vnd.vega.v5+json":
|
|
215
210
|
case "application/vnd.vegalite.v6+json":
|
|
216
211
|
case "application/vnd.vega.v6+json":
|
|
217
|
-
return
|
|
218
|
-
<Suspense fallback={<ChartLoadingState />}>
|
|
219
|
-
<LazyVegaEmbed
|
|
220
|
-
spec={parsedJsonData as TopLevelFacetedUnitSpec}
|
|
221
|
-
data-container-width={getContainerWidth(parsedJsonData)}
|
|
222
|
-
options={{
|
|
223
|
-
theme: theme === "dark" ? "dark" : undefined,
|
|
224
|
-
mode: "vega-lite",
|
|
225
|
-
tooltip: tooltipHandler.call,
|
|
226
|
-
renderer: "canvas",
|
|
227
|
-
}}
|
|
228
|
-
/>
|
|
229
|
-
</Suspense>
|
|
230
|
-
);
|
|
212
|
+
return <VegaOutput spec={parsedJsonData as TopLevelFacetedUnitSpec} />;
|
|
231
213
|
case "application/vnd.marimo+mimebundle":
|
|
232
214
|
return (
|
|
233
215
|
<MimeBundleOutputRenderer
|
|
@@ -378,6 +378,33 @@ describe("PairWithAgentModal", () => {
|
|
|
378
378
|
expect(screen.getByRole("button", { name: "Copy command" })).toBeDisabled();
|
|
379
379
|
});
|
|
380
380
|
|
|
381
|
+
it("cancels the copy confirmation reset when the modal unmounts", async () => {
|
|
382
|
+
vi.useFakeTimers();
|
|
383
|
+
const schedule = vi.spyOn(globalThis, "setTimeout");
|
|
384
|
+
const cancel = vi.spyOn(globalThis, "clearTimeout");
|
|
385
|
+
try {
|
|
386
|
+
const { unmount } = await act(async () =>
|
|
387
|
+
render(<PairWithAgentModal onClose={vi.fn()} />, { wrapper }),
|
|
388
|
+
);
|
|
389
|
+
await act(async () => {
|
|
390
|
+
fireEvent.click(screen.getByRole("button", { name: "Copy command" }));
|
|
391
|
+
});
|
|
392
|
+
expect(copyToClipboard).toHaveBeenCalledOnce();
|
|
393
|
+
const resetIndex = schedule.mock.calls.findIndex(
|
|
394
|
+
([, delay]) => delay === 2000,
|
|
395
|
+
);
|
|
396
|
+
expect(resetIndex).toBeGreaterThanOrEqual(0);
|
|
397
|
+
const reset = schedule.mock.results[resetIndex].value;
|
|
398
|
+
|
|
399
|
+
unmount();
|
|
400
|
+
expect(cancel).toHaveBeenCalledWith(reset);
|
|
401
|
+
} finally {
|
|
402
|
+
schedule.mockRestore();
|
|
403
|
+
cancel.mockRestore();
|
|
404
|
+
vi.useRealTimers();
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
|
|
381
408
|
it("copies a host mode terminal command without the token and lets the user copy the token separately", async () => {
|
|
382
409
|
vi.mocked(fetch).mockImplementation((url) =>
|
|
383
410
|
responseFor(url, "secret-token"),
|
|
@@ -252,6 +252,14 @@ const CommandBlock: React.FC<{
|
|
|
252
252
|
}) => {
|
|
253
253
|
const [copied, setCopied] = useState(false);
|
|
254
254
|
|
|
255
|
+
useEffect(() => {
|
|
256
|
+
if (!copied) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const timeout = setTimeout(() => setCopied(false), 2000);
|
|
260
|
+
return () => clearTimeout(timeout);
|
|
261
|
+
}, [copied]);
|
|
262
|
+
|
|
255
263
|
const copy = Events.stopPropagation(async (e) => {
|
|
256
264
|
e.preventDefault();
|
|
257
265
|
if (disabled) {
|
|
@@ -259,7 +267,6 @@ const CommandBlock: React.FC<{
|
|
|
259
267
|
}
|
|
260
268
|
await copyToClipboard(command);
|
|
261
269
|
setCopied(true);
|
|
262
|
-
setTimeout(() => setCopied(false), 2000);
|
|
263
270
|
});
|
|
264
271
|
|
|
265
272
|
if (multiline) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { Suspense, useState } from "react";
|
|
4
|
+
import type { VegaEmbedProps } from "react-vega";
|
|
5
|
+
import { LazyVegaEmbed } from "@/components/charts/lazy";
|
|
6
|
+
import { tooltipHandler } from "@/components/charts/tooltip";
|
|
7
|
+
import { ChartLoadingState } from "@/components/data-table/charts/components/chart-states";
|
|
8
|
+
import { useDeepCompareMemoize } from "@/hooks/useDeepCompareMemoize";
|
|
9
|
+
import type { TopLevelFacetedUnitSpec } from "@/plugins/impl/data-explorer/queries/types";
|
|
10
|
+
import { getContainerWidth } from "@/plugins/impl/vega/utils";
|
|
11
|
+
import { useTheme } from "@/theme/useTheme";
|
|
12
|
+
|
|
13
|
+
export function VegaOutput({ spec }: { spec: TopLevelFacetedUnitSpec }) {
|
|
14
|
+
const { theme } = useTheme();
|
|
15
|
+
const embed = useDeepCompareMemoize({
|
|
16
|
+
spec,
|
|
17
|
+
options: {
|
|
18
|
+
theme: theme === "dark" ? "dark" : undefined,
|
|
19
|
+
mode: "vega-lite",
|
|
20
|
+
tooltip: tooltipHandler.call,
|
|
21
|
+
renderer: "canvas",
|
|
22
|
+
},
|
|
23
|
+
} satisfies VegaEmbedProps);
|
|
24
|
+
const [rendered, setRendered] = useState<typeof embed>();
|
|
25
|
+
return (
|
|
26
|
+
<Suspense fallback={<ChartLoadingState />}>
|
|
27
|
+
<LazyVegaEmbed
|
|
28
|
+
{...embed}
|
|
29
|
+
onEmbed={() => setRendered(embed)}
|
|
30
|
+
data-marimo-vega-ready={rendered === embed || undefined}
|
|
31
|
+
data-container-width={getContainerWidth(spec)}
|
|
32
|
+
/>
|
|
33
|
+
</Suspense>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -18,10 +18,6 @@ import {
|
|
|
18
18
|
replaceAll,
|
|
19
19
|
replaceNext,
|
|
20
20
|
} from "@/core/codemirror/find-replace/navigate";
|
|
21
|
-
import {
|
|
22
|
-
clearGlobalSearchQuery,
|
|
23
|
-
setGlobalSearchQuery,
|
|
24
|
-
} from "@/core/codemirror/find-replace/search-highlight";
|
|
25
21
|
import {
|
|
26
22
|
findReplaceAtom,
|
|
27
23
|
openFindReplacePanel,
|
|
@@ -68,18 +64,15 @@ export const FindReplace: React.FC = () => {
|
|
|
68
64
|
|
|
69
65
|
useEffect(() => {
|
|
70
66
|
if (!state.isOpen) {
|
|
71
|
-
clearGlobalSearchQuery();
|
|
72
67
|
return;
|
|
73
68
|
}
|
|
74
69
|
|
|
75
70
|
if (state.findText === "") {
|
|
76
71
|
setMatches(undefined);
|
|
77
|
-
clearGlobalSearchQuery();
|
|
78
72
|
return;
|
|
79
73
|
}
|
|
80
74
|
|
|
81
75
|
resetMatches();
|
|
82
|
-
setGlobalSearchQuery();
|
|
83
76
|
}, [
|
|
84
77
|
// Re-search when any of these change
|
|
85
78
|
state.findText,
|
|
@@ -245,6 +238,7 @@ export const FindReplace: React.FC = () => {
|
|
|
245
238
|
data-testid="undo-replace-all-button"
|
|
246
239
|
onClick={() => {
|
|
247
240
|
undo();
|
|
241
|
+
resetMatches();
|
|
248
242
|
dismiss();
|
|
249
243
|
}}
|
|
250
244
|
/>
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { act, render, screen } 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 { mockAnimationFrames } from "@/__mocks__/animation-frames";
|
|
8
|
+
import { type ExecutionEntries, MockExecutions } from "@/__mocks__/executions";
|
|
9
|
+
import { MockNotebook } from "@/__mocks__/notebook";
|
|
10
|
+
import { cellId } from "@/__tests__/branded";
|
|
11
|
+
import { createRenderTracker } from "@/__tests__/render-tracker";
|
|
12
|
+
import { cellOutputAtom, clearCellOutputs } from "@/core/executions";
|
|
13
|
+
import {
|
|
14
|
+
cell,
|
|
15
|
+
document as documentOf,
|
|
16
|
+
withCells,
|
|
17
|
+
} from "@/core/notebook/document/__tests__/fixtures";
|
|
18
|
+
import { createReplicaFrame } from "@/core/notebook/replica";
|
|
19
|
+
import { activeNotebookFrameAtom } from "@/core/session/active-notebook";
|
|
20
|
+
import {
|
|
21
|
+
cellErrorCount,
|
|
22
|
+
cellErrorsAtom,
|
|
23
|
+
getNotebookActionsForStore,
|
|
24
|
+
useCellErrors,
|
|
25
|
+
} from "../cells";
|
|
26
|
+
|
|
27
|
+
const first = cellId("c1");
|
|
28
|
+
const second = cellId("c2");
|
|
29
|
+
const third = cellId("c3");
|
|
30
|
+
const firstError = MockExecutions.failed(first);
|
|
31
|
+
const secondError = MockExecutions.failed(second);
|
|
32
|
+
const ancestorError = MockExecutions.completed(second, {
|
|
33
|
+
kind: "skipped",
|
|
34
|
+
reason: "upstream-stopped",
|
|
35
|
+
message: "The upstream cell stopped",
|
|
36
|
+
related: [{ cell_id: first, range: null, message: "Stopped here" }],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
function setup(size: number, ...entries: ExecutionEntries) {
|
|
40
|
+
const store = createStore();
|
|
41
|
+
const actions = getNotebookActionsForStore(store);
|
|
42
|
+
const order = Array.from({ length: size }, (_, i) => cellId(`c${i + 1}`));
|
|
43
|
+
const confirmed = withCells(
|
|
44
|
+
documentOf(),
|
|
45
|
+
Object.fromEntries(order.map((id) => [id, cell(id, "pass", { name: id })])),
|
|
46
|
+
);
|
|
47
|
+
const cells = new Map(confirmed.cells);
|
|
48
|
+
actions.reconcileDocument({ order, cells });
|
|
49
|
+
const replica = MockExecutions.seed(store, entries, null, confirmed);
|
|
50
|
+
const receive = (records: ExecutionEntries) => {
|
|
51
|
+
const next = MockExecutions.inputs(records);
|
|
52
|
+
store.set(replica.executionsAtom, next.executions);
|
|
53
|
+
store.set(replica.resultsAtom, next.results);
|
|
54
|
+
};
|
|
55
|
+
return { store, actions, order, cells, replica, receive };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function ErrorNames() {
|
|
59
|
+
const names = useCellErrors().map((error) => error.cellName);
|
|
60
|
+
return <output>{names.join(", ")}</output>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
describe("cellErrorsAtom", () => {
|
|
64
|
+
it.each([5, 500])("skips unrelated updates with %i cells", (size) => {
|
|
65
|
+
const { store, actions, order, cells, replica, receive } = setup(
|
|
66
|
+
size,
|
|
67
|
+
firstError,
|
|
68
|
+
);
|
|
69
|
+
const advanceFrame = mockAnimationFrames();
|
|
70
|
+
const lifetime = new AbortController();
|
|
71
|
+
onTestFinished(() => lifetime.abort());
|
|
72
|
+
store.set(
|
|
73
|
+
activeNotebookFrameAtom,
|
|
74
|
+
createReplicaFrame(store, replica, { signal: lifetime.signal }),
|
|
75
|
+
);
|
|
76
|
+
const read = vi.spyOn(cellErrorsAtom, "read");
|
|
77
|
+
onTestFinished(() => read.mockRestore());
|
|
78
|
+
const renders = createRenderTracker();
|
|
79
|
+
render(
|
|
80
|
+
<Provider store={store}>
|
|
81
|
+
<Profiler id="errors" onRender={renders.onRender}>
|
|
82
|
+
<ErrorNames />
|
|
83
|
+
</Profiler>
|
|
84
|
+
</Provider>,
|
|
85
|
+
);
|
|
86
|
+
const before = store.get(cellErrorsAtom);
|
|
87
|
+
renders.reset();
|
|
88
|
+
read.mockClear();
|
|
89
|
+
|
|
90
|
+
act(() => {
|
|
91
|
+
actions.startCellConsole({ cellId: second });
|
|
92
|
+
cells.set(first, cell(first, "fixed()", { name: first }));
|
|
93
|
+
cells.set(second, cell(second, "pass", { name: "renamed" }));
|
|
94
|
+
actions.reconcileDocument({ order, cells });
|
|
95
|
+
});
|
|
96
|
+
act(() => {
|
|
97
|
+
receive([
|
|
98
|
+
firstError,
|
|
99
|
+
MockExecutions.shown(second, { mimetype: "text/plain", data: "42" }),
|
|
100
|
+
]);
|
|
101
|
+
advanceFrame();
|
|
102
|
+
});
|
|
103
|
+
expect(store.get(cellOutputAtom(second))?.data).toBe("42");
|
|
104
|
+
act(() => {
|
|
105
|
+
receive([firstError, ancestorError]);
|
|
106
|
+
advanceFrame();
|
|
107
|
+
});
|
|
108
|
+
expect(store.get(cellOutputAtom(second))?.data).toEqual([
|
|
109
|
+
expect.objectContaining({ type: "ancestor-stopped" }),
|
|
110
|
+
]);
|
|
111
|
+
expect(read).not.toHaveBeenCalled();
|
|
112
|
+
expect(renders.counts()).toEqual({});
|
|
113
|
+
expect(store.get(cellErrorsAtom)).toBe(before);
|
|
114
|
+
|
|
115
|
+
act(() => {
|
|
116
|
+
receive([firstError, secondError]);
|
|
117
|
+
advanceFrame();
|
|
118
|
+
});
|
|
119
|
+
expect(read).toHaveBeenCalledOnce();
|
|
120
|
+
expect(renders.counts()).toEqual({ errors: 1 });
|
|
121
|
+
expect(screen.getByRole("status").textContent).toBe("c1, renamed");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("tracks order, names, clear, and cell lifetime within each store", () => {
|
|
125
|
+
const { store, actions, cells, order } = setup(3, firstError, secondError);
|
|
126
|
+
const other = setup(2, firstError).store;
|
|
127
|
+
const otherErrors = other.get(cellErrorsAtom);
|
|
128
|
+
const names = () =>
|
|
129
|
+
store.get(cellErrorsAtom).map((error) => error.cellName);
|
|
130
|
+
expect(names()).toEqual([first, second]);
|
|
131
|
+
|
|
132
|
+
cells.set(first, cell(first, "pass", { name: "renamed" }));
|
|
133
|
+
actions.reconcileDocument({ order, cells });
|
|
134
|
+
expect(names()).toEqual(["renamed", second]);
|
|
135
|
+
const before = store.get(cellErrorsAtom);
|
|
136
|
+
actions.reconcileDocument({ order: [third, first, second], cells });
|
|
137
|
+
expect(store.get(cellErrorsAtom)).toBe(before);
|
|
138
|
+
actions.reconcileDocument({ order: [third, second, first], cells });
|
|
139
|
+
expect(names()).toEqual([second, "renamed"]);
|
|
140
|
+
clearCellOutputs(store, [second]);
|
|
141
|
+
expect(store.get(cellErrorCount)).toBe(1);
|
|
142
|
+
cells.delete(first);
|
|
143
|
+
actions.reconcileDocument({ order: [third, second], cells });
|
|
144
|
+
expect(names()).toEqual([]);
|
|
145
|
+
|
|
146
|
+
cells.set(first, cell(first, "pass", { name: "restored" }));
|
|
147
|
+
actions.reconcileDocument({ order, cells });
|
|
148
|
+
expect(names()).toEqual(["restored"]);
|
|
149
|
+
expect(other.get(cellErrorsAtom)).toBe(otherErrors);
|
|
150
|
+
expect(otherErrors.map((error) => error.cellName)).toEqual([first]);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("keeps actionable errors in a mixed output", () => {
|
|
154
|
+
const { store } = setup(2);
|
|
155
|
+
const actionable = [
|
|
156
|
+
MockNotebook.errors.exception("Division by zero"),
|
|
157
|
+
MockNotebook.errors.syntax("Invalid syntax"),
|
|
158
|
+
];
|
|
159
|
+
const output = {
|
|
160
|
+
channel: "marimo-error",
|
|
161
|
+
mimetype: "application/vnd.marimo+error",
|
|
162
|
+
timestamp: 1,
|
|
163
|
+
data: [
|
|
164
|
+
...actionable,
|
|
165
|
+
{
|
|
166
|
+
type: "ancestor-stopped",
|
|
167
|
+
raising_cell: second,
|
|
168
|
+
msg: "Upstream stop",
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
} as const;
|
|
172
|
+
const read = vi
|
|
173
|
+
.spyOn(cellOutputAtom(first), "read")
|
|
174
|
+
.mockReturnValue(output);
|
|
175
|
+
onTestFinished(() => read.mockRestore());
|
|
176
|
+
expect(store.get(cellErrorsAtom)[0]?.output.data).toEqual(actionable);
|
|
177
|
+
expect(store.get(cellErrorCount)).toBe(1);
|
|
178
|
+
});
|
|
179
|
+
});
|
package/src/core/cells/cells.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
releaseCellOutputAtoms,
|
|
19
19
|
} from "@/core/executions";
|
|
20
20
|
import type { CellColumnId } from "./layout";
|
|
21
|
+
import { arrayShallowEquals } from "@/utils/arrays";
|
|
21
22
|
import { Functions } from "@/utils/functions";
|
|
22
23
|
import { invariant } from "@/utils/invariant";
|
|
23
24
|
import { Logger } from "@/utils/Logger";
|
|
@@ -450,36 +451,31 @@ export const runReasonAtom = atom((get) =>
|
|
|
450
451
|
|
|
451
452
|
export const needsRunAtom = atom((get) => get(runReasonAtom) !== null);
|
|
452
453
|
|
|
453
|
-
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
const output = get(cellOutputAtom(cellId));
|
|
458
|
-
const { name } = cellData[cellId];
|
|
459
|
-
if (output !== null && isErrorMime(output.mimetype)) {
|
|
460
|
-
// Filter out ancestor-stopped errors
|
|
461
|
-
// These are errors that are caused by a cell that was stopped,
|
|
462
|
-
// but nothing the user can take action on.
|
|
463
|
-
invariant(Array.isArray(output.data), "Expected array data");
|
|
464
|
-
const nonAncestorErrors = output.data.filter(
|
|
465
|
-
(error) => !error.type.includes("ancestor"),
|
|
466
|
-
);
|
|
467
|
-
|
|
468
|
-
if (nonAncestorErrors.length > 0) {
|
|
469
|
-
return {
|
|
470
|
-
output: { ...output, data: nonAncestorErrors },
|
|
471
|
-
cellId: cellId,
|
|
472
|
-
cellName: name,
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
454
|
+
const cellErrorAtom = atomFamily((cellId: CellId) => {
|
|
455
|
+
const errorOutputAtom = atom((get) => {
|
|
456
|
+
const output = get(cellOutputAtom(cellId));
|
|
457
|
+
if (output === null || !isErrorMime(output.mimetype)) {
|
|
477
458
|
return null;
|
|
478
|
-
}
|
|
479
|
-
.
|
|
480
|
-
|
|
459
|
+
}
|
|
460
|
+
invariant(Array.isArray(output.data), "Expected array data");
|
|
461
|
+
const data = output.data.filter(
|
|
462
|
+
(error) => !error.type.includes("ancestor"),
|
|
463
|
+
);
|
|
464
|
+
return data.length > 0 ? { ...output, data } : null;
|
|
465
|
+
});
|
|
466
|
+
const nameAtom = atom((get) => get(cellDataAtom(cellId))?.name);
|
|
467
|
+
return atom((get) => {
|
|
468
|
+
const output = get(errorOutputAtom);
|
|
469
|
+
return output && { output, cellId, cellName: get(nameAtom) };
|
|
470
|
+
});
|
|
481
471
|
});
|
|
482
472
|
|
|
473
|
+
export const cellErrorsAtom = selectAtom(
|
|
474
|
+
atom((get) => get(cellIdsAtom).map((id) => get(cellErrorAtom(id)))),
|
|
475
|
+
(entries) => entries.filter(Boolean),
|
|
476
|
+
arrayShallowEquals,
|
|
477
|
+
);
|
|
478
|
+
|
|
483
479
|
// Layout needs lookup by cell ID. Navigation needs the same headings in document order.
|
|
484
480
|
const orderedCellOutlines = selectAtom(
|
|
485
481
|
atom((get) => {
|
|
@@ -620,6 +616,7 @@ export const cellHandleAtom = atomFamily((cellId: CellId) =>
|
|
|
620
616
|
* @see https://jotai.org/docs/utilities/family#caveat-memory-leaks
|
|
621
617
|
*/
|
|
622
618
|
export function releaseCellAtoms(cellId: CellId) {
|
|
619
|
+
cellErrorAtom.remove(cellId);
|
|
623
620
|
cellDataAtom.remove(cellId);
|
|
624
621
|
cellRuntimeAtom.remove(cellId);
|
|
625
622
|
cellHandleAtom.remove(cellId);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import { EditorState, Text } from "@codemirror/state";
|
|
3
|
+
import { EditorSelection, EditorState, Text } from "@codemirror/state";
|
|
4
4
|
import type { EditorView } from "@codemirror/view";
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
6
|
import { cellId } from "@/__tests__/branded";
|
|
@@ -138,23 +138,26 @@ describe("navigate", () => {
|
|
|
138
138
|
expect(state.currentView?.range).toEqual({ from: 0, to: 5 });
|
|
139
139
|
});
|
|
140
140
|
|
|
141
|
-
it("
|
|
142
|
-
|
|
143
|
-
store.set(findReplaceAtom, {
|
|
144
|
-
type: "setCurrentView",
|
|
145
|
-
view: view1,
|
|
146
|
-
range: { from: 30, to: 35 },
|
|
147
|
-
});
|
|
141
|
+
it("skips a selection dispatch when the preceding editor is already reset", () => {
|
|
142
|
+
store.set(findReplaceAtom, { type: "setFind", find: "Different" });
|
|
148
143
|
|
|
149
|
-
|
|
144
|
+
expect(findNext()).toMatchObject({ from: 14, to: 23 });
|
|
145
|
+
expect(view1.dispatch).not.toHaveBeenCalled();
|
|
146
|
+
expect(view2.dispatch).toHaveBeenCalledOnce();
|
|
147
|
+
expect(store.get(findReplaceAtom).currentView?.cellId).toBe(cell2);
|
|
148
|
+
});
|
|
150
149
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
it("clears the preceding editor's selection when moving to another editor", () => {
|
|
151
|
+
view1 = createMockView(
|
|
152
|
+
view1.state.update({ selection: EditorSelection.single(0, 5) }).state,
|
|
153
|
+
);
|
|
154
|
+
mockGetAllEditorViews.mockReturnValue([view1, view2]);
|
|
155
|
+
store.set(findReplaceAtom, { type: "setFind", find: "Different" });
|
|
155
156
|
|
|
156
|
-
|
|
157
|
-
expect(
|
|
157
|
+
expect(findNext()).toMatchObject({ from: 14, to: 23 });
|
|
158
|
+
expect(view1.dispatch).toHaveBeenCalledExactlyOnceWith({
|
|
159
|
+
selection: EditorSelection.single(0),
|
|
160
|
+
});
|
|
158
161
|
});
|
|
159
162
|
|
|
160
163
|
it("should wrap around to beginning when reaching end", () => {
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
import { EditorState } from "@codemirror/state";
|
|
3
|
-
import {
|
|
3
|
+
import { EditorView } from "@codemirror/view";
|
|
4
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
5
|
+
import { mockIntersectionObservers } from "@/__mocks__/intersection-observer";
|
|
4
6
|
import { store } from "@/core/state/jotai";
|
|
5
|
-
import { searchState } from "../search-highlight";
|
|
7
|
+
import { searchHighlighter, searchState } from "../search-highlight";
|
|
6
8
|
import { findReplaceAtom } from "../state";
|
|
7
9
|
|
|
10
|
+
const views: EditorView[] = [];
|
|
11
|
+
|
|
8
12
|
afterEach(() => {
|
|
13
|
+
for (const view of views.splice(0)) {
|
|
14
|
+
view.destroy();
|
|
15
|
+
}
|
|
16
|
+
vi.unstubAllGlobals();
|
|
17
|
+
store.set(findReplaceAtom, { type: "setRegex", regexp: false });
|
|
9
18
|
store.set(findReplaceAtom, { type: "setIsOpen", isOpen: false });
|
|
10
19
|
store.set(findReplaceAtom, { type: "setFind", find: "" });
|
|
11
20
|
});
|
|
@@ -28,3 +37,82 @@ it("does not highlight a previous search in an editor built after the panel clos
|
|
|
28
37
|
|
|
29
38
|
expect(searchOfNewEditor()).toBe("");
|
|
30
39
|
});
|
|
40
|
+
|
|
41
|
+
it("dispatches only to visible editors and applies the latest query on return", () => {
|
|
42
|
+
const observers = mockIntersectionObservers();
|
|
43
|
+
const createView = () => {
|
|
44
|
+
const view = new EditorView({
|
|
45
|
+
parent: document.body,
|
|
46
|
+
doc: "alpha beta gamma",
|
|
47
|
+
extensions: [searchState, searchHighlighter],
|
|
48
|
+
});
|
|
49
|
+
views.push(view);
|
|
50
|
+
return view;
|
|
51
|
+
};
|
|
52
|
+
const visible = createView();
|
|
53
|
+
const offscreen = Array.from({ length: 20 }, createView);
|
|
54
|
+
const [returning, touchingViewport] = offscreen;
|
|
55
|
+
const [viewport] = observers;
|
|
56
|
+
expect(viewport.observe).toHaveBeenCalledTimes(21);
|
|
57
|
+
viewport.emit(visible.dom, true);
|
|
58
|
+
viewport.emit(returning.dom, true);
|
|
59
|
+
viewport.emit(returning.dom, false);
|
|
60
|
+
viewport.emit(touchingViewport.dom, true, 0);
|
|
61
|
+
const visibleDispatch = vi.spyOn(visible, "dispatch");
|
|
62
|
+
const offscreenDispatches = offscreen.map((view) =>
|
|
63
|
+
vi.spyOn(view, "dispatch"),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
store.set(findReplaceAtom, { type: "setIsOpen", isOpen: true });
|
|
67
|
+
for (const find of ["alpha", "beta", "g.mma"]) {
|
|
68
|
+
store.set(findReplaceAtom, { type: "setFind", find });
|
|
69
|
+
}
|
|
70
|
+
store.set(findReplaceAtom, { type: "setRegex", regexp: true });
|
|
71
|
+
|
|
72
|
+
expect(visibleDispatch).toHaveBeenCalledTimes(4);
|
|
73
|
+
expect(visible.dom.querySelector(".cm-searchMatch")?.textContent).toBe(
|
|
74
|
+
"gamma",
|
|
75
|
+
);
|
|
76
|
+
for (const dispatch of offscreenDispatches) {
|
|
77
|
+
expect(dispatch).not.toHaveBeenCalled();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
viewport.emit(returning.dom, true);
|
|
81
|
+
expect(offscreenDispatches[0]).toHaveBeenCalledOnce();
|
|
82
|
+
expect(returning.dom.querySelector(".cm-searchMatch")?.textContent).toBe(
|
|
83
|
+
"gamma",
|
|
84
|
+
);
|
|
85
|
+
viewport.emit(returning.dom, false);
|
|
86
|
+
|
|
87
|
+
store.set(findReplaceAtom, { type: "setIsOpen", isOpen: false });
|
|
88
|
+
expect(visible.dom.querySelector(".cm-searchMatch")).toBeNull();
|
|
89
|
+
expect(offscreenDispatches[0]).toHaveBeenCalledOnce();
|
|
90
|
+
viewport.emit(returning.dom, true);
|
|
91
|
+
expect(offscreenDispatches[0]).toHaveBeenCalledTimes(2);
|
|
92
|
+
expect(returning.dom.querySelector(".cm-searchMatch")).toBeNull();
|
|
93
|
+
|
|
94
|
+
store.set(findReplaceAtom, { type: "setIsOpen", isOpen: true });
|
|
95
|
+
expect(returning.dom.querySelector(".cm-searchMatch")?.textContent).toBe(
|
|
96
|
+
"gamma",
|
|
97
|
+
);
|
|
98
|
+
expect(visible.dom.querySelector(".cm-searchMatch")?.textContent).toBe(
|
|
99
|
+
"gamma",
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("unsubscribes a destroyed visible editor from viewport and query updates", () => {
|
|
104
|
+
const observers = mockIntersectionObservers();
|
|
105
|
+
const view = new EditorView({ extensions: [searchState, searchHighlighter] });
|
|
106
|
+
const [viewport] = observers;
|
|
107
|
+
viewport.emit(view.dom, true);
|
|
108
|
+
const dispatch = vi.spyOn(view, "dispatch");
|
|
109
|
+
|
|
110
|
+
view.destroy();
|
|
111
|
+
viewport.emit(view.dom, true);
|
|
112
|
+
store.set(findReplaceAtom, { type: "setIsOpen", isOpen: true });
|
|
113
|
+
store.set(findReplaceAtom, { type: "setFind", find: "alpha" });
|
|
114
|
+
|
|
115
|
+
expect(dispatch).not.toHaveBeenCalled();
|
|
116
|
+
expect(viewport.unobserve).toHaveBeenCalledExactlyOnceWith(view.dom);
|
|
117
|
+
expect(viewport.disconnect).toHaveBeenCalledOnce();
|
|
118
|
+
});
|