@marimo-team/islands 0.23.15-dev1 → 0.23.15-dev11

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 (34) hide show
  1. package/dist/{chat-ui-DinOvbWu.js → chat-ui-FiwuOgQU.js} +3094 -3094
  2. package/dist/{code-visibility-PV_v9dwf.js → code-visibility-HO1U02IJ.js} +171 -171
  3. package/dist/{html-to-image-_wGfk8V-.js → html-to-image-JXL8cvmt.js} +2218 -2205
  4. package/dist/main.js +327 -339
  5. package/dist/{process-output-Mh4UrjwM.js → process-output-CnDIXtM-.js} +1 -1
  6. package/dist/{reveal-component-DVEmgnsr.js → reveal-component-BuQ2GKAM.js} +2 -2
  7. package/dist/style.css +1 -1
  8. package/package.json +1 -1
  9. package/src/components/chat/__tests__/chat-utils.test.ts +244 -1
  10. package/src/components/chat/__tests__/message-queue.test.tsx +121 -0
  11. package/src/components/chat/chat-panel.tsx +196 -67
  12. package/src/components/chat/chat-utils.ts +111 -2
  13. package/src/components/editor/SortableCell.tsx +6 -2
  14. package/src/components/editor/__tests__/output-persistence.test.tsx +241 -0
  15. package/src/components/editor/cell/cell-context-menu.tsx +7 -0
  16. package/src/components/editor/columns/__tests__/cell-column.test.tsx +105 -0
  17. package/src/components/editor/columns/cell-column.tsx +34 -4
  18. package/src/components/editor/columns/sortable-column.tsx +24 -4
  19. package/src/components/editor/notebook-cell.tsx +203 -106
  20. package/src/components/editor/renderers/__tests__/cells-renderer.test.tsx +66 -0
  21. package/src/components/editor/renderers/cell-array.tsx +26 -13
  22. package/src/components/editor/renderers/cells-renderer.tsx +8 -2
  23. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +19 -19
  24. package/src/core/cells/__tests__/utils.test.ts +59 -0
  25. package/src/core/cells/utils.ts +51 -0
  26. package/src/css/app/Cell.css +10 -0
  27. package/src/hooks/__tests__/useHotkey.test.tsx +88 -0
  28. package/src/hooks/useHotkey.ts +29 -4
  29. package/src/plugins/impl/anywidget/__tests__/host.test.ts +6 -9
  30. package/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts +22 -61
  31. package/src/plugins/impl/anywidget/model-proxy.ts +0 -13
  32. package/src/plugins/impl/anywidget/widget-binding.ts +4 -34
  33. package/src/plugins/impl/matplotlib/__tests__/matplotlib-renderer.test.ts +71 -3
  34. package/src/plugins/impl/matplotlib/matplotlib-renderer.ts +1 -0
@@ -33,11 +33,14 @@ import { getReadonlyCodeDisplay } from "@/core/cells/readonly-code-display";
33
33
  import { MarkdownLanguageAdapter } from "@/core/codemirror/language/languages/markdown";
34
34
  import { useResolvedMarimoConfig } from "@/core/config/config";
35
35
  import { CSSClasses, KnownQueryParams } from "@/core/constants";
36
- import type { MarimoError, OutputMessage } from "@/core/kernel/messages";
36
+ import type { OutputMessage } from "@/core/kernel/messages";
37
37
  import { kernelStateAtom } from "@/core/kernel/state";
38
38
  import { useNotebookCodeAvailable } from "@/core/meta/code-visibility";
39
39
  import { showCodeInRunModeAtom } from "@/core/meta/state";
40
- import { isErrorMime } from "@/core/mime";
40
+ import {
41
+ publishedCellClasses,
42
+ shouldHidePublishedCell,
43
+ } from "@/core/cells/utils";
41
44
  import { type AppMode, kioskModeAtom } from "@/core/mode";
42
45
  import { useRequestClient } from "@/core/network/requests";
43
46
  import type { CellConfig } from "@/core/network/types";
