@marimo-team/frontend 0.23.10-dev51 → 0.23.10-dev52

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 (83) hide show
  1. package/dist/assets/{CellStatus-BKK6G_iZ.js → CellStatus-BOTR_HB4.js} +1 -1
  2. package/dist/assets/{JsonOutput-CZQlutzs.js → JsonOutput-DOmfCaR3.js} +6 -6
  3. package/dist/assets/{MarimoErrorOutput-DIx3jD4Z.js → MarimoErrorOutput-Ca2QF99G.js} +2 -2
  4. package/dist/assets/{RenderHTML-B5i6Qdbh.js → RenderHTML-CXsJP1V5.js} +1 -1
  5. package/dist/assets/{RunButton-DLMH3KLF.js → RunButton-jGowD7Vi.js} +1 -1
  6. package/dist/assets/{add-cell-with-ai-BXpVenBx.js → add-cell-with-ai-BK11442L.js} +9 -9
  7. package/dist/assets/{add-connection-dialog-C_jDtIZF.js → add-connection-dialog-wzfYao2B.js} +1 -1
  8. package/dist/assets/{agent-panel-Ck0iPpUN.js → agent-panel-CgxV6vbd.js} +4 -4
  9. package/dist/assets/{ai-model-dropdown-CXNYq3J_.js → ai-model-dropdown-CqqTe6eF.js} +3 -3
  10. package/dist/assets/{app-config-button-BI_m1lzO.js → app-config-button-vSxYsM--.js} +1 -1
  11. package/dist/assets/cell-editor-BHNVF2sX.js +21 -0
  12. package/dist/assets/{cell-editor-Iey559K_.css → cell-editor-nqEF4IhQ.css} +1 -1
  13. package/dist/assets/{cell-link-spbX-mlL.js → cell-link-iYZiKtn4.js} +1 -1
  14. package/dist/assets/{cells-k7Js5h2t.js → cells-CoFnpuSu.js} +56 -56
  15. package/dist/assets/{chat-display-BlIrSb3b.js → chat-display-BgSnZSro.js} +1 -1
  16. package/dist/assets/{chat-panel-DtYOU7td.js → chat-panel-AZ1shEWX.js} +1 -1
  17. package/dist/assets/{chat-ui-CivhPCag.js → chat-ui-By5846Od.js} +1 -1
  18. package/dist/assets/{column-preview-DM1s1Z9h.js → column-preview-TS1GqZH2.js} +1 -1
  19. package/dist/assets/{command-palette-BtdM4b5O.js → command-palette-By31pA-R.js} +1 -1
  20. package/dist/assets/{common-Zqa_rd3u.js → common-Q-jtFQpL.js} +1 -1
  21. package/dist/assets/components--CWsNwF4.js +1 -0
  22. package/dist/assets/{datasource-mov7mYsn.js → datasource-CQiCeDJW.js} +2 -2
  23. package/dist/assets/{dependency-graph-panel-1c-_VkGM.js → dependency-graph-panel-Ct3KN-vZ.js} +4 -4
  24. package/dist/assets/documentation-panel-D8h8iNHa.js +1 -0
  25. package/dist/assets/{download-BS31LU22.js → download-B10yQcVE.js} +4 -4
  26. package/dist/assets/{edit-page-BQl0d1fo.js → edit-page-p8VsTwE3.js} +6 -6
  27. package/dist/assets/{error-panel-DmfYCEYR.js → error-panel-DYEkqXfY.js} +1 -1
  28. package/dist/assets/{file-explorer-panel-DGL7dM6k.js → file-explorer-panel-GJ_Lqi4C.js} +3 -3
  29. package/dist/assets/{file-icons-on-PIYta.js → file-icons-CtmUbkxd.js} +1 -1
  30. package/dist/assets/{file-name-input-D-E8LtaP.js → file-name-input-CHQhxLcF.js} +1 -1
  31. package/dist/assets/{floating-outline-CCH9y0X9.js → floating-outline-CzBp8YHO.js} +1 -1
  32. package/dist/assets/{focus-CRI5ilWC.js → focus-CjgVplbV.js} +1 -1
  33. package/dist/assets/{form-HcuPVpyt.js → form-WbviP6l9.js} +2 -2
  34. package/dist/assets/{home-page-CVKp7bjJ.js → home-page-sFt3WKqc.js} +2 -2
  35. package/dist/assets/{hooks-C1zkcVIj.js → hooks-0dN8JCy2.js} +1 -1
  36. package/dist/assets/{html-to-image-rLeQGF-G.js → html-to-image-DkJzNEld.js} +2 -2
  37. package/dist/assets/{index-44I991hQ.js → index-CdnLLLYn.js} +6 -6
  38. package/dist/assets/kiosk-mode-lr7kYrA8.js +1 -0
  39. package/dist/assets/{layout-C9L0bRP-.js → layout-BVZ3DZze.js} +5 -5
  40. package/dist/assets/{logs-panel-KFtLFK9O.js → logs-panel-Bk20lglR.js} +1 -1
  41. package/dist/assets/{markdown-renderer-BHa-Tbwi.js → markdown-renderer-DC51vSBA.js} +2 -2
  42. package/dist/assets/{name-cell-input-DyUkpM9d.js → name-cell-input-D0WKoNHr.js} +1 -1
  43. package/dist/assets/{outline-panel-DdPSzT5z.js → outline-panel-BuJMW1Dz.js} +1 -1
  44. package/dist/assets/{packages-panel-Bt88BnuF.js → packages-panel-BNk0bPl9.js} +1 -1
  45. package/dist/assets/{panels-DDvVhmjS.js → panels-CBe83v0S.js} +1 -1
  46. package/dist/assets/process-output-BiJLba4m.js +1 -0
  47. package/dist/assets/{radio-group-DS_mmqHJ.js → radio-group-RRco4zNE.js} +1 -1
  48. package/dist/assets/{readonly-python-code-3HZIBvHp.js → readonly-python-code-Crki_rLb.js} +1 -1
  49. package/dist/assets/{reveal-component-Hsm6-onk.js → reveal-component-Bv08TPRa.js} +9 -9
  50. package/dist/assets/{run-page-DeHIvt79.js → run-page-BdSzJWEw.js} +1 -1
  51. package/dist/assets/{scratchpad-panel-CKmA2mRq.js → scratchpad-panel-scHa4am5.js} +1 -1
  52. package/dist/assets/{session-panel-B0jBqtOA.js → session-panel-D0o5h-7L.js} +1 -1
  53. package/dist/assets/{snippets-panel-BGtSLFha.js → snippets-panel-Bnmi-xyF.js} +1 -1
  54. package/dist/assets/{state-C9ggN1rs.js → state-CHxBK47b.js} +1 -1
  55. package/dist/assets/{state-Dy-doCBq.js → state-CsD5BRG0.js} +2 -2
  56. package/dist/assets/{textarea-BfDUjd9c.js → textarea-DoKXC-jv.js} +1 -1
  57. package/dist/assets/{tracing-DNuuRjp_.js → tracing-BeWtlIAf.js} +1 -1
  58. package/dist/assets/{tracing-panel-CnlPrcNd.js → tracing-panel-ecc7OtVi.js} +2 -2
  59. package/dist/assets/{tree-actions-XvgFV23w.js → tree-actions-wXUHKee-.js} +1 -1
  60. package/dist/assets/{useCellActionButton-DNDYDKvS.js → useCellActionButton-Bn5MJUE0.js} +1 -1
  61. package/dist/assets/{useDeleteCell-cucOoAuB.js → useDeleteCell-DQCclxQO.js} +1 -1
  62. package/dist/assets/useDependencyPanelTab-CgHa5PER.js +1 -0
  63. package/dist/assets/{useNotebookActions-ClLcZA5r.js → useNotebookActions-CxBMp6mq.js} +1 -1
  64. package/dist/assets/useRunCells-Ck2FcYV8.js +1 -0
  65. package/dist/assets/useSplitCell-4cXAawGz.js +1 -0
  66. package/dist/index.html +22 -22
  67. package/package.json +1 -1
  68. package/src/__tests__/setup.ts +16 -0
  69. package/src/components/editor/cell/code/cell-editor.tsx +67 -32
  70. package/src/components/editor/cell/code/code-placeholder.css +17 -0
  71. package/src/components/editor/cell/code/code-placeholder.tsx +46 -0
  72. package/src/core/cells/scrollCellIntoView.ts +4 -0
  73. package/src/core/codemirror/__tests__/editor-mount-scheduler.test.ts +142 -0
  74. package/src/core/codemirror/editor-mount-scheduler.ts +100 -0
  75. package/src/utils/schedule-task.ts +70 -0
  76. package/dist/assets/cell-editor-DYta_icE.js +0 -20
  77. package/dist/assets/components-CXG-2UWv.js +0 -1
  78. package/dist/assets/documentation-panel-CQ8pDf0n.js +0 -1
  79. package/dist/assets/kiosk-mode-DhNcHA04.js +0 -1
  80. package/dist/assets/process-output-CRgRzt0h.js +0 -1
  81. package/dist/assets/useDependencyPanelTab-Bu76tcmV.js +0 -1
  82. package/dist/assets/useRunCells-CVd2QKS9.js +0 -1
  83. package/dist/assets/useSplitCell-D1KubWSa.js +0 -1
