@marimo-team/islands 0.23.14-dev25 → 0.23.14-dev30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.23.14-dev25",
3
+ "version": "0.23.14-dev30",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -0,0 +1,33 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { describe, expect, it } from "vitest";
4
+ import type { FieldTypesWithExternalType } from "@/components/data-table/types";
5
+ import { mergeIndexFields } from "../charts";
6
+
7
+ describe("mergeIndexFields", () => {
8
+ it("appends row-header (index) fields to field types", () => {
9
+ const fieldTypes: FieldTypesWithExternalType = [["v", ["number", "int64"]]];
10
+ const rowHeaders: FieldTypesWithExternalType = [
11
+ ["k", ["string", "object"]],
12
+ ];
13
+ expect(mergeIndexFields(fieldTypes, rowHeaders)).toEqual([
14
+ ["v", ["number", "int64"]],
15
+ ["k", ["string", "object"]],
16
+ ]);
17
+ });
18
+
19
+ it("de-dupes when an index name matches a column name", () => {
20
+ const fieldTypes: FieldTypesWithExternalType = [["k", ["number", "int64"]]];
21
+ const rowHeaders: FieldTypesWithExternalType = [
22
+ ["k", ["string", "object"]],
23
+ ];
24
+ expect(mergeIndexFields(fieldTypes, rowHeaders)).toEqual([
25
+ ["k", ["number", "int64"]],
26
+ ]);
27
+ });
28
+
29
+ it("returns field types unchanged when there are no row headers", () => {
30
+ const fieldTypes: FieldTypesWithExternalType = [["v", ["number", "int64"]]];
31
+ expect(mergeIndexFields(fieldTypes, [])).toEqual(fieldTypes);
32
+ });
33
+ });
@@ -54,6 +54,24 @@ const CHART_HEIGHT = 290;
54
54
  const CHART_MAX_ROWS = 50_000;
55
55
  const CHART_MAX_COLUMNS = 50;
56
56
 