@@ -362,12 +365,13 @@ const VerticalCell = memo(
362
365
  const className = cn(
363
366
  "marimo-cell",
364
367
  "hover-actions-parent empty:invisible",
365
- {
366
- published: published,
367
- "has-error": errored,
368
- stopped: stopped,
369
- borderless: isPureMarkdown && !published,
370
- },
368
+ published
369
+ ? publishedCellClasses({ errored, stopped })
370
+ : {
371
+ "has-error": errored,
372
+ stopped: stopped,
373
+ borderless: isPureMarkdown,
374
+ },
371
375
  );
372
376
 
373
377
  // Read mode and show code
@@ -419,19 +423,15 @@ const VerticalCell = memo(
419
423
  );
420
424
  }
421
425
 
422
- const outputIsError = isErrorMime(output?.mimetype);
423
426
  // When show_tracebacks is enabled, show error outputs inline
424
427
  // instead of hiding them
425
- const hasTraceback =
426
- showErrorTracebacks &&
427
- outputIsError &&
428
- Array.isArray(output?.data) &&
429
- output.data.some(
430
- (e: MarimoError) =>
431
- e.type === "exception" && "traceback" in e && e.traceback,
432
- );
433
- const hidden =
434
- (errored || interrupted || stopped || outputIsError) && !hasTraceback;
428
+ const hidden = shouldHidePublishedCell({
429
+ errored,
430
+ interrupted,
431
+ stopped,
432
+ output,
433
+ showErrorTracebacks,
434
+ });
435
435
  if (hidden) {
436
436
  return null;
437
437
  }
@@ -8,11 +8,13 @@ import {
8
8
  } from "@/core/cells/cells";
9
9
  import { CellId } from "@/core/cells/ids";
10
10
  import type { CellData, CellRuntimeState } from "@/core/cells/types";
11
+ import type { OutputMessage } from "@/core/kernel/messages";
11
12
  import { MultiColumn } from "@/utils/id-tree";
12
13
  import {
13
14
  disabledCellIds,
14
15
  enabledCellIds,
15
16
  isUninstantiated,
17
+ shouldHidePublishedCell,
16
18
  staleCellIds,
17
19
  } from "../utils";
18
20
 
@@ -426,3 +428,60 @@ describe("enabledCellIds", () => {
426
428
  expect(result).toEqual([cellId2, cellId3]);
427
429
  });
428
430
  });
431
+
432
+ describe("shouldHidePublishedCell", () => {
433
+ const base = {
434
+ errored: false,
435
+ interrupted: false,
436
+ stopped: false,
437
+ output: null,
438
+ showErrorTracebacks: false,
439
+ };
440
+ const errorOutput = (traceback?: string): OutputMessage => ({
441
+ channel: "marimo-error",
442
+ mimetype: "application/vnd.marimo+error",
443
+ data: [
444
+ { type: "exception", exception_type: "ValueError", msg: "!", traceback },
445
+ ],
446
+ timestamp: 0,
447
+ });
448
+
449
+ it("does not hide a healthy cell", () => {
450
+ expect(shouldHidePublishedCell(base)).toBe(false);
451
+ });
452
+
453
+ it.each(["errored", "interrupted", "stopped"] as const)(
454
+ "hides a %s cell",
455
+ (key) => {
456
+ expect(shouldHidePublishedCell({ ...base, [key]: true })).toBe(true);
457
+ },
458
+ );
459
+
460
+ it("hides error outputs", () => {
461
+ expect(shouldHidePublishedCell({ ...base, output: errorOutput() })).toBe(
462
+ true,
463
+ );
464
+ });
465
+
466
+ it("shows error outputs with a traceback when show_tracebacks is enabled", () => {
467
+ expect(
468
+ shouldHidePublishedCell({
469
+ ...base,
470
+ errored: true,
471
+ output: errorOutput("Traceback (most recent call last) ..."),
472
+ showErrorTracebacks: true,
473
+ }),
474
+ ).toBe(false);
475
+ });
476
+
477
+ it("hides error outputs without a traceback even when show_tracebacks is enabled", () => {
478
+ expect(
479
+ shouldHidePublishedCell({
480
+ ...base,
481
+ errored: true,
482
+ output: errorOutput(),
483
+ showErrorTracebacks: true,
484
+ }),
485
+ ).toBe(true);
486
+ });
487
+ });
@@ -2,6 +2,8 @@
2
2
 
3
3
  import type { EditorView } from "@codemirror/view";
4
4
  import { Objects } from "@/utils/objects";
