@marimo-team/islands 0.25.3-dev437 → 0.25.3-dev439

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 (96) hide show
  1. package/dist/{ConnectedDataExplorerComponent-CoEU9snz.js → ConnectedDataExplorerComponent-LA5OtjAG.js} +11 -11
  2. package/dist/{ErrorBoundary-LQpWaaaj.js → ErrorBoundary-B4npV6Uy.js} +18 -18
  3. package/dist/{abnfDiagram-VCTEODGH-RbfxpmIE.js → abnfDiagram-VCTEODGH-CBntFgCZ.js} +2 -2
  4. package/dist/{any-language-editor-Cw4VtZvb.js → any-language-editor-gzDRWdCH.js} +2 -2
  5. package/dist/{architectureDiagram-5GKGNRK7-DzzNVRo4.js → architectureDiagram-5GKGNRK7-Bz6ouXl-.js} +1 -1
  6. package/dist/{assertNever-ChGm2jYv.js → assertNever-DOTNJ2Y4.js} +2 -2
  7. package/dist/{chat-ui-BEMyRpmS.js → chat-ui-2c_3M6FX.js} +45 -45
  8. package/dist/{check-BHRB6N0I.js → check-CApwK1fD.js} +1 -1
  9. package/dist/{chunk-IMKFNOWR-1Zy6M_oP.js → chunk-IMKFNOWR-DK_M66Dt.js} +1 -1
  10. package/dist/{chunk-SHT3W25Y-yAttqZEk.js → chunk-SHT3W25Y-C7Cg6zGL.js} +1 -1
  11. package/dist/{chunk-SVP7TREG-MKJpuJHR.js → chunk-SVP7TREG-K0lWia53.js} +1 -1
  12. package/dist/{chunk-TICWLB2K-BOC0OebH.js → chunk-TICWLB2K-DiKpryGp.js} +1 -1
  13. package/dist/{classDiagram-ZZMXUADV-BOlD7kH9.js → classDiagram-ZZMXUADV-CXX5eaxi.js} +2 -2
  14. package/dist/{classDiagram-v2-VYDZK3BY-C3p3seuT.js → classDiagram-v2-VYDZK3BY-Bjyy4iKL.js} +2 -2
  15. package/dist/{code-visibility-Cl2Z5Y2R.js → code-visibility-Dx3sTl1s.js} +17 -17
  16. package/dist/{common-DVxtA3e0.js → common-Cx3bd6pm.js} +4881 -4842
  17. package/dist/{config-EJnOxh0i.js → config-C8TXSDmC.js} +18 -18
  18. package/dist/{copy-icon-Bv5SAA0w.js → copy-icon-CDvvlY90.js} +2 -2
  19. package/dist/{createReducer-BJJ0K5Tu.js → createReducer-CXqSak4H.js} +1 -1
  20. package/dist/{cynefinDiagram-5FMLGOSQ-BKnxm64C.js → cynefinDiagram-5FMLGOSQ-C-MlCYj4.js} +1 -1
  21. package/dist/{dagre-GXQ25YYZ-COBTexAI.js → dagre-GXQ25YYZ-C6e9vEKZ.js} +1 -1
  22. package/dist/{data-grid-overlay-editor-FI3lYcm3.js → data-grid-overlay-editor-CqMKHPcR.js} +1 -1
  23. package/dist/{diagram-S7CK7UJ4-Dyt3J6ek.js → diagram-S7CK7UJ4-DgXNq_At.js} +1 -1
  24. package/dist/{diagram-UQ7AKVKN-CJCsT4fA.js → diagram-UQ7AKVKN-BG5NExCt.js} +1 -1
  25. package/dist/{diagram-VX7I27RA-BboxCtbh.js → diagram-VX7I27RA-Da7VYCfC.js} +1 -1
  26. package/dist/{diagram-Z3DM3KII-DfRWWQ5t.js → diagram-Z3DM3KII-DHk6GaR5.js} +1 -1
  27. package/dist/{dialog-B8vU2hHC.js → dialog-rgayPemF.js} +20 -20
  28. package/dist/{dropdown-menu-DzhAnAhr.js → dropdown-menu-B12Nf3Zf.js} +703 -703
  29. package/dist/{ebnfDiagram-PWID7BFC-DYxwv-nl.js → ebnfDiagram-PWID7BFC-DdSjinXr.js} +2 -2
  30. package/dist/{erDiagram-RLTQ6QDP-D9e5WUw7.js → erDiagram-RLTQ6QDP-BgcwfZct.js} +1 -1
  31. package/dist/{error-banner-BRkKwvku.js → error-banner-DXHIN-63.js} +58 -58
  32. package/dist/{error-entries-BbxtqUQ4.js → error-entries-CNB7O2yS.js} +455 -455
  33. package/dist/{feedback-button-1MiN6gfS.js → feedback-button-CUPrIFyj.js} +7 -7
  34. package/dist/{flowDiagram-HODETNUW-tt7EepxX.js → flowDiagram-HODETNUW-CVwzkmUF.js} +2 -2
  35. package/dist/{formats-HRSqKdFt.js → formats-BWuAsLfw.js} +1 -1
  36. package/dist/{glide-data-editor-Kt7kYQLq.js → glide-data-editor-T1r8b4Cr.js} +11 -11
  37. package/dist/{glide-utils-BzjESEmr.js → glide-utils-D1McS0Pn.js} +2 -2
  38. package/dist/{globals-BjpSYd8i.js → globals-BweO1Da5.js} +3 -3
  39. package/dist/{html-to-image-DuNAF8H5.js → html-to-image-B0UiwmMu.js} +774 -774
  40. package/dist/{infoDiagram-27XIBGKW-CpQH_joy.js → infoDiagram-27XIBGKW-CHkU2P-8.js} +1 -1
  41. package/dist/{ishikawaDiagram-5VMMS53U-d-it4xqm.js → ishikawaDiagram-5VMMS53U-B0k5UyY5.js} +1 -1
  42. package/dist/{kanban-definition-UXKFOSKX-DItpqTFY.js → kanban-definition-UXKFOSKX-DwQvOV0x.js} +1 -1
  43. package/dist/main.js +4958 -4980
  44. package/dist/{mermaid-BugOVfeH.js → mermaid-Bqy6f_NU.js} +34 -34
  45. package/dist/{mindmap-definition-YA3MSWOX-D6IpF-_J.js → mindmap-definition-YA3MSWOX-CqvvAm8I.js} +1 -1
  46. package/dist/{number-overlay-editor-BG707U9t.js → number-overlay-editor-eynzhDoK.js} +1 -1
  47. package/dist/{pegDiagram-XKGWAZYB-CXUu3QwE.js → pegDiagram-XKGWAZYB-Befnx4Ry.js} +2 -2
  48. package/dist/{pencil-DWRFEz2B.js → pencil-BC7pOv9g.js} +1 -1
  49. package/dist/{pieDiagram-E7YTZNPT-DoUJF0yj.js → pieDiagram-E7YTZNPT-6rYFbF7p.js} +1 -1
  50. package/dist/{process-output-Cl97_Reh.js → process-output-3Epq3rw6.js} +4 -4
  51. package/dist/{railroadDiagram-O6MQD6OU-BsGDhtLL.js → railroadDiagram-O6MQD6OU-SSniwYC8.js} +2 -2
  52. package/dist/{requirementDiagram-BXWQKSXE-BHW0qW2Z.js → requirementDiagram-BXWQKSXE-3L_xNfQr.js} +1 -1
  53. package/dist/{reveal-component-C8L9okWw.js → reveal-component-C-ZgAhoP.js} +900 -900
  54. package/dist/{select-Brvb-RwP.js → select-PQHWLm64.js} +99 -99
  55. package/dist/{sequenceDiagram-WJ2MYXX4-DpgYJzLl.js → sequenceDiagram-WJ2MYXX4-DvzIRlWu.js} +1 -1
  56. package/dist/{spec-BWpscSQi.js → spec-6shN7lEe.js} +4 -4
  57. package/dist/{stateDiagram-D77RDMKH-Btf1jiYb.js → stateDiagram-D77RDMKH-VsHup-Ig.js} +2 -2
  58. package/dist/{stateDiagram-v2-MP3YSRHH-DN9FyEf3.js → stateDiagram-v2-MP3YSRHH-BwIIR8nk.js} +2 -2
  59. package/dist/{static-state-BhCfPRoz.js → static-state-CWXd6dYX.js} +9 -9
  60. package/dist/{swimlanes-42K2YHIH-2l_tR9qL.js → swimlanes-42K2YHIH-DhSDCIWI.js} +1 -1
  61. package/dist/{swimlanesDiagram-VR7AAH4N-BAkmv8kE.js → swimlanesDiagram-VR7AAH4N-C2WGVm-W.js} +2 -2
  62. package/dist/{timeline-definition-24CTP7MA-AxSxEOhx.js → timeline-definition-24CTP7MA-DhUhNinO.js} +1 -1
  63. package/dist/{toast-DOWc3HtU.js → toast-BGvv7tKS.js} +153 -153
  64. package/dist/{tooltip-DsQZP310.js → tooltip-CiJ919pg.js} +62 -62
  65. package/dist/{use-restore-focus-CTa7IRP6.js → use-restore-focus-BLj45Ibw.js} +75 -75
  66. package/dist/{useDateFormatter-CRuBYwR6.js → useDateFormatter-C659lkax.js} +2 -2
  67. package/dist/{useDeepCompareMemoize-B2RNcTmn.js → useDeepCompareMemoize-CDhinwm7.js} +1 -1
  68. package/dist/{useLifecycle-Bw0JtmoB.js → useLifecycle-mKiMNa4V.js} +1 -1
  69. package/dist/{vega-component-BV9sYHhU.js → vega-component-CWvQ7wBJ.js} +6 -6
  70. package/dist/{vennDiagram-4TSXK5OY-oHztO7MH.js → vennDiagram-4TSXK5OY-exvBF8P5.js} +1 -1
  71. package/dist/{wardleyDiagram-VM6X3IG4-DWeEjZSc.js → wardleyDiagram-VM6X3IG4-BFhJmnXo.js} +1 -1
  72. package/dist/{xychartDiagram-S5SC5T6Z-ESBlsY9i.js → xychartDiagram-S5SC5T6Z-D_xAdG6u.js} +1 -1
  73. package/package.json +1 -1
  74. package/src/__mocks__/executions.ts +1 -0
  75. package/src/components/editor/controls/Controls.tsx +5 -2
  76. package/src/components/editor/notebook-cell.tsx +7 -21
  77. package/src/components/editor/renderers/grid-layout/grid-layout.tsx +2 -7
  78. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +2 -4
  79. package/src/components/slides/minimap.tsx +2 -3
  80. package/src/components/slides/reveal-component.tsx +2 -3
  81. package/src/components/slides/slide-cell-view.tsx +5 -12
  82. package/src/core/cells/__tests__/cell.test.ts +8 -51
  83. package/src/core/cells/__tests__/utils.test.ts +27 -18
  84. package/src/core/cells/cell.ts +6 -12
  85. package/src/core/cells/cells.ts +5 -3
  86. package/src/core/cells/utils.ts +61 -55
  87. package/src/core/config/config.ts +4 -0
  88. package/src/core/executions/__tests__/atoms.test.ts +0 -18
  89. package/src/core/executions/__tests__/hooks.test.tsx +48 -2
  90. package/src/core/executions/__tests__/output-lifecycle.test.ts +90 -22
  91. package/src/core/executions/__tests__/select.test.ts +0 -17
  92. package/src/core/executions/atoms.ts +51 -65
  93. package/src/core/executions/hooks.ts +24 -0
  94. package/src/core/executions/index.ts +2 -0
  95. package/src/core/executions/select.ts +0 -5
  96. package/src/core/notebook/replica/replica.ts +8 -0