package/dist/index.html CHANGED
@@ -66,7 +66,7 @@
66
66
  <marimo-server-token data-token="{{ server_token }}" hidden></marimo-server-token>
67
67
  <!-- /TODO -->
68
68
  <title>{{ title }}</title>
69
- <script type="module" crossorigin src="./assets/index-44I991hQ.js"></script>
69
+ <script type="module" crossorigin src="./assets/index-CdnLLLYn.js"></script>
70
70
  <link rel="modulepreload" crossorigin href="./assets/preload-helper-BPPi7vOr.js">
71
71
  <link rel="modulepreload" crossorigin href="./assets/chunk-LvLJmgfZ.js">
72
72
  <link rel="modulepreload" crossorigin href="./assets/react-Bj1aDYRI.js">
@@ -133,7 +133,7 @@
133
133
  <link rel="modulepreload" crossorigin href="./assets/debounce-DhnxH9Rh.js">
134
134
  <link rel="modulepreload" crossorigin href="./assets/database-zap-kIkTfzTX.js">
135
135
  <link rel="modulepreload" crossorigin href="./assets/main-B0OX4z33.js">
136
- <link rel="modulepreload" crossorigin href="./assets/cells-k7Js5h2t.js">
136
+ <link rel="modulepreload" crossorigin href="./assets/cells-CoFnpuSu.js">
137
137
  <link rel="modulepreload" crossorigin href="./assets/ErrorBoundary-DyYDV0HI.js">