5
+ import type { MarimoError, OutputMessage } from "../kernel/messages";
6
+ import { isErrorMime } from "../mime";
5
7
  import type { RuntimeState } from "../network/types";
6
8
  import type { NotebookState } from "./cells";
7
9
  import type { CellId } from "./ids";
@@ -196,3 +198,52 @@ export function cellStatusClasses({
196
198
  stale: status === "disabled-transitively",
197
199
  };
198
200
  }
201
+
202
+ /**
203
+ * Status classes for a published cell (read or present mode, output only).
204
+ */
205
+ export function publishedCellClasses({
206
+ errored,
207
+ stopped,
208
+ }: {
209
+ errored: boolean;
210
+ stopped: boolean;
211
+ }) {
212
+ return {
213
+ published: true,
214
+ "has-error": errored,
215
+ stopped: stopped,
216
+ };
217
+ }
218
+
219
+ /**
220
+ * Whether a published cell (read or present mode) should be hidden.
221
+ *
222
+ * Errored, interrupted, and stopped cells (and error outputs) are hidden in
223
+ * published views, unless `show_tracebacks` is enabled and the output carries
224
+ * an exception traceback to display inline.
225
+ */
226
+ export function shouldHidePublishedCell({
227
+ errored,
228
+ interrupted,
229
+ stopped,
230
+ output,
231
+ showErrorTracebacks,
232
+ }: {
233
+ errored: boolean;
234
+ interrupted: boolean;
235
+ stopped: boolean;
236
+ output: OutputMessage | null;
237
+ showErrorTracebacks: boolean;
238
+ }): boolean {
239
+ const outputIsError = isErrorMime(output?.mimetype);
240
+ const hasTraceback =
241
+ showErrorTracebacks &&
242
+ outputIsError &&
243
+ Array.isArray(output?.data) &&
244
+ output.data.some(
245
+ (e: MarimoError) =>
246
+ e.type === "exception" && "traceback" in e && e.traceback,
247
+ );
248
+ return (errored || interrupted || stopped || outputIsError) && !hasTraceback;
249
+ }
@@ -255,6 +255,12 @@
255
255
  border: none;
256
256
  box-shadow: none;
257
257
 
258
+ /* No dividers between sections. Tailwind v4's divide-y is structural
259
+ * (`> :not(:last-child)`), so hidden-but-mounted children (e.g. the tray
260
+ * while presenting) still count as siblings and would otherwise draw a
261
+ * stray rule under the output. */
262
+ @apply divide-y-0;
263
+
258
264
  .output-area {
259
265
  /* flow-root interferes with margin collapsing, but appears to be unneeded
260
266
  * when cell outlines are hidden; clear:both is sufficient.
@@ -443,6 +449,10 @@
443
449
  /* Set a fixed gutter width to ensure the hover area is always wide enough */
444
450
  /* And make the gutter bigger when the window is super wide */
445
451
  --gutter-width: 100px;
452
+
453
+ /* Vertical gap between notebook cells (gap-5). Overridable via custom css;
454
+ * zeroed while presenting, when published cells flow together. */
455
+ --notebook-cell-gap: 1.25rem;
446
456
  }
447
457
 
448
458
  /* ------------------------ CodeMirror Editor ----------------------------- */
