@marimo-team/islands 0.26.1-dev27 → 0.26.1-dev29

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 (76) hide show
  1. package/dist/{ErrorBoundary-zpe6C93k.js → ErrorBoundary-CPcZlpvU.js} +1 -1
  2. package/dist/{chat-ui-DOvIzlMA.js → chat-ui-CWmSnBs8.js} +899 -899
  3. package/dist/{code-visibility-BtvMUvQ6.js → code-visibility-CHvnQsso.js} +2 -2
  4. package/dist/{common-B46KECgx.js → common-9OlCmjdr.js} +6565 -6565
  5. package/dist/{config-DL9e-OWE.js → config-1ku0tAiU.js} +27 -28
  6. package/dist/{data-grid-overlay-editor-CLCJ44fs.js → data-grid-overlay-editor-D6x_MBSD.js} +1 -1
  7. package/dist/{dropdown-menu-DYN2RV5d.js → dropdown-menu-D65ZUqka.js} +1983 -1983
  8. package/dist/{error-entries-CncQR572.js → error-entries-DFHEq_SO.js} +515 -519
  9. package/dist/{feedback-button-CnyHlwaY.js → feedback-button-CodkZ3hF.js} +19 -19
  10. package/dist/{glide-data-editor-C3znsea0.js → glide-data-editor-BZxvtSp-.js} +35 -35
  11. package/dist/{globals-DHoGn4Qt.js → globals-DFf-tSyE.js} +1 -1
  12. package/dist/{html-to-image-BU7H-AM1.js → html-to-image-D6Gtk5ik.js} +24005 -23992
  13. package/dist/main.js +864 -864
  14. package/dist/{number-overlay-editor-DwK5S3_f.js → number-overlay-editor-CfwFMv_U.js} +1 -1
  15. package/dist/{process-output-xJm8T5-E.js → process-output-ZBdibqlG.js} +2 -2
  16. package/dist/{reveal-component-Dsp5kSt3.js → reveal-component-CDfNuSFv.js} +3 -3
  17. package/dist/style.css +1 -1
  18. package/dist/{vega-component-DpTyTrz3.js → vega-component-D61CTW1X.js} +1 -1
  19. package/package.json +1 -1
  20. package/src/__mocks__/intersection-observer.ts +45 -0
  21. package/src/components/databases/engine-variable.tsx +2 -2
  22. package/src/components/dependency-graph/panels.tsx +2 -2
  23. package/src/components/editor/actions/useCellActionButton.tsx +2 -8
  24. package/src/components/editor/cell/code/__tests__/code-placeholder.test.tsx +40 -0
  25. package/src/components/editor/cell/code/cell-editor.tsx +41 -104
  26. package/src/components/editor/cell/code/code-placeholder.css +61 -11
  27. package/src/components/editor/cell/code/code-placeholder.tsx +52 -29
  28. package/src/components/editor/cell/useSplitCell.tsx +2 -2
  29. package/src/components/editor/chrome/wrapper/__tests__/pending-ai-cells.test.tsx +6 -10
  30. package/src/components/editor/errors/auto-fix.tsx +8 -7
  31. package/src/components/editor/navigation/__tests__/navigation.test.ts +3 -12
  32. package/src/components/editor/navigation/focus-utils.ts +20 -8
  33. package/src/components/editor/navigation/multi-cell-action-toolbar.tsx +3 -11
  34. package/src/components/editor/navigation/navigation.ts +2 -2
  35. package/src/components/editor/notebook-cell.tsx +15 -24
  36. package/src/components/editor/output/MarimoTracebackOutput.tsx +2 -2
  37. package/src/components/editor/renderers/vertical-layout/__tests__/useFocusFirstEditor.test.ts +6 -9
  38. package/src/components/editor/renderers/vertical-layout/useFocusFirstEditor.ts +2 -5
  39. package/src/components/find-replace/find-replace.tsx +3 -7
  40. package/src/components/variables/__tests__/variables-table.test.tsx +1 -2
  41. package/src/core/ai/__tests__/staged-cells.test.ts +6 -39
  42. package/src/core/ai/staged-cells.ts +2 -20
  43. package/src/core/ai/tools/__tests__/edit-notebook-tool.test.ts +15 -13
  44. package/src/core/ai/tools/edit-notebook-tool.ts +13 -8
  45. package/src/core/cells/__tests__/cell-editor-view.test.ts +44 -0
  46. package/src/core/cells/__tests__/cells.test.ts +0 -1
  47. package/src/core/cells/__tests__/focus.test.ts +1 -7
  48. package/src/core/cells/__tests__/harness.ts +0 -1
  49. package/src/core/cells/cells.ts +15 -10
  50. package/src/core/cells/focus.ts +1 -1
  51. package/src/core/cells/scrollCellIntoView.ts +4 -14
  52. package/src/core/cells/utils.ts +0 -13
  53. package/src/core/codemirror/__tests__/cell-documents.test.ts +79 -0
  54. package/src/core/codemirror/__tests__/editor-mount-scheduler.test.ts +75 -105
  55. package/src/core/codemirror/__tests__/format.test.ts +85 -63
  56. package/src/core/codemirror/__tests__/use-lazy-editor-mount.test.tsx +193 -0
  57. package/src/core/codemirror/cell-documents.ts +132 -0
  58. package/src/core/codemirror/copilot/__tests__/getCodes.test.ts +0 -1
  59. package/src/core/codemirror/copilot/getCodes.ts +3 -14
  60. package/src/core/codemirror/editor-mount-scheduler.ts +41 -48
  61. package/src/core/codemirror/extensions.ts +2 -2
  62. package/src/core/codemirror/find-replace/__tests__/navigate.test.ts +42 -16
  63. package/src/core/codemirror/find-replace/__tests__/search-highlight.test.ts +30 -0
  64. package/src/core/codemirror/find-replace/__tests__/unmounted-cells.test.ts +145 -0
  65. package/src/core/codemirror/find-replace/navigate.ts +88 -129
  66. package/src/core/codemirror/find-replace/search-highlight.ts +3 -1
  67. package/src/core/codemirror/find-replace/state.ts +7 -2
  68. package/src/core/codemirror/format.ts +25 -31
  69. package/src/core/codemirror/go-to-definition/__tests__/utils.test.ts +8 -9
  70. package/src/core/codemirror/language/cell-code.ts +7 -0
  71. package/src/core/codemirror/lsp/__tests__/notebook-lsp.test.ts +25 -0
  72. package/src/core/codemirror/lsp/notebook-lsp.ts +6 -16
  73. package/src/core/codemirror/use-lazy-editor-mount.ts +67 -0
  74. package/src/core/codemirror/utils.ts +2 -6
  75. package/src/utils/__tests__/shared-intersection-observer.test.ts +49 -0
  76. package/src/utils/shared-intersection-observer.ts +53 -0