138
138
  <link rel="modulepreload" crossorigin href="./assets/kbd-CTUAEnEx.js">
139
139
  <link rel="modulepreload" crossorigin href="./assets/useInstallPackage-GI6gu7_S.js">
@@ -147,38 +147,38 @@
147
147
  <link rel="modulepreload" crossorigin href="./assets/usePress-DQ_tAz5W.js">
148
148
  <link rel="modulepreload" crossorigin href="./assets/input-DA8xlX70.js">
149
149
  <link rel="modulepreload" crossorigin href="./assets/ImperativeModal-BW1dmntO.js">
150
- <link rel="modulepreload" crossorigin href="./assets/cell-link-spbX-mlL.js">
150
+ <link rel="modulepreload" crossorigin href="./assets/cell-link-iYZiKtn4.js">
151
151
  <link rel="modulepreload" crossorigin href="./assets/multi-map-C4OANz8X.js">
152
152
  <link rel="modulepreload" crossorigin href="./assets/alert-yTS3WpF4.js">
153
153
  <link rel="modulepreload" crossorigin href="./assets/chevron-right-CG5QYXYk.js">
154
154
  <link rel="modulepreload" crossorigin href="./assets/dropdown-menu-CZ4XbE-c.js">
155
155
  <link rel="modulepreload" crossorigin href="./assets/links-D1JoyKTt.js">
156
- <link rel="modulepreload" crossorigin href="./assets/useRunCells-CVd2QKS9.js">
156
+ <link rel="modulepreload" crossorigin href="./assets/useRunCells-Ck2FcYV8.js">
157
157
  <link rel="modulepreload" crossorigin href="./assets/copy-LK56fFow.js">
158
158
  <link rel="modulepreload" crossorigin href="./assets/copy-BwrPA9zQ.js">
159
159
  <link rel="modulepreload" crossorigin href="./assets/copy-icon-BuRdHNPA.js">
160
- <link rel="modulepreload" crossorigin href="./assets/RenderHTML-B5i6Qdbh.js">
161
- <link rel="modulepreload" crossorigin href="./assets/datasource-mov7mYsn.js">
162
- <link rel="modulepreload" crossorigin href="./assets/state-C9ggN1rs.js">
160
+ <link rel="modulepreload" crossorigin href="./assets/RenderHTML-CXsJP1V5.js">
161
+ <link rel="modulepreload" crossorigin href="./assets/datasource-CQiCeDJW.js">
162
+ <link rel="modulepreload" crossorigin href="./assets/state-CHxBK47b.js">
163
163
  <link rel="modulepreload" crossorigin href="./assets/package-Tv6ztuzw.js">
164
164
  <link rel="modulepreload" crossorigin href="./assets/sparkles-lWUAsPhp.js">
165
- <link rel="modulepreload" crossorigin href="./assets/MarimoErrorOutput-DIx3jD4Z.js">
165
+ <link rel="modulepreload" crossorigin href="./assets/MarimoErrorOutput-Ca2QF99G.js">
166
166
  <link rel="modulepreload" crossorigin href="./assets/eye-off-Cm6DdkeR.js">
167
167
  <link rel="modulepreload" crossorigin href="./assets/refresh-cw-DHwG4Mac.js">
168
- <link rel="modulepreload" crossorigin href="./assets/tree-actions-XvgFV23w.js">
168
+ <link rel="modulepreload" crossorigin href="./assets/tree-actions-wXUHKee-.js">
169
169
  <link rel="modulepreload" crossorigin href="./assets/spinner-Bhir8k53.js">
170
- <link rel="modulepreload" crossorigin href="./assets/html-to-image-rLeQGF-G.js">
171
- <link rel="modulepreload" crossorigin href="./assets/focus-CRI5ilWC.js">
170
+ <link rel="modulepreload" crossorigin href="./assets/html-to-image-DkJzNEld.js">
171
+ <link rel="modulepreload" crossorigin href="./assets/focus-CjgVplbV.js">
172
172
  <link rel="modulepreload" crossorigin href="./assets/useAsyncData-bgszE9F0.js">
173
173
  <link rel="modulepreload" crossorigin href="./assets/LazyAnyLanguageCodeMirror-C7ALwTI_.js">
174
174
  <link rel="modulepreload" crossorigin href="./assets/micromark-factory-space-bqhKsQDn.js">
175
175
  <link rel="modulepreload" crossorigin href="./assets/chunk-5FQGJX7Z-D91x7QHS.js">