57
+ /**
58
+ * Append row-header (index) fields to the chart field list, skipping any whose
59
+ * name already exists as a data column so the chart builder never offers the
60
+ * same axis twice.
61
+ */
62
+ export function mergeIndexFields(
63
+ fieldTypes: FieldTypesWithExternalType | null | undefined,
64
+ rowHeaders: FieldTypesWithExternalType | null | undefined,
65
+ ): FieldTypesWithExternalType {
66
+ const base = fieldTypes ?? [];
67
+ if (!rowHeaders || rowHeaders.length === 0) {
68
+ return base;
69
+ }
70
+ const seen = new Set(base.map(([name]) => name));
71
+ const indexFields = rowHeaders.filter(([name]) => !seen.has(name));
72
+ return [...base, ...indexFields];
73
+ }
74
+
57
75
  export interface TablePanelProps {
58
76
  cellId: CellId | null;
59
77
  data: unknown[];
@@ -64,6 +82,7 @@ export interface TablePanelProps {
64
82
  onCloseChartBuilder?: () => void;
65
83
  getDataUrl?: GetDataUrl;
66
84
  fieldTypes?: FieldTypesWithExternalType | null;
85
+ rowHeaders?: FieldTypesWithExternalType | null;
67
86
  }
68
87
 
69
88
  export const TablePanel: React.FC<TablePanelProps> = ({
@@ -74,6 +93,7 @@ export const TablePanel: React.FC<TablePanelProps> = ({
74
93
  columns,
75
94
  getDataUrl,
76
95
  fieldTypes,
96
+ rowHeaders,
77
97
  displayHeader,
78
98
  onCloseChartBuilder,
79
99
  }) => {
@@ -265,7 +285,10 @@ export const TablePanel: React.FC<TablePanelProps> = ({
265
285
  saveChart={saveChart}
266
286
  saveChartType={saveChartType}
267
287
  getDataUrl={getDataUrl}
268
- fieldTypes={fieldTypes ?? inferFieldTypes(dataTable.props.data)}
288
+ fieldTypes={mergeIndexFields(
289
+ fieldTypes ?? inferFieldTypes(dataTable.props.data),
290
+ rowHeaders,
291
+ )}
269
292
  isLargeDataset={isLargeDataset}
270
293
  />
271
294
  </TabsContent>
@@ -35,7 +35,7 @@ import {
35
35
  import { Label } from "@/components/ui/label";
36
36
  import { NumberField } from "@/components/ui/number-field";
37
37
  import { Switch } from "@/components/ui/switch";
38
- import { outputIsLoading } from "@/core/cells/cell";
38
+ import { outputIsLoading, outputIsStale } from "@/core/cells/cell";
39
39
  import type { CellId } from "@/core/cells/ids";
40
40
  import type { AppMode } from "@/core/mode";
41
41
  import { useIsDragging } from "@/hooks/useIsDragging";
@@ -222,6 +222,7 @@ export const GridLayoutRenderer: React.FC<Props> = ({
222
222
  cellId={cell.id}
223
223
  output={cell.output}
224
224
  status={cell.status}
225
+ stale={outputIsStale(cell, false)}
225
226
  isScrollable={isScrollable}
226
227
  side={side}
227
228
  hidden={cell.errored || cell.interrupted || cell.stopped}
@@ -288,6 +289,7 @@ export const GridLayoutRenderer: React.FC<Props> = ({
288
289
  cellId={cell.id}
289
290
  output={cell.output}
290
291
  status={cell.status}
292
+ stale={outputIsStale(cell, false)}
291
293
  isScrollable={false}
292
294
  hidden={false}
293
295
  />
@@ -358,6 +360,7 @@ export const GridLayoutRenderer: React.FC<Props> = ({
358
360
  output={cell.output}
359
361
  isScrollable={false}
360
362
  status={cell.status}
363
+ stale={outputIsStale(cell, false)}
361
364
  hidden={false}
362
365
  />
363
366
  </div>
@@ -376,6 +379,7 @@ interface GridCellProps extends Pick<CellRuntimeState, "output" | "status"> {
376
379
  hidden: boolean;
377
380
  isScrollable: boolean;
378
381
  side?: GridLayoutCellSide;
382
+ stale: boolean;
379
383
  }
380
384
 
381
385
  const GridCell = memo(
@@ -389,6 +393,7 @@ const GridCell = memo(
389
393
  isScrollable,
390
394
  side,
391
395
  className,
396
+ stale,
392
397
  }: GridCellProps) => {
393
398
  const loading = outputIsLoading(status);
394
399
 
@@ -415,7 +420,7 @@ const GridCell = memo(
415
420
  allowExpand={false}
416
421
  output={output}
417
422
  cellId={cellId}
418
- stale={loading}
423
+ stale={stale}
419
424
  loading={loading}
420
425
  />
421
426
  </div>
@@ -0,0 +1,33 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { render } from "@testing-library/react";
4
+ import { describe, expect, it } from "vitest";
5
+ import type { CellId } from "@/core/cells/ids";
6
+ import type { OutputMessage } from "@/core/kernel/messages";
7
+ import type { Seconds } from "@/utils/time";
8
+ import { Slide } from "../slide";
9
+
10
+ const cellId = "cell-1" as CellId;
11
+
12
+ const output: OutputMessage = {
13
+ channel: "output",
14
+ mimetype: "text/plain",
15
+ data: "hello",
16
+ timestamp: 0 as Seconds,
17
+ };
18
+
19
+ describe("Slide", () => {
20
+ it("does not grey out the output when stale is false", () => {
21
+ const { container } = render(
22
+ <Slide cellId={cellId} status="running" output={output} stale={false} />,
23
+ );
24
+ expect(container.querySelector(".marimo-output-stale")).toBeNull();
25
+ });
26
+
27
+ it("greys out the output when stale is true", () => {
28
+ const { container } = render(
29
+ <Slide cellId={cellId} status="queued" output={output} stale={true} />,
30
+ );
31
+ expect(container.querySelector(".marimo-output-stale")).not.toBeNull();
32
+ });
33
+ });
@@ -1,6 +1,7 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { useDeleteCellCallback } from "@/components/editor/cell/useDeleteCell";
4
+ import { outputIsStale } from "@/core/cells/cell";
4
5
  import { useCellActions, useCellIds } from "@/core/cells/cells";
5
6
  import type { CellId } from "@/core/cells/ids";
6
7
  import type { CellColumnId } from "@/utils/id-tree";
@@ -670,7 +671,12 @@ const SlideThumbnailCard = ({
670
671
  {isNoOutput ? (
671
672
  <MiniCodePreview code={cell.code} />
672
673
  ) : (
673
- <Slide cellId={cell.id} status={cell.status} output={cell.output} />
674
+ <Slide
675
+ cellId={cell.id}
676
+ status={cell.status}
677
+ output={cell.output}
678
+ stale={outputIsStale(cell, false)}
679
+ />
674
680
  )}
675
681
  </div>
676
682
  )}
@@ -16,6 +16,7 @@ import { Slide as CellOutputSlide } from "@/components/slides/slide";
16
16
  import { Button } from "@/components/ui/button";
17
17
  import { useFullScreenElement } from "@/components/ui/fullscreen";
18
18
  import { Tooltip } from "@/components/ui/tooltip";
19
+ import { outputIsStale } from "@/core/cells/cell";
19
20
  import type { CellId } from "@/core/cells/ids";
20
21
  import type { RuntimeCell } from "@/core/cells/types";
21
22
  import type { RevealApi, RevealConfig } from "reveal.js";
@@ -333,6 +334,7 @@ const SubslideView = ({
333
334
  cellId={cell.id}
334
335
  status={cell.status}
335
336
  output={cell.output}
337
+ stale={outputIsStale(cell, false)}
336
338
  />
337
339
  );
338
340
  }
@@ -397,6 +399,7 @@ const ParkedPreviewContent = ({
397
399
  cellId={cell.id}
398
400
  status={cell.status}
399
401
  output={cell.output}
402
+ stale={outputIsStale(cell, false)}
400
403
  />
401
404
  );
402
405
  };
@@ -13,6 +13,7 @@ import { StopButton } from "@/components/editor/cell/StopButton";
13
13
  import { useRunCell } from "@/components/editor/cell/useRunCells";
14
14
  import { Slide as CellOutputSlide } from "@/components/slides/slide";
15
15
  import { maybeAddMarimoImport } from "@/core/cells/add-missing-import";
16
+ import { outputIsStale } from "@/core/cells/cell";
16
17
  import { useCellActions } from "@/core/cells/cells";
17
18
  import { autoInstantiateAtom, useUserConfig } from "@/core/config/config";
18
19
  import {
@@ -96,6 +97,7 @@ export const SlideCellView = ({ cell }: { cell: RuntimeCell }) => {
96
97
  cellId={cell.id}
97
98
  status={cell.status}
98
99
  output={cell.output}
100
+ stale={outputIsStale(cell, false)}
99
101
  />
100
102
  );
101
103
 
@@ -195,6 +197,7 @@ export const SlideCellReadOnlyView = ({ cell }: { cell: RuntimeCell }) => {
195
197
  cellId={cell.id}
196
198
  status={cell.status}
197
199
  output={cell.output}
200
+ stale={outputIsStale(cell, false)}
198
201
  />
199
202
  );
200
203
 
@@ -11,19 +11,22 @@ interface SlideContentProps extends Pick<
11
11
  "output" | "status"
12
12
  > {
13
13
  cellId: CellId;
14
+ stale: boolean;
14
15
  }
15
16
 
16
- export const Slide = memo(({ output, cellId, status }: SlideContentProps) => {
17
- const loading = outputIsLoading(status);
18
- return (
19
- <OutputArea
20
- className="contents"
21
- allowExpand={false}
22
- output={output}
23
- cellId={cellId}
24
- stale={loading}
25
- loading={loading}
26
- />
27
- );
28
- });
17
+ export const Slide = memo(
18
+ ({ output, cellId, status, stale }: SlideContentProps) => {
19
+ const loading = outputIsLoading(status);
20
+ return (
21
+ <OutputArea
22
+ className="contents"
23
+ allowExpand={false}
24
+ output={output}
25
+ cellId={cellId}
26
+ stale={stale}
27
+ loading={loading}
28
+ />
29
+ );
30
+ },
31
+ );
29
32
  Slide.displayName = "Slide";
@@ -805,6 +805,7 @@ export const LoadingDataTableComponent = memo(
805
805
  dataTable={dataTable}
806
806
  getDataUrl={props.get_data_url}
807
807
  fieldTypes={props.fieldTypes}
808
+ rowHeaders={props.rowHeaders}
808
809
  cellId={cellId}
809
810
  />
810
811
  ) : (
@@ -140,7 +140,8 @@ const AnyWidgetSlot = (props: IPluginProps<ModelIdRef, Data>) => {
140
140
  return null;
141
141
  }
142
142
 
143
- if (!isAnyWidgetModule(jsModule)) {
143
+ const widget = resolveAnyWidget(jsModule, jsUrl);
144
+ if (!widget) {
144
145
  return (
145
146
  <ErrorBanner error={getInvalidAnyWidgetModuleError(jsModule, jsUrl)} />
146
147
  );
@@ -150,7 +151,7 @@ const AnyWidgetSlot = (props: IPluginProps<ModelIdRef, Data>) => {
150
151
  <LoadedSlot
151
152
  // Force remount when the widget module or model changes (cell re-run).
152
153
  key={`${jsHash}:${modelId}`}
153
- widget={jsModule.default}
154
+ widget={widget}
154
155
  modelId={modelId}
155
156
  host={host}
156
157
  />
@@ -200,6 +201,55 @@ function isAnyWidgetModule(mod: any): mod is { default: AnyWidget } {
200
201
  );
201
202
  }
202
203
 
204
+ const warnedLegacyNamedExportUrls = new Set<string>();
205
+ // Cache the synthesized widget per module namespace so its identity stays
206
+ // stable across re-renders (like a default export), avoiding needless
207
+ // WidgetBinding re-initialization.
208
+ const legacyWidgetCache = new WeakMap<object, AnyWidget>();
209
+
210
+ /**
211
+ * Resolve the AnyWidget from a loaded module: prefer the AFM-spec default
212
+ * export, otherwise synthesize one from legacy named `render`/`initialize`
213
+ * exports. Returns null if neither is present.
214
+ */
215
+ function resolveAnyWidget(mod: any, jsUrl: string): AnyWidget | null {
216
+ if (isAnyWidgetModule(mod)) {
217
+ return mod.default;
218
+ }
219
+
220
+ // Only fall back to legacy (pre-AFM) named exports when there is no default
221
+ // export at all; a present-but-invalid default should surface an error
222
+ // rather than be masked.
223
+ if (mod?.default != null) {
224
+ return null;
225
+ }
226
+
227
+ const hasNamedRender = typeof mod?.render === "function";
228
+ const hasNamedInitialize = typeof mod?.initialize === "function";
229
+ if (!hasNamedRender && !hasNamedInitialize) {
230
+ return null;
231
+ }
232
+
233
+ const cached = legacyWidgetCache.get(mod);
234
+ if (cached) {
235
+ return cached;
236
+ }
237
+
238
+ if (!warnedLegacyNamedExportUrls.has(jsUrl)) {
239
+ warnedLegacyNamedExportUrls.add(jsUrl);
240
+ Logger.warn(
241
+ `Anywidget module at ${jsUrl} uses deprecated top-level named ` +
242
+ "exports (`render`/`initialize`). Per the AFM spec, use a default " +
243
+ "export instead: `export default { render }`. " +
244
+ "See https://anywidget.dev/en/afm/",
245
+ );
246
+ }
247
+
248
+ const widget: AnyWidget = { render: mod.render, initialize: mod.initialize };
249
+ legacyWidgetCache.set(mod, widget);
250
+ return widget;
251
+ }
252
+
203
253
  function getInvalidAnyWidgetModuleError(mod: unknown, jsUrl: string): Error {
204
254
  const afmDocs = "https://anywidget.dev/en/afm/";
205
255
  const hasNamedRender = isRecord(mod) && hasFunctionProperty(mod, "render");
@@ -296,5 +346,6 @@ export const visibleForTesting = {
296
346
  LoadedSlot,
297
347
  runAnyWidgetModule,
298
348
  isAnyWidgetModule,
349
+ resolveAnyWidget,
299
350
  getInvalidAnyWidgetModuleError,
300
351
  };
@@ -9,8 +9,12 @@ import { MODEL_MANAGER, Model } from "../model";
9
9
  import type { WidgetModelId } from "../types";
10
10
  import { BINDING_MANAGER } from "../widget-binding";
11
11
 
12
- const { LoadedSlot, isAnyWidgetModule, getInvalidAnyWidgetModuleError } =
13
- visibleForTesting;
12
+ const {
13
+ LoadedSlot,
14
+ isAnyWidgetModule,
15
+ resolveAnyWidget,
16
+ getInvalidAnyWidgetModuleError,
17
+ } = visibleForTesting;
14
18
 
15
19
  // Helper to create typed model IDs for tests
16
20
  const asModelId = (id: string): WidgetModelId => id as WidgetModelId;
@@ -170,6 +174,52 @@ describe("isAnyWidgetModule", () => {
170
174
  });
171
175
  });
172
176
 
177
+ describe("resolveAnyWidget", () => {
178
+ const jsUrl = "./@file/widget.js";
179
+
180
+ it("should return the default export when present", () => {
181
+ const widget = { render: () => undefined };
182
+ expect(resolveAnyWidget({ default: widget }, jsUrl)).toBe(widget);
183
+ });
184
+
185
+ it("should return a default factory function", () => {
186
+ const factory = async () => ({ render: () => {} });
187
+ expect(resolveAnyWidget({ default: factory }, jsUrl)).toBe(factory);
188
+ });
189
+
190
+ it("should synthesize a widget from a legacy named render export", () => {
191
+ const render = vi.fn();
192
+ const resolved = resolveAnyWidget({ render }, jsUrl);
193
+ expect(resolved).not.toBeNull();
194
+ expect(resolved).toMatchObject({ render });
195
+ });
196
+
197
+ it("should synthesize a widget from a legacy named initialize export", () => {
198
+ const initialize = vi.fn();
199
+ const resolved = resolveAnyWidget({ initialize }, jsUrl);
200
+ expect(resolved).not.toBeNull();
201
+ expect(resolved).toMatchObject({ initialize });
202
+ });
203
+
204
+ it("should return null for a module with no valid exports", () => {
205
+ expect(resolveAnyWidget({}, jsUrl)).toBeNull();
206
+ expect(resolveAnyWidget({ default: {} }, jsUrl)).toBeNull();
207
+ expect(resolveAnyWidget({ render: "not a function" }, jsUrl)).toBeNull();
208
+ });
209
+
210
+ it("should return a stable widget identity across calls for one module", () => {
211
+ const mod = { render: vi.fn() };
212
+ expect(resolveAnyWidget(mod, jsUrl)).toBe(resolveAnyWidget(mod, jsUrl));
213
+ });
214
+
215
+ it("should not fall back to named exports when a default export is present", () => {
216
+ // A present-but-invalid default should surface an error, not be masked.
217
+ expect(
218
+ resolveAnyWidget({ default: {}, render: vi.fn() }, jsUrl),
219
+ ).toBeNull();
220
+ });
221
+ });
222
+
173
223
  describe("getInvalidAnyWidgetModuleError", () => {
174
224
  const jsUrl = "./@file/widget.js";
175
225