@@ -0,0 +1,44 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { EditorView } from "@codemirror/view";
3
+ import { afterEach, expect, it, vi } from "vitest";
4
+ import { cellId } from "@/__tests__/branded";
5
+ import { editorMountScheduler } from "@/core/codemirror/editor-mount-scheduler";
6
+ import { store } from "@/core/state/jotai";
7
+ import {
8
+ ensureCellEditorView,
9
+ getCellEditorView,
10
+ initialNotebookState,
11
+ notebookAtom,
12
+ } from "../cells";
13
+
14
+ const id = cellId("cell");
15
+ const view = new EditorView();
16
+
17
+ afterEach(() => {
18
+ store.set(notebookAtom, initialNotebookState());
19
+ });
20
+
21
+ it("returns an editor only once it is built, and building is explicit", () => {
22
+ const handle = { current: { editorView: null } } as {
23
+ current: {
24
+ editorView: EditorView | null;
25
+ };
26
+ };
27
+ store.set(notebookAtom, {
28
+ ...initialNotebookState(),
29
+ cellIds: [id],
30
+ cellHandles: { [id]: handle },
31
+ });
32
+ const build = vi.fn(() => {
33
+ handle.current = { editorView: view };
34
+ });
35
+ const release = editorMountScheduler.register(id, build);
36
+
37
+ expect(getCellEditorView(id)).toBeUndefined();
38
+ expect(build).not.toHaveBeenCalled();
39
+
40
+ expect(ensureCellEditorView(id)).toBe(view);
41
+ expect(getCellEditorView(id)).toBe(view);
42
+ expect(build).toHaveBeenCalledTimes(1);
43
+ release();
44
+ });
@@ -115,7 +115,6 @@ describe("cell reducer", () => {
115
115
  const view = createEditor(state.cellData[cid].code);
116
116
  const handle: CellHandle = {
117
117
  editorView: view,
118
- editorViewOrNull: view,
119
118
  };
120
119
  state.cellHandles[cid] = { current: handle };
121
120
  }
@@ -1,6 +1,5 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
- import type { EditorView } from "@codemirror/view";
4
3
  import { createStore } from "jotai";
5
4
  import { beforeEach, describe, expect, it } from "vitest";
6
5
  import { MockNotebook } from "@/__mocks__/notebook";
@@ -282,12 +281,7 @@ describe("lastFocusedCellAtom", () => {
282
281
  const store = createStore();
283
282
  const markdownCellId = cellId("markdown");
284
283
 
285
- const unmountedEditorHandle: CellHandle = {
286
- get editorView(): EditorView {
287
- throw new ReferenceError("Attempting to dereference null object.");
288
- },
289
- editorViewOrNull: null,
290
- };
284
+ const unmountedEditorHandle: CellHandle = { editorView: null };
291
285
 
292
286
  const notebook = MockNotebook.notebookState({
293
287
  cellData: {
@@ -92,7 +92,6 @@ export function setupNotebook(
92
92
  });
93
93
  store.get(notebookAtom).cellHandles[id].current = {
94
94
  editorView: view,
95
- editorViewOrNull: view,
96
95
  };
97
96
  return view;
98
97
  },
@@ -1,5 +1,6 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
+ import type { EditorView } from "@codemirror/view";
3
4
  import type * as Protocol from "@marimo-team/client/protocol";
4
5
  import { type Atom, atom, useAtom, useAtomValue } from "jotai";
5
6
  import { atomFamily, selectAtom, splitAtom } from "jotai/utils";
@@ -325,8 +326,9 @@ const {
325
326
  };
326
327
  },
327
328
  foldAll: (state) => {
328
- const targets = Object.values(state.cellHandles).map(
329
- (handle) => handle.current?.editorView,
329
+ // A cell without an editor starts unfolded, so folding needs every editor.
330
+ const targets = Object.keys(state.cellHandles).map((cellId) =>
331
+ ensureCellEditorView(cellId as CellId),
330
332
  );
331
333
  foldAllBulk(targets);
332
334
  return state;
@@ -614,26 +616,29 @@ export const useCellHandle = (cellId: CellId) =>
614
616
  useAtomValue(cellHandleAtom(cellId));
615
617
 
616
618
  /**
617
- * Get the editor views for all cells.
619
+ * Get mounted editor views only. Read cellData for cells without an editor.
618
620
  */
619
621
  export const getAllEditorViews = () => {
620
622
  const { cellIds, cellHandles } = store.get(notebookAtom);
621
623
  return cellIds
622
- .map((cellId) => cellHandles[cellId]?.current?.editorViewOrNull)
624
+ .map((cellId) => cellHandles[cellId]?.current?.editorView)
623
625
  .filter(Boolean);
624
626
  };
625
627
 
626
- export const getCellEditorView = (cellId: CellId) => {
628
+ /** The cell's editor if it has been built; never builds one. */
629
+ export const getCellEditorView = (cellId: CellId): EditorView | undefined => {
627
630
  const { cellHandles } = store.get(notebookAtom);
628
- return cellHandles[cellId].current?.editorView;
631
+ return cellHandles[cellId]?.current?.editorView ?? undefined;
629
632
  };
630
633
 
631
634
  /**
632
- * Get the cell's editor view. When the view's build is still queued in the
633
- * progressive-mount scheduler, build it synchronously first. This lets user
634
- * actions target a cell whose editor is not mounted yet.
635
+ * The cell's editor, built synchronously first if it is still dormant. Use it
636
+ * for explicit user actions that target one cell. A freshly built editor is
637
+ * not attached to the page until React renders, so wait before focusing it.
635
638
  */
636
- export const ensureCellEditorView = (cellId: CellId) => {
639
+ export const ensureCellEditorView = (
640
+ cellId: CellId,
641
+ ): EditorView | undefined => {
637
642
  editorMountScheduler.promote(cellId);
638
643
  return getCellEditorView(cellId);
639
644
  };
@@ -110,7 +110,7 @@ function cellFocusDetails(get: Getter, cellId: CellId) {
110
110
  if (!data || !handle) {
111
111
  return null;
112
112
  }
113
- const getEditorView = () => handle.editorViewOrNull;
113
+ const getEditorView = () => handle.editorView;
114
114
  const execution = cellExecutionView(get(cellExecutionInputsAtom), cellId);
115
115
 
116
116
  return {
@@ -1,11 +1,11 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
  import type { RefObject } from "react";
3
3
  import {
4
+ focusEditor,
4
5
  isAnyCellFocused,
5
6
  tryFocus,
6
7
  } from "@/components/editor/navigation/focus-utils";
7
8
  import type { CellHandle } from "@/components/editor/notebook-cell";
8
- import { retryWithTimeout } from "@/utils/timeout";
9
9
  import { Logger } from "../../utils/Logger";
10
10
  import { editorMountScheduler } from "../codemirror/editor-mount-scheduler";
11
11
  import { scrollActiveLineIntoView } from "../codemirror/extensions";
@@ -49,8 +49,8 @@ export function focusAndScrollCellIntoView({
49
49
  // https://github.com/marimo-team/marimo/issues/2940
50
50
  tryFocus(element);
51
51
  } else {
52
- // Build this cell's editor now if it is still queued, so focus can land in
53
- // it instead of the placeholder.
52
+ // Build this cell's editor now if it is still dormant, so focus can land
53
+ // in it instead of the placeholder.
54
54
  editorMountScheduler.promote(cellId);
55
55
  const editor = cell.current?.editorView;
56
56
  if (!editor) {
@@ -63,17 +63,7 @@ export function focusAndScrollCellIntoView({
63
63
  return;
64
64
  }
65
65
 
66
- // Try to focus a few times
67
- retryWithTimeout(
68
- () => {
69
- editor.focus();
70
- return editor.hasFocus;
71
- },
72
- {
73
- retries: 5,
74
- delay: 20,
75
- },
76
- );
66
+ focusEditor(editor);
77
67
 
78
68
  if (codeFocus === "top") {
79
69
  // If codeFocus is top, move the cursor to the top of the editor.
@@ -1,6 +1,5 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
- import type { EditorView } from "@codemirror/view";
4
3
  import {
5
4
  type CellError,
6
5
  type CellExecutionInputs,
@@ -11,7 +10,6 @@ import {
11
10
  cellExecutionView,
12
11
  } from "@/core/executions";
13
12
  import type { Executions } from "@/core/notebook/replica";
14
- import { Objects } from "@/utils/objects";
15
13
  import { isErrorMime } from "../mime";
16
14
  import type { NotebookState } from "./cells";
17
15
  import type { CellId } from "./ids";
@@ -21,17 +19,6 @@ export function notebookCells(state: NotebookState) {
21
19
  return state.cellIds.map((cellId) => state.cellData[cellId]);
22
20
  }
23
21
 
24
- export function notebookCellEditorViews({ cellHandles }: NotebookState) {
25
- const views: Record<CellId, EditorView> = {};
26
- for (const [cell, ref] of Objects.entries(cellHandles)) {
27
- if (!ref.current?.editorView) {
28
- continue;
29
- }
30
- views[cell] = ref.current.editorView;
31
- }
32
- return views;
33
- }
34
-
35
22
  export function disabledCellIds(state: NotebookState) {
36
23
  const { cellIds, cellData } = state;
37
24
  const disabledCells: CellId[] = [];
@@ -0,0 +1,79 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { EditorView } from "@codemirror/view";
3
+ import { afterEach, expect, it, vi } from "vitest";
4
+ import { cellId } from "@/__tests__/branded";
5
+ import { initialNotebookState, notebookAtom } from "@/core/cells/cells";
6
+ import { createCell } from "@/core/cells/types";
7
+ import { store } from "@/core/state/jotai";
8
+ import { getCellDocuments, writeCellCode } from "../cell-documents";
9
+
10
+ const { writes } = vi.hoisted(() => ({ writes: vi.fn() }));
11
+ vi.mock("@/core/cells/actions", async () => {
12
+ const { atom } = await import("jotai");
13
+ return { setCellCodeAtom: atom(null, (_get, _set, w) => writes(w)) };
14
+ });
15
+
16
+ const id = cellId("cell");
17
+
18
+ function setNotebook(code: string, view: EditorView | null) {
19
+ store.set(notebookAtom, {
20
+ ...initialNotebookState(),
21
+ cellIds: [id],
22
+ cellData: { [id]: createCell({ id, code }) },
23
+ cellHandles: {
24
+ [id]: {
25
+ current: { editorView: view },
26
+ },
27
+ },
28
+ });
29
+ }
30
+
31
+ afterEach(() => {
32
+ writes.mockClear();
33
+ store.set(notebookAtom, initialNotebookState());
34
+ });
35
+
36
+ it("derives a document from the stored code when the cell has no editor", () => {
37
+ setNotebook('mo.md(r"""# Title""")', null);
38
+
39
+ const [document] = getCellDocuments();
40
+
41
+ expect(document.view).toBeNull();
42
+ expect(document.state.doc.toString()).toBe("# Title");
43
+ expect(document.code).toBe('mo.md(r"""# Title""")');
44
+ });
45
+
46
+ it("reads a mounted editor's document and Python code", () => {
47
+ const view = new EditorView({ doc: "x = 1" });
48
+ setNotebook("x = 1", view);
49
+
50
+ const [document] = getCellDocuments();
51
+
52
+ expect(document.view).toBe(view);
53
+ expect(document.state).toBe(view.state);
54
+ expect(document.code).toBe("x = 1");
55
+ view.destroy();
56
+ });
57
+
58
+ it("writes document changes back as the cell's Python code", () => {
59
+ setNotebook('mo.md(r"""# Title""")', null);
60
+ const [document] = getCellDocuments();
61
+
62
+ document.applyChanges({ from: 2, to: 7, insert: "Heading" }, "input");
63
+
64
+ expect(writes).toHaveBeenCalledExactlyOnceWith({
65
+ cellId: id,
66
+ code: expect.stringContaining("# Heading"),
67
+ });
68
+ expect(writes.mock.lastCall?.[0].code).toMatch(/^mo\.md\(/);
69
+ });
70
+
71
+ it("does not write code the cell already has", () => {
72
+ setNotebook("x = 1", null);
73
+
74
+ writeCellCode(id, "x = 1");
75
+ expect(writes).not.toHaveBeenCalled();
76
+
77
+ writeCellCode(id, "x = 2");
78
+ expect(writes).toHaveBeenCalledExactlyOnceWith({ cellId: id, code: "x = 2" });
79
+ });
@@ -2,142 +2,112 @@
2
2
  import { describe, expect, it } from "vitest";
3
3
  import { createEditorMountScheduler } from "../editor-mount-scheduler";
4
4
 
5
- function makeManualSchedule() {
5
+ function setup() {
6
6
  let pending: (() => void) | null = null;
7
- const schedule = (cb: () => void) => {
8
- pending = cb;
9
- };
10
7
  const flush = () => {
11
- const cb = pending;
8
+ const task = pending;
12
9
  pending = null;
13
- cb?.();
10
+ task?.();
14
11
  };
15
- return { schedule, flush, hasPending: () => pending !== null };
12
+ const scheduler = createEditorMountScheduler((task) => {
13
+ pending = task;
14
+ });
15
+ const built: string[] = [];
16
+ const register = (cellId: string) =>
17
+ scheduler.register(cellId, () => built.push(cellId));
18
+ return { scheduler, register, built, flush, hasPending: () => !!pending };
16
19
  }
17
20
 
18
21
  describe("createEditorMountScheduler", () => {
19
- it("builds one queued editor per tick in FIFO order, rescheduling between", () => {
20
- const { schedule, flush, hasPending } = makeManualSchedule();
21
- const built: string[] = [];
22
- const s = createEditorMountScheduler(schedule);
23
- s.request("a", () => built.push("a"));
24
- s.request("b", () => built.push("b"));
25
- flush();
26
- expect(built).toEqual(["a"]);
27
- expect(hasPending()).toBe(true);
28
- flush();
29
- expect(built).toEqual(["a", "b"]);
30
- });
22
+ it("keeps registrations dormant until prioritized or promoted", () => {
23
+ const { scheduler, register, built, flush, hasPending } = setup();
24
+ register("a");
25
+ register("b");
26
+ register("c");
27
+ expect(hasPending()).toBe(false);
31
28
 
32
- it("stops rescheduling once the queue is empty", () => {
33
- const { schedule, flush, hasPending } = makeManualSchedule();
34
- const built: string[] = [];
35
- const s = createEditorMountScheduler(schedule);
36
- s.request("a", () => built.push("a"));
29
+ scheduler.prioritize("b");
37
30
  flush();
38
- expect(built).toEqual(["a"]);
31
+ expect(built).toEqual(["b"]);
39
32
  expect(hasPending()).toBe(false);
33
+
34
+ scheduler.promote("c");
35
+ scheduler.promote("c");
36
+ expect(built).toEqual(["b", "c"]);
40
37
  });
41
38
 
42
- it("promote builds immediately and removes from the queue", () => {
43
- const { schedule, flush } = makeManualSchedule();
44
- const built: string[] = [];
45
- const s = createEditorMountScheduler(schedule);
46
- s.request("a", () => built.push("a"));
47
- s.request("b", () => built.push("b"));
48
- s.promote("b");
49
- expect(built).toEqual(["b"]);
39
+ it("builds prioritized cells one per task, in prioritization order", () => {
40
+ const { scheduler, register, built, flush, hasPending } = setup();
41
+ register("a");
42
+ register("b");
43
+ register("c");
44
+ scheduler.prioritize("c");
45
+ scheduler.prioritize("a");
46
+ flush();
47
+ expect(built).toEqual(["c"]);
48
+ expect(hasPending()).toBe(true);
50
49
  flush();
51
- expect(built).toEqual(["b", "a"]);
50
+ expect(built).toEqual(["c", "a"]);
51
+ expect(hasPending()).toBe(false);
52
52
  });
53
53
 
54
- it("cancel prevents a queued build", () => {
55
- const { schedule, flush } = makeManualSchedule();
56
- const built: string[] = [];
57
- const s = createEditorMountScheduler(schedule);
58
- s.request("a", () => built.push("a"));
59
- s.cancel("a");
60
- flush();
54
+ it("does not build a cell that was deprioritized or disposed", () => {
55
+ const { scheduler, register, built, flush } = setup();
56
+ register("a");
57
+ const disposeB = register("b");
58
+ scheduler.prioritize("a");
59
+ scheduler.deprioritize("a");
60
+ scheduler.prioritize("b");
61
+ disposeB();
62
+ flush();
63
+ scheduler.promote("b");
61
64
  expect(built).toEqual([]);
62
- });
63
65
 
64
- it("builds prioritized cells before earlier-queued ones", () => {
65
- const { schedule, flush } = makeManualSchedule();
66
- const built: string[] = [];
67
- const s = createEditorMountScheduler(schedule);
68
- s.request("a", () => built.push("a"));
69
- s.request("b", () => built.push("b"));
70
- s.request("c", () => built.push("c"));
71
- s.prioritize("c");
72
- flush();
66
+ scheduler.prioritize("a");
73
67
  flush();
74
- flush();
75
- expect(built).toEqual(["c", "a", "b"]);
68
+ expect(built).toEqual(["a"]);
76
69
  });
77
70
 
78
- it("builds multiple prioritized cells in prioritization order, then FIFO", () => {
79
- const { schedule, flush } = makeManualSchedule();
80
- const built: string[] = [];
81
- const s = createEditorMountScheduler(schedule);
82
- s.request("a", () => built.push("a"));
83
- s.request("b", () => built.push("b"));
84
- s.request("c", () => built.push("c"));
85
- s.request("d", () => built.push("d"));
86
- s.prioritize("d");
87
- s.prioritize("b");
88
- flush();
89
- flush();
90
- flush();
91
- flush();
92
- expect(built).toEqual(["d", "b", "a", "c"]);
71
+ it("ignores prioritize for a cell that is not registered", () => {
72
+ const { scheduler, hasPending } = setup();
73
+ scheduler.prioritize("missing");
74
+ expect(hasPending()).toBe(false);
93
75
  });
94
76
 
95
- it("ignores prioritize for a cell that is not queued", () => {
96
- const { schedule, flush } = makeManualSchedule();
97
- const built: string[] = [];
98
- const s = createEditorMountScheduler(schedule);
99
- s.request("a", () => built.push("a"));
100
- s.prioritize("not-queued");
101
- flush();
102
- expect(built).toEqual(["a"]);
77
+ it("lets a stale or repeated disposal leave a replacement registration alone", () => {
78
+ const { scheduler, built, flush } = setup();
79
+ const stale = scheduler.register("a", () => built.push("stale"));
80
+ const current = scheduler.register("a", () => built.push("current"));
81
+ stale();
82
+ stale();
83
+ scheduler.prioritize("a");
84
+ flush();
85
+ current();
86
+ expect(built).toEqual(["current"]);
103
87
  });
104
88
 
105
- it("deprioritize reverts a cell to FIFO order without dropping it", () => {
106
- const { schedule, flush } = makeManualSchedule();
107
- const built: string[] = [];
108
- const s = createEditorMountScheduler(schedule);
109
- s.request("a", () => built.push("a"));
110
- s.request("b", () => built.push("b"));
111
- s.prioritize("b");
112
- s.deprioritize("b");
113
- flush();
89
+ it("allows a build to register new work for the same cell", () => {
90
+ const { scheduler, built, flush } = setup();
91
+ scheduler.register("a", () => {
92
+ built.push("first");
93
+ scheduler.register("a", () => built.push("second"));
94
+ });
95
+ scheduler.promote("a");
96
+ scheduler.promote("a");
114
97
  flush();
115
- expect(built).toEqual(["a", "b"]);
98
+ expect(built).toEqual(["first", "second"]);
116
99
  });
117
100
 
118
- it("keeps draining the queue after a build throws", () => {
119
- const { schedule, flush } = makeManualSchedule();
120
- const built: string[] = [];
121
- const s = createEditorMountScheduler(schedule);
122
- s.request("a", () => {
101
+ it("keeps draining prioritized cells after a build throws", () => {
102
+ const { scheduler, register, built, flush } = setup();
103
+ scheduler.register("a", () => {
123
104
  throw new Error("boom");
124
105
  });
125
- s.request("b", () => built.push("b"));
106
+ register("b");
107
+ scheduler.prioritize("a");
108
+ scheduler.prioritize("b");
126
109
  expect(() => flush()).toThrow("boom");
127
110
  flush();
128
111
  expect(built).toEqual(["b"]);
129
112
  });
130
-
131
- it("cancel removes a prioritized cell", () => {
132
- const { schedule, flush } = makeManualSchedule();
133
- const built: string[] = [];
134
- const s = createEditorMountScheduler(schedule);
135
- s.request("a", () => built.push("a"));
136
- s.request("b", () => built.push("b"));
137
- s.prioritize("b");
138
- s.cancel("b");
139
- flush();
140
- flush();
141
- expect(built).toEqual(["a"]);
142
- });
143
113
  });