176
- <link rel="modulepreload" crossorigin href="./assets/markdown-renderer-BHa-Tbwi.js">
176
+ <link rel="modulepreload" crossorigin href="./assets/markdown-renderer-DC51vSBA.js">
177
177
  <link rel="modulepreload" crossorigin href="./assets/command-BmOGG6-2.js">
178
178
  <link rel="modulepreload" crossorigin href="./assets/field-DCdxnSKm.js">
179
179
  <link rel="modulepreload" crossorigin href="./assets/popover-CNCYAwbC.js">
180
180
  <link rel="modulepreload" crossorigin href="./assets/errors-D3F5g1xA.js">
181
- <link rel="modulepreload" crossorigin href="./assets/download-BS31LU22.js">
181
+ <link rel="modulepreload" crossorigin href="./assets/download-B10yQcVE.js">
182
182
  <link rel="modulepreload" crossorigin href="./assets/table-BGPSHfig.js">
183
183
  <link rel="modulepreload" crossorigin href="./assets/useIframeCapabilities-CcI1zSdn.js">
184
184
  <link rel="modulepreload" crossorigin href="./assets/error-banner-D0xvrLog.js">
@@ -198,21 +198,21 @@
198
198
  <link rel="modulepreload" crossorigin href="./assets/plus-BgB18UzY.js">
199
199
  <link rel="modulepreload" crossorigin href="./assets/trash-2-rVklqqFF.js">
200
200
  <link rel="modulepreload" crossorigin href="./assets/react-resizable-panels.browser.esm-CV8-hvjx.js">
201
- <link rel="modulepreload" crossorigin href="./assets/JsonOutput-CZQlutzs.js">
201
+ <link rel="modulepreload" crossorigin href="./assets/JsonOutput-DOmfCaR3.js">
202
202
  <link rel="modulepreload" crossorigin href="./assets/chart-no-axes-column-nqk474t8.js">
203
203
  <link rel="modulepreload" crossorigin href="./assets/square-function-uY_yJr5g.js">
204
204
  <link rel="modulepreload" crossorigin href="./assets/spec-CPQR_o92.js">
205
- <link rel="modulepreload" crossorigin href="./assets/column-preview-DM1s1Z9h.js">
205
+ <link rel="modulepreload" crossorigin href="./assets/column-preview-TS1GqZH2.js">
206
206
  <link rel="modulepreload" crossorigin href="./assets/icons-Ol38nIbL.js">
207
- <link rel="modulepreload" crossorigin href="./assets/radio-group-DS_mmqHJ.js">
208
- <link rel="modulepreload" crossorigin href="./assets/floating-outline-CCH9y0X9.js">
207
+ <link rel="modulepreload" crossorigin href="./assets/radio-group-RRco4zNE.js">
208
+ <link rel="modulepreload" crossorigin href="./assets/floating-outline-CzBp8YHO.js">
209
209
  <link rel="modulepreload" crossorigin href="./assets/objectWithoutPropertiesLoose-DfWeGRFv.js">
210
210
  <link rel="modulepreload" crossorigin href="./assets/esm-xaw4Vy8N.js">
211
- <link rel="modulepreload" crossorigin href="./assets/readonly-python-code-3HZIBvHp.js">
211
+ <link rel="modulepreload" crossorigin href="./assets/readonly-python-code-Crki_rLb.js">
212
212
  <link rel="modulepreload" crossorigin href="./assets/file-headphone-BrQspHac.js">
213
213
  <link rel="modulepreload" crossorigin href="./assets/file-BrdxGLRX.js">
214
214
  <link rel="modulepreload" crossorigin href="./assets/image-DQHXdEQn.js">
215
- <link rel="modulepreload" crossorigin href="./assets/file-icons-on-PIYta.js">
215
+ <link rel="modulepreload" crossorigin href="./assets/file-icons-CtmUbkxd.js">
216
216
  <link rel="modulepreload" crossorigin href="./assets/switch-Ac7CgLgh.js">
217
217
  <link rel="modulepreload" crossorigin href="./assets/events-CPoJAfgx.js">
218
218
  <link rel="modulepreload" crossorigin href="./assets/globals-BivClSmn.js">
@@ -221,11 +221,11 @@
221
221
  <link rel="modulepreload" crossorigin href="./assets/memoize-Tp7rARFe.js">
222
222
  <link rel="modulepreload" crossorigin href="./assets/get-C-qh_et5.js">
223
223
  <link rel="modulepreload" crossorigin href="./assets/_baseSet-CxV9N1bc.js">
224
- <link rel="modulepreload" crossorigin href="./assets/state-Dy-doCBq.js">
224
+ <link rel="modulepreload" crossorigin href="./assets/state-CsD5BRG0.js">
225
225
  <link rel="modulepreload" crossorigin href="./assets/label-C2_YQRio.js">
226
- <link rel="modulepreload" crossorigin href="./assets/textarea-BfDUjd9c.js">
226
+ <link rel="modulepreload" crossorigin href="./assets/textarea-DoKXC-jv.js">
227
227
  <link rel="modulepreload" crossorigin href="./assets/refresh-ccw-C-n2VFP5.js">