@@ -0,0 +1,88 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { renderHook } from "@testing-library/react";
3
+ import { createStore, Provider } from "jotai";
4
+ import { describe, expect, it, vi } from "vitest";
5
+ import { Functions } from "@/utils/functions";
6
+ import { useHotkey } from "../useHotkey";
7
+
8
+ // global.hideCode is bound to "Mod-." by default; "mod" accepts ctrl or meta.
9
+ const SHORTCUT = "global.hideCode";
10
+
11
+ function createWrapper() {
12
+ const store = createStore();
13
+ return ({ children }: { children: React.ReactNode }) => (
14
+ <Provider store={store}>{children}</Provider>
15
+ );
16
+ }
17
+
18
+ function press() {
19
+ const event = new KeyboardEvent("keydown", {
20
+ key: ".",
21
+ ctrlKey: true,
22
+ cancelable: true,
23
+ bubbles: true,
24
+ });
25
+ document.dispatchEvent(event);
26
+ return event;
27
+ }
28
+
29
+ describe("useHotkey", () => {
30
+ it("invokes the callback and prevents default", () => {
31
+ const callback = vi.fn();
32
+ renderHook(() => useHotkey(SHORTCUT, callback), {
33
+ wrapper: createWrapper(),
34
+ });
35
+
36
+ const event = press();
37
+ expect(callback).toHaveBeenCalledOnce();
38
+ expect(event.defaultPrevented).toBe(true);
39
+ });
40
+
41
+ it("does not prevent default when the callback returns false", () => {
42
+ const callback = vi.fn(() => false);
43
+ renderHook(() => useHotkey(SHORTCUT, callback), {
44
+ wrapper: createWrapper(),
45
+ });
46
+
47
+ const event = press();
48
+ expect(callback).toHaveBeenCalledOnce();
49
+ expect(event.defaultPrevented).toBe(false);
50
+ });
51
+
52
+ it("still swallows the keystroke for NOOP catch-all handlers", () => {
53
+ renderHook(() => useHotkey(SHORTCUT, Functions.NOOP), {
54
+ wrapper: createWrapper(),
55
+ });
56
+
57
+ const event = press();
58
+ expect(event.defaultPrevented).toBe(true);
59
+ });
60
+
61
+ it("neither runs the callback nor prevents default when disabled", () => {
62
+ const callback = vi.fn();
63
+ renderHook(() => useHotkey(SHORTCUT, callback, { disabled: true }), {
64
+ wrapper: createWrapper(),
65
+ });
66
+
67
+ const event = press();
68
+ expect(callback).not.toHaveBeenCalled();
69
+ expect(event.defaultPrevented).toBe(false);
70
+ });
71
+
72
+ it("re-enables when disabled flips back to false", () => {
73
+ const callback = vi.fn();
74
+ const { rerender } = renderHook(
75
+ ({ disabled }: { disabled: boolean }) =>
76
+ useHotkey(SHORTCUT, callback, { disabled }),
77
+ { wrapper: createWrapper(), initialProps: { disabled: true } },
78
+ );
79
+
80
+ press();
81
+ expect(callback).not.toHaveBeenCalled();
82
+
83
+ rerender({ disabled: false });
84
+ const event = press();
85
+ expect(callback).toHaveBeenCalledOnce();
86
+ expect(event.defaultPrevented).toBe(true);
87
+ });
88
+ });
@@ -17,13 +17,31 @@ type HotkeyHandler = (
17
17
  // oxlint-disable-next-line typescript/no-invalid-void-type
18
18
  ) => boolean | void | undefined | Promise<void>;
19
19
 
20
+ interface HotkeyOptions {
21
+ /**
22
+ * If true, the hotkey is not handled at all: the callback does not run, the
23
+ * event's default is not prevented, and the action is not registered in the
24
+ * shortcut registry.
25
+ *
26
+ * This differs from passing `Functions.NOOP` as the callback, which still
27
+ * swallows the keystroke (preventDefault) to suppress native browser/OS
28
+ * behavior.
29
+ */
30
+ disabled?: boolean;
31
+ }
32
+
20
33
  /**
21
34
  * Registers a hotkey listener for the given shortcut.
22
35
  *
23
36
  * @param callback The callback to run when the shortcut is pressed. It does not need to be memoized as this hook will always use the latest callback.
24
37
  * If the callback returns false, preventDefault will not be called on the event.
25
38
  */