@@ -15,14 +15,7 @@ import { Objects } from "@/utils/objects";
15
15
  import { isErrorMime } from "../mime";
16
16
  import type { NotebookState } from "./cells";
17
17
  import type { CellId } from "./ids";
18
-
19
- export function notebookNeedsRun(
20
- state: NotebookState,
21
- executions: CellExecutionInputs,
22
- freshness: CellFreshnessLookup,
23
- ) {
24
- return staleCellIds(state, executions, freshness).length > 0;
25
- }
18
+ import type { CellData } from "./types";
26
19
 
27
20
  export function notebookCells(state: NotebookState) {
28
21
  return state.cellIds.map((cellId) => state.cellData[cellId]);
@@ -103,35 +96,72 @@ export function getDescendantsStatus(
103
96
  };
104
97
  }
105
98
 
106
- /**
107
- * Cells that are stale and can be run.
108
- */
99
+ type RunReason = "not-run" | "source" | "inputs" | "interrupted";
100
+
101
+ export function cellRunReason(
102
+ execution: Pick<CellExecutionView, "status" | "live" | "outcome" | "blocked">,
103
+ freshness: CellFreshness,
104
+ cell: Pick<CellData, "code" | "config">,
105
+ ): RunReason | null {
106
+ if (execution.status !== "idle") {
107
+ return null;
108
+ }
109
+ if (isUninstantiated(execution) && cell.code.trim()) {
110
+ return "not-run";
111
+ }
112
+ if (freshness.sourceChanged) {
113
+ return "source";
114
+ }
115
+ if (execution.outcome === "interrupted") {
116
+ return "interrupted";
117
+ }
118
+ return freshness.inputsChanged && !cell.config.disabled && !execution.blocked
119
+ ? "inputs"
120
+ : null;
121
+ }
122
+
123
+ function* cellsNeedingRun(
124
+ state: NotebookState,
125
+ executions: CellExecutionInputs,
126
+ freshness: CellFreshnessLookup,
127
+ ): Generator<[CellId, RunReason]> {
128
+ for (const id of state.cellIds) {
129
+ const view = cellExecutionView(executions, id);
130
+ const changes = freshness(id);
131
+ const reason = cellRunReason(view, changes, state.cellData[id]);
132
+ if (reason !== null) {
133
+ yield [id, reason];
134
+ } else if (changes.sourceChanged && inFlight(executions.executions, id)) {
135
+ // The run action can submit an edit made after the host planned this cell.
136
+ yield [id, "source"];
137
+ }
138
+ }
139
+ }
140
+
109
141
  export function staleCellIds(
110
142
  state: NotebookState,
111
143
  executions: CellExecutionInputs,
112
144
  freshness: CellFreshnessLookup,
113
145
  ) {
114
- const { cellIds, cellData } = state;
115
- return cellIds.filter((cellId) => {
116
- const execution = cellExecutionView(executions, cellId);
117
- if (execution.status !== "idle") {
118
- // A run in progress covers the source it was asked for. Only an edit
119
- // since then, visible once the host has planned the run, needs another.
120
- return (
121
- inFlight(executions.executions, cellId) &&
122
- freshness(cellId).sourceChanged
123
- );
146
+ return Array.from(
147
+ cellsNeedingRun(state, executions, freshness),
148
+ ([id]) => id,
149
+ );
150
+ }
151
+
152
+ export function notebookRunReason(
153
+ state: NotebookState,
154
+ executions: CellExecutionInputs,
155
+ freshness: CellFreshnessLookup,
156
+ ): RunReason | null {
157
+ let reason: RunReason | null = null;
158
+ for (const [, pending] of cellsNeedingRun(state, executions, freshness)) {
159
+ if (pending !== "inputs") {
160
+ return pending;
124
161
  }
125
- return (
126
- isUninstantiated(execution) ||
127
- cellNeedsRun({
128
- freshness: freshness(cellId),
129
- interrupted: execution.outcome === "interrupted",
130
- disabled: cellData[cellId].config.disabled,
131
- blocked: execution.blocked,
132
- })
133
- );
134
- });
162
+ reason = pending;
163
+ }
164
+ return reason;
135
165
  }
136
166
 
137
167
  /** Whether the host holds a planned or started execution of the cell that has not completed. */
@@ -158,30 +188,6 @@ export function isUninstantiated({
158
188
  );
159
189
  }
160
190
 
161
- /**
162
- * Whether a cell needs to be run: its source changed, its last run was
163
- * interrupted, or an input changed and the cell can run. A disabled cell,
164
- * or one blocked by a disabled ancestor, is not flagged for changed inputs
165
- * until it can run again.
166
- */
167
- export function cellNeedsRun({
168
- freshness,
169
- interrupted,
170
- disabled,
171
- blocked,
172
- }: {
173
- freshness: CellFreshness;
174
- interrupted: boolean;
175
- disabled: boolean | undefined;
176
- blocked: boolean;
177
- }): boolean {
178
- return (
179
- freshness.sourceChanged ||
180
- interrupted ||
181
- (freshness.inputsChanged && !(disabled || blocked))
182
- );
183
- }
184
-
185
191
  export function cellStatusClasses({
186
192
  needsRun,
187
193
  errored,
@@ -71,6 +71,10 @@ export const resolvedMarimoConfigAtom = atom<UserConfig>((get) => {
71
71
  return mergeConfig(userConfig, overrides);
72
72
  });
73
73
 
74
+ export const autoRunOnChangeAtom = atom(
75
+ (get) => get(resolvedMarimoConfigAtom).runtime.on_cell_change === "autorun",
76
+ );
77
+
74
78
  export const autoInstantiateAtom = atom((get) => {
75
79
  return get(resolvedMarimoConfigAtom).runtime.auto_instantiate;
76
80
  });
@@ -233,24 +233,6 @@ describe("acceptRun", () => {
233
233
  expect(statusOf(store)).toBe("idle");
234
234
  });
235
235
 
236
- it("keeps waiting while the stream is between a reset and its snapshot", () => {
237
- const { store, replica } = shown();
238
- const made = request(store, [C1]);
239
- acceptRun(store, made, run([C1]));
240
-
241
- const notebook = store.get(replica.notebookAtom);
242
- store.set(replica.notebookAtom, null);
243
- const stream = store.get(replica.executionsAtom);
244
- store.set(replica.executionsAtom, { ...stream });
245
- store.set(replica.notebookAtom, notebook);
246
- expect(requested(store)).toEqual([C1]);
247
- expect(statusOf(store)).toBe("queued");
248
-
249
- store.set(replica.executionsAtom, withRuns(stream, [run([C1])]));
250
- expect(requested(store)).toEqual([]);
251
- expect(statusOf(store)).toBe("queued");
252
- });
253
-
254
236
  it("drops the request once the replica shows another notebook", () => {
255
237
  const { store, replica } = shown();
256
238
  const made = request(store, [C1]);
@@ -3,8 +3,9 @@
3
3
  import { act, renderHook } from "@testing-library/react";
4
4
  import { createStore, Provider } from "jotai";
5
5
  import type { ReactNode } from "react";
6
- import { describe, expect, it } from "vitest";
6
+ import { describe, expect, it, vi } from "vitest";
7
7
  import { MockExecutions } from "@/__mocks__/executions";
8
+ import { configOverridesAtom } from "@/core/config/config";
8
9
  import { cellId } from "@/__tests__/branded";
9
10
  import {
10
11
  cell,
@@ -12,7 +13,11 @@ import {
12
13
  withCells,
13
14
  } from "@/core/notebook/document/__tests__/fixtures";
14
15
  import { clearCellOutputs } from "../atoms";
15
- import { useCellFreshness, useCellOutput } from "../hooks";
16
+ import {
17
+ useCellFreshness,
18
+ useCellOutput,
19
+ useShowChangedInputs,
20
+ } from "../hooks";
16
21
 
17
22
  const C1 = cellId("c1");
18
23
  const C2 = cellId("c2");
@@ -106,6 +111,47 @@ describe("useCellFreshness", () => {
106
111
  });
107
112
  });
108
113
 
114
+ describe("input-change warnings", () => {
115
+ it("gives autorun time to queue a reader, but exposes an unhandled change", () => {
116
+ vi.useFakeTimers();
117
+ try {
118
+ const { wrapper, store } = setup([]);
119
+ const { result, rerender } = renderHook(
120
+ (changed: boolean) => useShowChangedInputs(changed),
121
+ {
122
+ wrapper,
123
+ initialProps: false,
124
+ },
125
+ );
126
+ rerender(true);
127
+ expect(result.current).toBe(false);
128
+ // Queued before the warning appeared.
129
+ rerender(false);
130
+ act(() => vi.runAllTimers());
131
+ expect(result.current).toBe(false);
132
+ rerender(true);
133
+ act(() => vi.runAllTimers());
134
+ expect(result.current).toBe(true);
135
+ rerender(false);
136
+ expect(result.current).toBe(false);
137
+ act(() => vi.advanceTimersByTime(50));
138
+ rerender(true);
139
+ act(() => vi.advanceTimersByTime(199));
140
+ expect(result.current).toBe(false);
141
+ act(() => vi.advanceTimersByTime(1));
142
+ expect(result.current).toBe(true);
143
+ rerender(false);
144
+ act(() =>
145
+ store.set(configOverridesAtom, { runtime: { on_cell_change: "lazy" } }),
146
+ );
147
+ rerender(true);
148
+ expect(result.current).toBe(true);
149
+ } finally {
150
+ vi.useRealTimers();
151
+ }
152
+ });
153
+ });
154
+
109
155
  describe("useCellOutput", () => {
110
156
  const shown = (id: string) =>
111
157
  MockExecutions.completed(id, {
@@ -14,7 +14,16 @@ import {
14
14
  } from "@/core/notebook/replica/__tests__/fixtures";
15
15
  import { activeNotebookReplicaAtom } from "@/core/session/active-notebook";
16
16
  import { Deferred } from "@/utils/Deferred";
17
- import { cellOutputAtom, clearCellOutputs } from "../atoms";
17
+ import {
18
+ acceptRun,
19
+ cellExecutionInputsAtom,
20
+ cellOutputAtom,
21
+ clearCellOutputs,
22
+ isCurrent,
23
+ observeCellMessage,
24
+ requestRun,
25
+ withdrawRequest,
26
+ } from "../atoms";
18
27
  import { scratchOutputView } from "../output";
19
28
 
20
29
  const C1 = cellId("c1");
@@ -24,12 +33,16 @@ const value = (data: string): Protocol.Outcome => ({
24
33
  });
25
34
 
26
35
  async function setup() {
27
- const connected = new Deferred<Parameters<NotebookTransport>[1]>();
36
+ interface Attempt {
37
+ message: Parameters<NotebookTransport>[1]["message"];
38
+ drop(): void;
39
+ }
40
+ let opened = new Deferred<Attempt>();
28
41
  const backend = fakeBackend({
29
42
  transport: ({ signal }, handlers) =>
30
43
  new Promise<void>((resolve) => {
31
44
  handlers.open();
32
- connected.resolve(handlers);
45
+ opened.resolve({ message: handlers.message, drop: resolve });
33
46
  signal.addEventListener("abort", () => resolve(), { once: true });
34
47
  }),
35
48
  });
@@ -38,7 +51,14 @@ async function setup() {
38
51
  store.set(activeNotebookReplicaAtom, replica);
39
52
  const disconnect = replica.connect(backend, { onNotification: vi.fn() });
40
53
  onTestFinished(disconnect);
41
- const { message } = await connected.promise;
54
+ let attempt = await opened.promise;
55
+ const message: Attempt["message"] = (frame) => attempt.message(frame);
56
+ const reconnect = async () => {
57
+ opened = new Deferred<Attempt>();
58
+ attempt.drop();
59
+ await vi.advanceTimersByTimeAsync(2000);
60
+ attempt = await opened.promise;
61
+ };
42
62
  let cursor = 100;
43
63
  const emit = (execution: Protocol.Execution) =>
44
64
  message({ event: "execution", id: String(++cursor), data: { execution } });
@@ -65,24 +85,76 @@ async function setup() {
65
85
  records.forEach(emit);
66
86
  message({ event: "ready", id: String(++cursor), data: {} });
67
87
  };
68
- return { store, replica, emit, remove, snapshot, message, disconnect };
88
+ return {
89
+ store,
90
+ replica,
91
+ emit,
92
+ remove,
93
+ snapshot,
94
+ message,
95
+ reconnect,
96
+ };
69
97
  }
70
98
 
71
99
  describe("output lifetime", () => {
72
- it("keeps a cleared output hidden through reset and disconnect", async () => {
73
- const { store, snapshot, message, disconnect } = await setup();
74
- const result = MockExecutions.completed(C1, { outcome: value("A") });
75
- snapshot([result]);
76
- clearCellOutputs(store, [C1]);
77
- expect(store.get(cellOutputAtom(C1))).toBeNull();
100
+ it.each(["replay", "snapshot", "in-place reset"] as const)(
101
+ "expires editor marks on %s for the same notebook",
102
+ async (recovery) => {
103
+ vi.useFakeTimers();
104
+ onTestFinished(() => {
105
+ vi.useRealTimers();
106
+ });
107
+ const { store, snapshot, message, reconnect } = await setup();
108
+ const result = MockExecutions.completed(C1, { outcome: value("A") });
109
+ snapshot([result]);
110
+ const run: Protocol.Run = {
111
+ id: "missed",
112
+ notebook_id: "n1",
113
+ runtime_id: "r1",
114
+ cells: [C1],
115
+ status: "queued",
116
+ outcome: null,
117
+ started_at: null,
118
+ completed_at: null,
119
+ };
120
+ const pending = requestRun(store, [C1])!;
121
+ acceptRun(store, pending, run);
122
+ const late = requestRun(store, [C1])!;
123
+ observeCellMessage(store, {
124
+ cell_id: C1,
125
+ status: "disabled-transitively",
126
+ timestamp: 1,
127
+ output: null,
128
+ console: null,
129
+ });
130
+ clearCellOutputs(store, [C1]);
131
+ expect(store.get(cellExecutionInputsAtom).blocked.has(C1)).toBe(true);
132
+ expect(store.get(cellOutputAtom(C1))).toBeNull();
133
+
134
+ if (recovery !== "in-place reset") {
135
+ await reconnect();
136
+ }
137
+ if (recovery !== "replay") {
138
+ snapshot([result]);
139
+ } else {
140
+ message({ event: "ready", id: "120", data: {} });
141
+ }
142
+ const { requested, blocked } = store.get(cellExecutionInputsAtom);
143
+ expect([...requested]).toEqual([]);
144
+ expect([...blocked]).toEqual([]);
145
+ expect(store.get(cellOutputAtom(C1))?.data).toBe("A");
146
+ expect(isCurrent(store, late)).toBe(false);
147
+
148
+ const current = requestRun(store, [C1])!;
149
+ acceptRun(store, late, run);
150
+ withdrawRequest(store, pending);
151
+ expect(isCurrent(store, current)).toBe(true);
152
+ expect([...store.get(cellExecutionInputsAtom).requested]).toEqual([C1]);
153
+ withdrawRequest(store, current);
154
+ expect([...store.get(cellExecutionInputsAtom).requested]).toEqual([]);
155
+ },
156
+ );
78
157
 
79
- message({ event: "reset", data: {} });
80
- expect(store.get(cellOutputAtom(C1))).toBeNull();
81
- snapshot([result]);
82
- expect(store.get(cellOutputAtom(C1))).toBeNull();
83
- disconnect();
84
- expect(store.get(cellOutputAtom(C1))).toBeNull();
85
- });
86
158
  it("keeps a changed display visible after its execution retires", async () => {
87
159
  const { store, replica, emit, remove, snapshot } = await setup();
88
160
  const result = MockExecutions.completed(C1, { outcome: value("A") });
@@ -121,14 +193,10 @@ describe("output lifetime", () => {
121
193
  };
122
194
  emit(completed);
123
195
  expect(store.get(cellOutputAtom(C1))).toBeNull();
124
- snapshot([completed]);
125
- expect(store.get(cellOutputAtom(C1))).toBeNull();
126
196
  remove(completed);
127
197
  const next = MockExecutions.running(C1);
128
198
  emit(next);
129
199
  expect(store.get(cellOutputAtom(C1))).toBeNull();
130
- snapshot([next]);
131
- expect(store.get(cellOutputAtom(C1))).toBeNull();
132
200
  emit({ ...next, outcome: value("A") });
133
201
  expect(store.get(cellOutputAtom(C1))?.data).toBe("A");
134
202
  });
@@ -110,7 +110,6 @@ describe("cellExecutionView", () => {
110
110
  outcome: null,
111
111
  startedAt: null,
112
112
  duration: null,
113
- rendered: false,
114
113
  live: true,
115
114
  });
116
115
  });
@@ -146,25 +145,10 @@ describe("cellExecutionView", () => {
146
145
  outcome: null,
147
146
  startedAt: Date.parse(T2),
148
147
  duration: null,
149
- rendered: false,
150
148
  live: true,
151
149
  });
152
150
  });
153
151
 
154
- it("notes when a running execution has shown a value so far", () => {
155
- const showing = inputs({
156
- executions: [
157
- execution({
158
- id: "e1",
159
- status: "running",
160
- outcome: { kind: "value", display: null },
161
- completed_at: null,
162
- }),
163
- ],
164
- });
165
- expect(cellExecutionView(showing, "c1").rendered).toBe(true);
166
- });
167
-
168
152
  it("says whether the notebook's runtime produced the cell's result", () => {
169
153
  const result = execution({ id: "e1" });
170
154
  const produced = (runtimeId: string | null) =>
@@ -205,7 +189,6 @@ describe("cellExecutionView", () => {
205
189
  outcome: "value",
206
190
  startedAt: Date.parse(T0),
207
191
  duration: 1500,
208
- rendered: false,
209
192
  live: true,
210
193
  });
211
194
  const error = (kind: string): Protocol.Outcome => ({
@@ -51,15 +51,9 @@ const NO_CLEARED: ReadonlyMap<Protocol.CellId, ClearedOutput> = new Map();
51
51
  interface ShownNotebook {
52
52
  readonly replica: NotebookReplica;
53
53
  readonly id: Protocol.NotebookId;
54
+ readonly generation: number;
54
55
  }
55
56
 
56
- /**
57
- * What the editor marks about cells of one replica's notebook.
58
- *
59
- * The marks refer to cells by id, which another notebook, or the same one
60
- * after a reconnect, reuses with different executions behind it. They
61
- * therefore count only for the replica and host notebook they belong to.
62
- */
63
57
  type Marks<T> = {
64
58
  readonly notebook: ShownNotebook;
65
59
  readonly value: T;
@@ -96,55 +90,44 @@ const requestsAtom = atom<Marks<ReadonlySet<RunRequest>>>(null);
96
90
  */
97
91
  const blockedCellsAtom = atom<Marks<ReadonlySet<Protocol.CellId>>>(null);
98
92
 
99
- function current<T>(
100
- marks: Marks<T>,
101
- replica: NotebookReplica | null,
102
- notebookId: Protocol.NotebookId | null,
103
- empty: T,
104
- ): T {
105
- return marks !== null &&
106
- marks.notebook.replica === replica &&
107
- marks.notebook.id === notebookId
93
+ function sameNotebook(
94
+ marked: ShownNotebook,
95
+ shown: ShownNotebook | null,
96
+ ): boolean {
97
+ return (
98
+ shown !== null &&
99
+ marked.replica === shown.replica &&
100
+ marked.id === shown.id &&
101
+ marked.generation === shown.generation
102
+ );
103
+ }
104
+
105
+ function current<T>(marks: Marks<T>, shown: ShownNotebook | null, empty: T): T {
106
+ return marks !== null && sameNotebook(marks.notebook, shown)
108
107
  ? marks.value
109
108
  : empty;
110
109
  }
111
110
 
112
- function shownNotebook(store: Pick<Store, "get">): ShownNotebook | null {
113
- const replica = store.get(activeNotebookReplicaAtom);
114
- const notebook = replica === null ? null : store.get(replica.notebookAtom);
111
+ const shownNotebookAtom = atom((get): ShownNotebook | null => {
112
+ const replica = get(activeNotebookReplicaAtom);
113
+ const notebook = replica === null ? null : get(replica.notebookAtom);
115
114
  return replica === null || notebook === null
116
115
  ? null
117
- : { replica, id: notebook.id };
118
- }
119
-
120
- function mark<T>(store: Pick<Store, "get">, value: T): Marks<T> {
121
- const notebook = shownNotebook(store);
122
- return notebook === null ? null : { notebook, value };
123
- }
116
+ : { replica, id: notebook.id, generation: get(replica.generationAtom) };
117
+ });
124
118
 
125
- /**
126
- * Whether `request` still belongs to the notebook being shown.
127
- *
128
- * Between a reset and the next snapshot the replica has no notebook for a
129
- * moment. That says nothing about where the request belongs, so it does
130
- * not count against it. Another replica, or another notebook on the same
131
- * replica, does.
132
- */
119
+ /** Whether the request still belongs to the current stream. */
133
120
  export function isCurrent(store: Store, request: RunRequest): boolean {
134
- const replica = store.get(activeNotebookReplicaAtom);
135
- if (replica !== request.notebook.replica) {
136
- return false;
137
- }
138
- const notebook = store.get(replica.notebookAtom);
139
- return notebook === null || notebook.id === request.notebook.id;
121
+ return sameNotebook(request.notebook, store.get(shownNotebookAtom));
140
122
  }
141
123
 
142
124
  /** Cells named by pending requests made in the notebook now shown. */
143
125
  const requestedCellsAtom = atom((get) => {
144
- const replica = get(activeNotebookReplicaAtom);
145
- const notebookId =
146
- replica === null ? null : (get(replica.notebookAtom)?.id ?? null);
147
- const requests = current(get(requestsAtom), replica, notebookId, NO_REQUESTS);
126
+ const requests = current(
127
+ get(requestsAtom),
128
+ get(shownNotebookAtom),
129
+ NO_REQUESTS,
130
+ );
148
131
  return requests.size === 0
149
132
  ? NO_REQUESTED
150
133
  : new Set([...requests].flatMap((request) => request.cells));
@@ -153,15 +136,13 @@ const requestedCellsAtom = atom((get) => {
153
136
  /** What every cell's view derives from. Pair with `cellExecutionView`. */
154
137
  export const cellExecutionInputsAtom = atom((get): CellExecutionInputs => {
155
138
  const replica = get(activeNotebookReplicaAtom);
156
- const notebookId =
157
- replica === null ? null : (get(replica.notebookAtom)?.id ?? null);
158
139
  const document = replica === null ? null : get(replica.shownDocumentAtom);
159
140
  return {
160
141
  executions: replica === null ? NO_EXECUTIONS : get(replica.executionsAtom),
161
142
  results: replica === null ? NO_RESULTS : get(replica.resultsAtom),
162
143
  cells: document?.cells ?? NO_CELLS,
163
144
  requested: get(requestedCellsAtom),
164
- blocked: current(get(blockedCellsAtom), replica, notebookId, NO_BLOCKED),
145
+ blocked: current(get(blockedCellsAtom), get(shownNotebookAtom), NO_BLOCKED),
165
146
  runtimeId: replica === null ? null : (get(replica.runtimeAtom)?.id ?? null),
166
147
  };
167
148
  });
@@ -195,17 +176,24 @@ const displayedNotebookAtom = atom((get): ShownNotebook | null => {
195
176
  const document = replica === null ? null : get(replica.shownDocumentAtom);
196
177
  return replica === null || document === null
197
178
  ? null
198
- : { replica, id: document.revision.notebook_id };
179
+ : {
180
+ replica,
181
+ id: document.revision.notebook_id,
182
+ generation: get(replica.generationAtom),
183
+ };
199
184
  });
200
185
 
201
186
  /** What every cell's output derives from. Pair with `cellOutputView`. */
202
187
  export const cellOutputInputsAtom = atom((get): CellOutputInputs => {
203
188
  const replica = get(activeNotebookReplicaAtom);
204
- const notebookId = get(displayedNotebookAtom)?.id ?? null;
205
189
  return {
206
190
  executions: replica === null ? NO_EXECUTIONS : get(replica.executionsAtom),
207
191
  results: replica === null ? NO_RESULTS : get(replica.resultsAtom),
208
- cleared: current(get(clearedOutputsAtom), replica, notebookId, NO_CLEARED),
192
+ cleared: current(
193
+ get(clearedOutputsAtom),
194
+ get(displayedNotebookAtom),
195
+ NO_CLEARED,
196
+ ),
209
197
  cells:
210
198
  replica === null
211
199
  ? NO_CELLS
@@ -347,18 +335,12 @@ export function requestRun(
347
335
  store: Store,
348
336
  cellIds: readonly Protocol.CellId[],
349
337
  ): RunRequest | null {
350
- const notebook = shownNotebook(store);
338
+ const notebook = store.get(shownNotebookAtom);
351
339
  if (notebook === null) {
352
340
  return null;
353
341
  }
354
342
  const request: RunRequest = { notebook, cells: [...cellIds] };
355
- const marks = store.get(requestsAtom);
356
- const kept =
357
- marks !== null &&
358
- marks.notebook.replica === notebook.replica &&
359
- marks.notebook.id === notebook.id
360
- ? marks.value
361
- : NO_REQUESTS;
343
+ const kept = current(store.get(requestsAtom), notebook, NO_REQUESTS);
362
344
  store.set(requestsAtom, { notebook, value: new Set(kept).add(request) });
363
345
  return request;
364
346
  }
@@ -385,13 +367,14 @@ export function acceptRun(
385
367
  request: RunRequest,
386
368
  run: Protocol.Run,
387
369
  ): void {
388
- const { replica } = request.notebook;
389
- const unsubscribe = store.sub(replica.executionsAtom, check);
370
+ const waitingAtom = atom(
371
+ (get) =>
372
+ sameNotebook(request.notebook, get(shownNotebookAtom)) &&
373
+ !get(request.notebook.replica.executionsAtom).runs.has(run.id),
374
+ );
375
+ const unsubscribe = store.sub(waitingAtom, check);
390
376
  function check() {
391
- if (
392
- isCurrent(store, request) &&
393
- !store.get(replica.executionsAtom).runs.has(run.id)
394
- ) {
377
+ if (store.get(waitingAtom)) {
395
378
  return;
396
379
  }
397
380
  unsubscribe();
@@ -415,7 +398,10 @@ function setCellBlocked(
415
398
  } else {
416
399
  next.delete(cellId);
417
400
  }
418
- store.set(blockedCellsAtom, mark(store, next));
401
+ const notebook = store.get(shownNotebookAtom);
402
+ if (notebook !== null) {
403
+ store.set(blockedCellsAtom, { notebook, value: next });
404
+ }
419
405
  }
420
406
 
421
407
  /**
@@ -5,6 +5,8 @@ import { dequal } from "dequal";
5
5
  import { useAtomValue } from "jotai";
6
6
  import { selectAtom } from "jotai/utils";
7
7
  import { useMemo } from "react";
8
+ import { autoRunOnChangeAtom } from "@/core/config/config";
9
+ import { useDelayElapsed } from "@/hooks/useDelayElapsed";
8
10
  import type { CellId } from "@/core/cells/ids";
9
11
  import type { Outline } from "@/core/cells/outline";
10
12
  import {
@@ -54,6 +56,28 @@ export function useCellFreshness(id: Protocol.CellId): CellFreshness {
54
56
  return useAtomValue(cellAtom);
55
57
  }
56
58
 
59
+ /** A variable revision can arrive just before the host queues its readers. */
60
+ export function useShowChangedInputs(changed: boolean): boolean {
61
+ const autorun = useAtomValue(autoRunOnChangeAtom);
62
+ const delayElapsed = useDelayElapsed(autorun && changed ? 200 : 0);
63
+ return changed && delayElapsed;
64
+ }
65
+
66
+ export function useCellPresentation(id: Protocol.CellId) {
67
+ const execution = useCellExecution(id);
68
+ const actual = useCellFreshness(id);
69
+ const inputsChanged = useShowChangedInputs(
70
+ actual.inputsChanged && execution.status === "idle",
71
+ );
72
+ return {
73
+ execution,
74
+ freshness:
75
+ inputsChanged === actual.inputsChanged
76
+ ? actual
77
+ : { ...actual, inputsChanged },
78
+ };
79
+ }
80
+
57
81
  /** What the cell shows: its running value so far, else its result's outcome. */
58
82
  export function useCellOutput(id: CellId): CellOutput | null {
59
83
  return useAtomValue(cellOutputAtom(id));