228
- <link rel="modulepreload" crossorigin href="./assets/form-HcuPVpyt.js">
228
+ <link rel="modulepreload" crossorigin href="./assets/form-WbviP6l9.js">
229
229
  <link rel="modulepreload" crossorigin href="./assets/renderShortcut--ku7VECI.js">
230
230
  <link rel="modulepreload" crossorigin href="./assets/useBoolean-CE6PfxGj.js">
231
231
  <link rel="modulepreload" crossorigin href="./assets/useDeepCompareMemoize-CVmg-GkP.js">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/frontend",
3
- "version": "0.23.10-dev51",
3
+ "version": "0.23.10-dev52",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -20,6 +20,22 @@ globalThis.ResizeObserver ??= class {
20
20
  }
21
21
  } as never;
22
22
 
23
+ // mock implementation because jsdom doesn't support IntersectionObserver
24
+ globalThis.IntersectionObserver ??= class {
25
+ observe(_target: Element) {
26
+ /* noop */
27
+ }
28
+ unobserve(_target: Element) {
29
+ /* noop */
30
+ }
31
+ disconnect() {
32
+ /* noop */
33
+ }
34
+ takeRecords() {
35
+ return [];
36
+ }
37
+ } as never;
38
+
23
39
  // Global setup for all tests