26
- export function useHotkey(shortcut: HotkeyAction, callback: HotkeyHandler) {
39
+ export function useHotkey(
40
+ shortcut: HotkeyAction,
41
+ callback: HotkeyHandler,
42
+ options: HotkeyOptions = {},
43
+ ) {
44
+ const { disabled = false } = options;
27
45
  const { registerAction, unregisterAction } = useSetRegisteredAction();
28
46
  const hotkeys = useAtomValue(hotkeysAtom);
29
47
 
@@ -31,7 +49,7 @@ export function useHotkey(shortcut: HotkeyAction, callback: HotkeyHandler) {
31
49
  const memoizeCallback = useEvent((evt?: KeyboardEvent) => callback(evt));
32
50
 
33
51
  const listener = useEvent((e: KeyboardEvent) => {
34
- if (e.defaultPrevented) {
52
+ if (disabled || e.defaultPrevented) {
35
53
  return;
36
54
  }
37
55
 
@@ -51,11 +69,18 @@ export function useHotkey(shortcut: HotkeyAction, callback: HotkeyHandler) {
51
69
 
52
70
  // Register with the shortcut registry
53
71
  useEffect(() => {
54
- if (!isNOOP) {
72
+ if (!isNOOP && !disabled) {
55
73
  registerAction(shortcut, memoizeCallback);
56
74
  return () => unregisterAction(shortcut);
57
75
  }
58
- }, [memoizeCallback, shortcut, isNOOP, registerAction, unregisterAction]);
76
+ }, [
77
+ memoizeCallback,
78
+ shortcut,
79
+ isNOOP,
80
+ disabled,
81
+ registerAction,
82
+ unregisterAction,
83
+ ]);
59
84
  }
60
85
 
61
86
  /**
@@ -277,25 +277,22 @@ describe("WidgetBinding receives a host in render props", () => {
277
277
  });
278
278
  });
279
279
 
280
- describe("host-mounted views hydrate like display-mounted ones", () => {
281
- it("replays current state to a child's render listeners", async () => {
282
- const childId = asModelId("host-hydration-child");
280
+ describe("host-mounted views", () => {
281
+ it("render with the child's current model state", async () => {
282
+ const childId = asModelId("host-child-state");
283
283
  const parentController = new AbortController();
284
284
  const getModuleSpy = vi.spyOn(WIDGET_DEF_REGISTRY, "getModule");
285
285
  try {
286
286
  const childWidget = {
287
287
  render: vi.fn(({ model, el }) => {
288
- el.textContent = "count is 5";
289
- model.on("change:count", () => {
290
- el.textContent = `count is ${model.get("count")}`;
291
- });
288
+ el.textContent = `count is ${model.get("count")}`;
292
289
  }),
293
290
  };
294
291
  const childModel = new Model<ModelState>({ count: 8 }, createMockComm());
295
292
  WIDGET_REGISTRY.setModel(childId, childModel);
296
293
  WIDGET_REGISTRY.setSpec(childId, {
297
- url: "./@file/10-host-hydration-child.js",
298
- hash: "hash-host-hydration-child",
294
+ url: "./@file/10-host-child-state.js",
295
+ hash: "hash-host-child-state",
299
296
  });
300
297
  getModuleSpy.mockResolvedValue({ default: childWidget });
301
298
 
@@ -337,13 +337,12 @@ describe("WidgetBinding", () => {
337
337
  { el: document.createElement("div") },
338
338
  { signal: controller.signal },
339
339
  );
340
- // Called once by the hydration replay at mount, once by the set.
341
340
  model.set("count", 1);
342
- expect(onCount).toHaveBeenCalledTimes(2);
341
+ expect(onCount).toHaveBeenCalledTimes(1);
343
342
 
344
343
  controller.abort();
345
344
  model.set("count", 2);
346
- expect(onCount).toHaveBeenCalledTimes(2);
345
+ expect(onCount).toHaveBeenCalledTimes(1);
347
346
  });
348
347
 
349
348
  it("should auto-clear initialize listeners on destroy", async () => {
@@ -366,92 +365,54 @@ describe("WidgetBinding", () => {
366
365
  });
367
366
  });
368
367
 
369
- describe("WidgetBinding hydration replay", () => {
370
- it("replays current state to render listeners exactly once", async () => {
368
+ describe("WidgetBinding render listeners", () => {
369
+ it("fire only for changes after mount, never for pre-existing state", async () => {
371
370
  const model = new Model<ModelState>({ count: 8 }, createMockComm());
372
- const el = document.createElement("div");
373
- const widgetDef = {
374
- render: vi.fn(({ model, el }) => {
375
- // A widget view that starts with a local default and relies on
376
- // change events for hydration.
377
- el.textContent = "count is 5";
378
- model.on("change:count", () => {
379
- el.textContent = `count is ${model.get("count")}`;
380
- });
381
- }),
382
- };
383
- const binding = await createBinding(widgetDef, model);
384
-
385
- const controller = new AbortController();
386
- await binding.createView({ el }, { signal: controller.signal });
387
- expect(el.textContent).toBe("count is 8");
388
- });
389
-
390
- it("does not re-fire listeners of already-mounted views", async () => {
391
- // Mounting view B must not double-paint view A: the replay is
392
- // scoped to the listeners the new render attached.
393
- const model = new Model<ModelState>({ count: 0 }, createMockComm());
394
- const listeners: Array<ReturnType<typeof vi.fn>> = [];
371
+ const onCount = vi.fn();
372
+ const onAnyChange = vi.fn();
395
373
  const widgetDef = {
396
374
  render: vi.fn(({ model }) => {
397
- const listener = vi.fn();
398
- listeners.push(listener);
399
- model.on("change:count", listener);
375
+ model.on("change:count", onCount);
376
+ model.on("change", onAnyChange);
400
377
  }),
401
378
  };
402
379
  const binding = await createBinding(widgetDef, model);
403
380
  const controller = new AbortController();
404
-
405
381
  await binding.createView(
406
382
  { el: document.createElement("div") },
407
383
  { signal: controller.signal },
408
384
  );
409
- expect(listeners[0]).toHaveBeenCalledTimes(1);
385
+ expect(onCount).not.toHaveBeenCalled();
386
+ expect(onAnyChange).not.toHaveBeenCalled();
410
387
 
411
- await binding.createView(
412
- { el: document.createElement("div") },
413
- { signal: controller.signal },
414
- );
415
- // View B's listener hydrated once; view A's was left alone.
416
- expect(listeners[1]).toHaveBeenCalledTimes(1);
417
- expect(listeners[0]).toHaveBeenCalledTimes(1);
388
+ model.set("count", 9);
389
+ expect(onCount).toHaveBeenCalledTimes(1);
390
+ expect(onCount).toHaveBeenCalledWith(9);
418
391
  });
419
392
 
420
- it("replays the any-change event to its listeners", async () => {
421
- const model = new Model<ModelState>({ count: 1 }, createMockComm());
422
- const onAnyChange = vi.fn();
393
+ it("mounting a second view does not fire the first view's listeners", async () => {
394
+ const model = new Model<ModelState>({ count: 0 }, createMockComm());
395
+ const listeners: Array<ReturnType<typeof vi.fn>> = [];
423
396
  const widgetDef = {
424
397
  render: vi.fn(({ model }) => {
425
- model.on("change", onAnyChange);
398
+ const listener = vi.fn();
399
+ listeners.push(listener);
400
+ model.on("change:count", listener);
426
401
  }),
427
402
  };
428
403
  const binding = await createBinding(widgetDef, model);
429
404
  const controller = new AbortController();
405
+
430
406
  await binding.createView(
431
407
  { el: document.createElement("div") },
432
408
  { signal: controller.signal },
433
409
  );
434
- expect(onAnyChange).toHaveBeenCalledTimes(1);
435
- });
436
-
437
- it("does not replay initialize listeners", async () => {
438
- // The guarantee is per-view: initialize listeners existed before
439
- // any view, and replaying at them would fire once per mount.
440
- const model = new Model<ModelState>({ count: 1 }, createMockComm());
441
- const initListener = vi.fn();
442
- const widgetDef = {
443
- initialize: vi.fn(({ model }) => {
444
- model.on("change:count", initListener);
445
- }),
446
- render: vi.fn(),
447
- };
448
- const binding = await createBinding(widgetDef, model);
449
- const controller = new AbortController();
450
410
  await binding.createView(
451
411
  { el: document.createElement("div") },
452
412
  { signal: controller.signal },
453
413
  );
454
- expect(initListener).not.toHaveBeenCalled();
414
+ expect(listeners[0]).not.toHaveBeenCalled();
415
+ expect(listeners[1]).not.toHaveBeenCalled();
455
416
  });
456
417
 
457
418
  it("clears the element before rendering into it", async () => {
@@ -5,15 +5,6 @@ import type { ModelState } from "./types";
5
5
 
6
6
  type ModelEventCallback = Parameters<AnyModel<ModelState>["on"]>[1];
7
7
 
8
- /**
9
- * A listener registered through a model proxy (see the hydration
10
- * replay in `WidgetBinding.createView`).
11
- */
12
- export interface ProxyRegistration {
13
- event: string;
14
- callback: ModelEventCallback;
15
- }
16
-
17
8
  /**
18
9
  * Wrap a model so every `on()` call from inside `initialize` or `render`
19
10
  * is auto-tied to a lifetime `AbortSignal`. When the signal aborts,
@@ -27,14 +18,11 @@ export interface ProxyRegistration {
27
18
  * The proxy is purely a host-side ergonomic helper. The widget author
28
19
  * still writes `model.on("change:foo", handler)` exactly as before; the
29
20
  * cleanup signal is supplied transparently.
30
- *
31
- * `onRegister`, when given, observes each `on()` registration.
32
21
  */
33
22
  // oxlint-disable-next-line marimo/prefer-object-params -- concise internal helper used at protocol call sites
34
23
  export function modelProxy<T extends ModelState>(
35
24
  model: AnyModel<T>,
36
25
  signal: AbortSignal,
37
- onRegister?: (registration: ProxyRegistration) => void,
38
26
  ): AnyModel<T> {
39
27
  return {
40
28
  get(key) {
@@ -55,7 +43,6 @@ export function modelProxy<T extends ModelState>(
55
43
  signal.addEventListener("abort", () => model.off(name, callback), {
56
44
  once: true,
57
45
  });
58
- onRegister?.({ event: name, callback });
59
46
  },
60
47
  off(name?: string | null, callback?: ModelEventCallback | null): void {
61
48
  model.off(name ?? null, callback ?? null);
@@ -12,7 +12,7 @@ import { isTrustedVirtualFileUrl } from "@/plugins/core/trusted-url";
12
12
  import { Logger } from "@/utils/Logger";
13
13
  import type { Host } from "./host";
14
14
  import type { Model } from "./model";
15
- import { modelProxy, type ProxyRegistration } from "./model-proxy";
15
+ import { modelProxy } from "./model-proxy";
16
16
  import type { ModelState } from "./types";
17
17
 
18
18
  export const experimental: Experimental = {
@@ -266,9 +266,8 @@ export class WidgetBinding<T extends ModelState = ModelState> {
266
266
  * when the caller's `signal` fires or the binding is destroyed, and
267
267
  * listeners registered inside `render` auto-clear on abort.
268
268
  *
269
- * Hydration guarantee: listeners attached during `render` observe
270
- * current model state exactly once, after `render` settles. Scoped
271
- * to this view's listeners; re-firing at other views double-paints.
269
+ * `render` reads current state via `model.get`; change listeners
270
+ * observe only subsequent changes, matching Jupyter semantics.
272
271
  */
273
272
  async createView(
274
273
  target: { el: HTMLElement },
@@ -305,11 +304,8 @@ export class WidgetBinding<T extends ModelState = ModelState> {
305
304
  // Each view gets a host scoped to its own signal so child views tear
306
305
  // down with this view.
307
306
  const host = this.#createHost(renderSignal);
308
- const registrations: ProxyRegistration[] = [];
309
307
  const renderCleanup = await widget.render({
310
- model: modelProxy(this.#model, renderSignal, (registration) =>
311
- registrations.push(registration),
312
- ),
308
+ model: modelProxy(this.#model, renderSignal),
313
309
  el: target.el,
314
310
  experimental,
315
311
  signal: renderSignal,
@@ -333,7 +329,6 @@ export class WidgetBinding<T extends ModelState = ModelState> {
333
329
  once: true,
334
330
  });
335
331
  }
336
- this.#replayState(registrations, renderSignal);
337
332
  }
338
333
 
339
334
  #trackCleanup(cleanup: Cleanup, reason: string): Promise<void> {
@@ -343,31 +338,6 @@ export class WidgetBinding<T extends ModelState = ModelState> {
343
338
  return task;
344
339
  }
345
340
 
346
- /**
347
- * The hydration guarantee documented on `createView`.
348
- */
349
- #replayState(
350
- registrations: readonly ProxyRegistration[],
351
- renderSignal: AbortSignal,
352
- ): void {
353
- const changePrefix = "change:";
354
- for (const { event, callback } of registrations) {
355
- if (renderSignal.aborted) {
356
- return;
357
- }
358
- try {
359
- if (event.startsWith(changePrefix)) {
360
- const key = event.slice(changePrefix.length);
361
- callback(this.#model.get(key));
362
- } else if (event === "change") {
363
- callback();
364
- }
365
- } catch (error) {
366
- Logger.error("[WidgetBinding] Error replaying state", error);
367
- }
368
- }
369
- }
370
-
371
341
  /**
372
342
  * Destroy this generation, running initialize/render cleanups and
373
343
  * clearing listeners registered through its model proxies.