24
40
  beforeEach(() => {
25
41
  // Reset all mocks before each test
@@ -2,8 +2,9 @@
2
2
  import { historyField } from "@codemirror/commands";
3
3
  import { EditorState, StateEffect } from "@codemirror/state";
4
4
  import { EditorView, ViewPlugin } from "@codemirror/view";
5
+ import { useIntersectionObserver } from "@uidotdev/usehooks";
5
6
  import { useAtom, useAtomValue } from "jotai";
6
- import React, { memo, useEffect, useMemo, useRef } from "react";
7
+ import React, { memo, useEffect, useMemo, useRef, useState } from "react";
7
8
  import useEvent from "react-use-event-hook";
8
9
  import { Button } from "@/components/ui/button";
9
10
  import { DelayMount } from "@/components/utils/delay-mount";
@@ -14,6 +15,7 @@ import { usePendingDeleteService } from "@/core/cells/pending-delete-service";
14
15
  import type { CellData, CellRuntimeState } from "@/core/cells/types";
15
16
  import { setupCodeMirror } from "@/core/codemirror/cm";
16
17
  import { acceptCompletionOnEnterAtom } from "@/core/codemirror/completion/accept-on-enter-atom";
18
+ import { editorMountScheduler } from "@/core/codemirror/editor-mount-scheduler";
17
19
  import {
18
20
  getInitialLanguageAdapter,
19
21
  languageAdapterState,
@@ -45,6 +47,7 @@ import {
45
47
  } from "../../navigation/navigation";
46
48
  import { useDeleteCellCallback } from "../useDeleteCell";
47
49
  import { useSplitCellCallback } from "../useSplitCell";
50
+ import { CodePlaceholder } from "./code-placeholder";
48
51
  import { LanguageToggles } from "./language-toggle";
49
52
 
50
53
  export interface CellEditorProps
@@ -405,38 +408,45 @@ const CellEditorInternal = ({
405
408
  // Clear the serialized state so that we don't re-create the editor next time
406
409
  cellActions.clearSerializedEditorState({ cellId });
407
410
  });
411
+ const [isEditorMounted, setIsEditorMounted] = useState(
412
+ serializedEditorState !== null,
413
+ );
408
414
 
415
+ // Build the editor. Deserialize eagerly; otherwise queue an async build so
416
+ // large notebooks stay responsive while editors come online progressively.
409
417
  useEffect(() => {
410
- if (serializedEditorState === null) {
411
- if (editorViewRef.current === null) {
412
- handleInitializeEditor();
413
- } else {
414
- // If the editor already exists, reconfigure it with the new extensions.
415
- handleReconfigureEditor();
416
- }
417
- } else {
418
- handleDeserializeEditor();
418
+ if (editorViewRef.current !== null) {
419
+ setIsEditorMounted(true);
420
+ return;
419
421
  }
420
-
421
- if (
422
- editorViewRef.current !== null &&
423
- editorViewParentRef &&
424
- editorViewParentRef.current !== null
425
- ) {
426
- // Always replace the children in case the editor view was re-created.
427
- editorViewParentRef.current.replaceChildren(editorViewRef.current.dom);
422
+ if (serializedEditorState !== null) {
423
+ handleDeserializeEditor();
424
+ setIsEditorMounted(true);
425
+ return;
428
426
  }
427
+ editorMountScheduler.request(cellId, () => {
428
+ if (editorViewRef.current !== null) {
429
+ return;
430
+ }
431
+ handleInitializeEditor();
432
+ setIsEditorMounted(true);
433
+ });
434
+ return () => editorMountScheduler.cancel(cellId);
429
435
  }, [
430
- handleInitializeEditor,
431
- handleReconfigureEditor,
432
- handleDeserializeEditor,
436
+ cellId,
433
437
  editorViewRef,
434
- editorViewParentRef,
438
+ handleDeserializeEditor,
439
+ handleInitializeEditor,
435
440
  serializedEditorState,
436
- // Props to trigger reconfiguration
437
- extensions,
438
441
  ]);
439
442
 
443
+ useEffect(() => {
444
+ if (editorViewRef.current === null) {
445
+ return;
446
+ }
447
+ handleReconfigureEditor();
448
+ }, [handleReconfigureEditor, extensions, editorViewRef]);
449
+
440
450
  // Destroy the editor when the component is unmounted
441
451
  useEffect(() => {
442
452
  const ev = editorViewRef.current;
@@ -445,6 +455,23 @@ const CellEditorInternal = ({
445
455
  };
446
456
  }, [editorViewRef]);
447
457
 
458
+ // Prioritize building this cell's editor when it scrolls into view, so the
459
+ // visible region fills in first instead of waiting for the top-to-bottom
460
+ // queue. The margin builds cells just before they reach the viewport.
461
+ const [intersectionRef, intersection] = useIntersectionObserver({
462
+ rootMargin: "300px 0px",
463
+ });
464
+ useEffect(() => {
465
+ if (isEditorMounted) {
466
+ return;
467
+ }
468
+ if (intersection?.isIntersecting) {
469
+ editorMountScheduler.prioritize(cellId);
470
+ } else {
471
+ editorMountScheduler.deprioritize(cellId);
472
+ }
473
+ }, [isEditorMounted, intersection?.isIntersecting, cellId]);
474
+
448
475
  const navigationProps = useCellEditorNavigationProps(cellId, editorViewRef);
449
476
 
450
477
  let editorClassName = "";
@@ -489,14 +516,22 @@ const CellEditorInternal = ({
489
516
  runCell={handleRunCell}
490
517
  outputArea={outputArea}
491
518
  >
492
- <div className="relative w-full" {...navigationProps}>
493
- <CellCodeMirrorEditor
494
- className={editorClassName}
495
- editorView={editorViewRef.current}
496
- ref={editorViewParentRef}
497
- hidden={hidden}
498
- showHiddenCode={showHiddenCode}
499
- />
519
+ <div
520
+ className="relative w-full"
521
+ ref={intersectionRef}
522
+ {...navigationProps}
523
+ >
524
+ {isEditorMounted ? (
525
+ <CellCodeMirrorEditor
526
+ className={editorClassName}
527
+ editorView={editorViewRef.current}
528
+ ref={editorViewParentRef}
529
+ hidden={hidden}
530
+ showHiddenCode={showHiddenCode}
531
+ />
532
+ ) : (
533
+ <CodePlaceholder code={code} className={editorClassName} />
534
+ )}
500
535
  {!hidden && showLanguageToggles && (
501
536
  <div className="absolute top-1 right-5">
502
537
  <LanguageToggles
@@ -0,0 +1,17 @@
1
+ .mo-code-placeholder {
2
+ --mo-skeleton-bar: color-mix(in srgb, var(--muted), var(--foreground) 18%);
3
+ cursor: default;
4
+ padding: 4px 10px;
5
+ font-size: var(--cm-font-size, 0.875rem);
6
+ }
7
+
8
+ .mo-code-placeholder-line {
9
+ display: flex;
10
+ align-items: center;
11
+ height: 1.5em;
12
+ }
13
+
14
+ .mo-code-placeholder-bar {
15
+ height: 0.7em;
16
+ background-color: var(--mo-skeleton-bar);
17
+ }
@@ -0,0 +1,46 @@
1
+ import "./code-placeholder.css";
2
+ import { Skeleton } from "@/components/ui/skeleton";
3
+ import { cn } from "@/utils/cn";
4
+
5
+ interface CodePlaceholderProps {
6
+ code: string;
7
+ className?: string;
8
+ }
9
+
10
+ // Bound the rendered bars so a very long cell does not create excessive nodes.
11
+ const MAX_LINES = 50;
12
+ const MIN_LINE_WIDTH_CH = 4;
13
+ const MAX_LINE_WIDTH_CH = 60;
14
+
15
+ function getLineWidthCh(length: number): number {
16
+ return Math.min(MAX_LINE_WIDTH_CH, Math.max(MIN_LINE_WIDTH_CH, length));
17
+ }
18
+
19
+ /**
20
+ * Stand-in shown while a cell's CodeMirror editor has not been built yet.
21
+ * one skeleton bar per code line, so the final render doesn't cause a big jump.
22
+ */
23
+ export const CodePlaceholder = ({ code, className }: CodePlaceholderProps) => {
24
+ const lines = code.split("\n", MAX_LINES);
25
+ return (
26
+ <div
27
+ className={cn("cm", "mo-code-placeholder", className)}
28
+ data-testid="cell-editor-placeholder"
29
+ aria-hidden={true}
30
+ >
31
+ {lines.map((line, index) => {
32
+ const length = line.trimEnd().length;
33
+ return (
34
+ <div key={index} className="mo-code-placeholder-line">
35
+ {length > 0 && (
36
+ <Skeleton
37
+ className="mo-code-placeholder-bar"
38
+ style={{ width: `${getLineWidthCh(length)}ch` }}
39
+ />
40
+ )}
41
+ </div>
42
+ );
43
+ })}
44
+ </div>
45
+ );
46
+ };
@@ -7,6 +7,7 @@ import {
7
7
  import type { CellHandle } from "@/components/editor/notebook-cell";
8
8
  import { retryWithTimeout } from "@/utils/timeout";
9
9
  import { Logger } from "../../utils/Logger";
10
+ import { editorMountScheduler } from "../codemirror/editor-mount-scheduler";
10
11
  import { scrollActiveLineIntoView } from "../codemirror/extensions";
11
12
  import { goToVariableDefinition } from "../codemirror/go-to-definition/commands";
12
13
  import { getCellEditorView } from "./cells";
@@ -48,6 +49,9 @@ export function focusAndScrollCellIntoView({
48
49
  // https://github.com/marimo-team/marimo/issues/2940
49
50
  tryFocus(element);
50
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.
54
+ editorMountScheduler.promote(cellId);
51
55
  const editor = cell.current?.editorView;
52
56
  if (!editor) {
53
57
  Logger.warn("scrollCellIntoView: editor not found", cellId);
@@ -0,0 +1,142 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { createEditorMountScheduler } from "../editor-mount-scheduler";
3
+
4
+ function makeManualSchedule() {
5
+ let pending: (() => void) | null = null;
6
+ const schedule = (cb: () => void) => {
7
+ pending = cb;
8
+ };
9
+ const flush = () => {
10
+ const cb = pending;
11
+ pending = null;
12
+ cb?.();
13
+ };
14
+ return { schedule, flush, hasPending: () => pending !== null };
15
+ }
16
+
17
+ describe("createEditorMountScheduler", () => {
18
+ it("builds one queued editor per tick in FIFO order, rescheduling between", () => {
19
+ const { schedule, flush, hasPending } = makeManualSchedule();
20
+ const built: string[] = [];
21
+ const s = createEditorMountScheduler(schedule);
22
+ s.request("a", () => built.push("a"));
23
+ s.request("b", () => built.push("b"));
24
+ flush();
25
+ expect(built).toEqual(["a"]);
26
+ expect(hasPending()).toBe(true);
27
+ flush();
28
+ expect(built).toEqual(["a", "b"]);
29
+ });
30
+
31
+ it("stops rescheduling once the queue is empty", () => {
32
+ const { schedule, flush, hasPending } = makeManualSchedule();
33
+ const built: string[] = [];
34
+ const s = createEditorMountScheduler(schedule);
35
+ s.request("a", () => built.push("a"));
36
+ flush();
37
+ expect(built).toEqual(["a"]);
38
+ expect(hasPending()).toBe(false);
39
+ });
40
+
41
+ it("promote builds immediately and removes from the queue", () => {
42
+ const { schedule, flush } = makeManualSchedule();
43
+ const built: string[] = [];
44
+ const s = createEditorMountScheduler(schedule);
45
+ s.request("a", () => built.push("a"));
46
+ s.request("b", () => built.push("b"));
47
+ s.promote("b");
48
+ expect(built).toEqual(["b"]);
49
+ flush();
50
+ expect(built).toEqual(["b", "a"]);
51
+ });
52
+
53
+ it("cancel prevents a queued build", () => {
54
+ const { schedule, flush } = makeManualSchedule();
55
+ const built: string[] = [];
56
+ const s = createEditorMountScheduler(schedule);
57
+ s.request("a", () => built.push("a"));
58
+ s.cancel("a");
59
+ flush();
60
+ expect(built).toEqual([]);
61
+ });
62
+
63
+ it("builds prioritized cells before earlier-queued ones", () => {
64
+ const { schedule, flush } = makeManualSchedule();
65
+ const built: string[] = [];
66
+ const s = createEditorMountScheduler(schedule);
67
+ s.request("a", () => built.push("a"));
68
+ s.request("b", () => built.push("b"));
69
+ s.request("c", () => built.push("c"));
70
+ s.prioritize("c");
71
+ flush();
72
+ flush();
73
+ flush();
74
+ expect(built).toEqual(["c", "a", "b"]);
75
+ });
76
+
77
+ it("builds multiple prioritized cells in prioritization order, then FIFO", () => {
78
+ const { schedule, flush } = makeManualSchedule();
79
+ const built: string[] = [];
80
+ const s = createEditorMountScheduler(schedule);
81
+ s.request("a", () => built.push("a"));
82
+ s.request("b", () => built.push("b"));
83
+ s.request("c", () => built.push("c"));
84
+ s.request("d", () => built.push("d"));
85
+ s.prioritize("d");
86
+ s.prioritize("b");
87
+ flush();
88
+ flush();
89
+ flush();
90
+ flush();
91
+ expect(built).toEqual(["d", "b", "a", "c"]);
92
+ });
93
+
94
+ it("ignores prioritize for a cell that is not queued", () => {
95
+ const { schedule, flush } = makeManualSchedule();
96
+ const built: string[] = [];
97
+ const s = createEditorMountScheduler(schedule);
98
+ s.request("a", () => built.push("a"));
99
+ s.prioritize("not-queued");
100
+ flush();
101
+ expect(built).toEqual(["a"]);
102
+ });
103
+
104
+ it("deprioritize reverts a cell to FIFO order without dropping it", () => {
105
+ const { schedule, flush } = makeManualSchedule();
106
+ const built: string[] = [];
107
+ const s = createEditorMountScheduler(schedule);
108
+ s.request("a", () => built.push("a"));
109
+ s.request("b", () => built.push("b"));
110
+ s.prioritize("b");
111
+ s.deprioritize("b");
112
+ flush();
113
+ flush();
114
+ expect(built).toEqual(["a", "b"]);
115
+ });
116
+
117
+ it("keeps draining the queue after a build throws", () => {
118
+ const { schedule, flush } = makeManualSchedule();
119
+ const built: string[] = [];
120
+ const s = createEditorMountScheduler(schedule);
121
+ s.request("a", () => {
122
+ throw new Error("boom");
123
+ });
124
+ s.request("b", () => built.push("b"));
125
+ expect(() => flush()).toThrow("boom");
126
+ flush();
127
+ expect(built).toEqual(["b"]);
128
+ });
129
+
130
+ it("cancel removes a prioritized cell", () => {
131
+ const { schedule, flush } = makeManualSchedule();
132
+ const built: string[] = [];
133
+ const s = createEditorMountScheduler(schedule);
134
+ s.request("a", () => built.push("a"));
135
+ s.request("b", () => built.push("b"));
136
+ s.prioritize("b");
137
+ s.cancel("b");
138
+ flush();
139
+ flush();
140
+ expect(built).toEqual(["a"]);
141
+ });
142
+ });
@@ -0,0 +1,100 @@
1
+ import {
2
+ scheduleTask as defaultScheduleTask,
3
+ type ScheduleTaskFn,
4
+ } from "@/utils/schedule-task";
5
+
6
+ type BuildFn = () => void;
7
+
8
+ export interface EditorMountScheduler {
9
+ /** Queue a cell's editor build to run on a future task. */
10
+ request(cellId: string, build: BuildFn): void;
11
+ /** Build a queued cell's editor synchronously, right now (e.g. on focus). */
12
+ promote(cellId: string): void;
13
+ /**
14
+ * Mark a queued cell to build ahead of un-prioritized ones, keeping the
15
+ * one-build-per-task pacing (e.g. when the cell scrolls into view).
16
+ */
17
+ prioritize(cellId: string): void;
18
+ /** Drop a cell's prioritized mark, reverting it to plain FIFO order. */
19
+ deprioritize(cellId: string): void;
20
+ /** Remove a cell's queued build entirely. */
21
+ cancel(cellId: string): void;
22
+ }
23
+
24
+ /**
25
+ * Drains a FIFO queue of editor builds, one per macrotask, so constructing many
26
+ * CodeMirror instances never blocks the main thread in a single long task. The
27
+ * scheduler yields between every build to keep the page responsive. Cells can
28
+ * be prioritized (e.g. when they scroll into view) to jump ahead of the queue
29
+ * without breaking the one-build-per-macrotask pacing.
30
+ */
31
+ export function createEditorMountScheduler(
32
+ scheduleTask: ScheduleTaskFn = defaultScheduleTask,
33
+ ): EditorMountScheduler {
34
+ const queue = new Map<string, BuildFn>();
35
+ const priority = new Set<string>();
36
+ let isProcessingScheduled = false;
37
+
38
+ function scheduleProcessing(): void {
39
+ if (isProcessingScheduled || queue.size === 0) {
40
+ return;
41
+ }
42
+ isProcessingScheduled = true;
43
+ scheduleTask(processNext);
44
+ }
45
+
46
+ // Prioritized cells first, in the order they were prioritized; then FIFO.
47
+ function nextCellId(): string | undefined {
48
+ for (const cellId of priority) {
49
+ if (queue.has(cellId)) {
50
+ return cellId;
51
+ }
52
+ priority.delete(cellId);
53
+ }
54
+ return queue.keys().next().value;
55
+ }
56
+
57
+ function processNext(): void {
58
+ isProcessingScheduled = false;
59
+ try {
60
+ const cellId = nextCellId();
61
+ if (cellId !== undefined) {
62
+ const build = queue.get(cellId);
63
+ queue.delete(cellId);
64
+ priority.delete(cellId);
65
+ build?.();
66
+ }
67
+ } finally {
68
+ scheduleProcessing();
69
+ }
70
+ }
71
+
72
+ return {
73
+ request(cellId, build) {
74
+ queue.set(cellId, build);
75
+ scheduleProcessing();
76
+ },
77
+ promote(cellId) {
78
+ const build = queue.get(cellId);
79
+ if (build) {
80
+ queue.delete(cellId);
81
+ priority.delete(cellId);
82
+ build();
83
+ }
84
+ },
85
+ prioritize(cellId) {
86
+ if (queue.has(cellId)) {
87
+ priority.add(cellId);
88
+ }
89
+ },
90
+ deprioritize(cellId) {
91
+ priority.delete(cellId);
92
+ },
93
+ cancel(cellId) {
94
+ queue.delete(cellId);
95
+ priority.delete(cellId);
96
+ },
97
+ };
98
+ }
99
+
100
+ export const editorMountScheduler = createEditorMountScheduler();