@marimo-team/islands 0.26.1-dev6 → 0.26.1-dev60

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 (317) hide show
  1. package/dist/{ConnectedDataExplorerComponent-DtwVgVpX.js → ConnectedDataExplorerComponent-yQVBQBUW.js} +16 -16
  2. package/dist/{ErrorBoundary-CLLMEsVD.js → ErrorBoundary-BdXvplK4.js} +19 -19
  3. package/dist/{abnfDiagram-VCTEODGH-BbZOIueZ.js → abnfDiagram-VCTEODGH-Ck_lXwQR.js} +2 -2
  4. package/dist/{any-language-editor-yG-YmLaK.js → any-language-editor-Cx4idbgX.js} +5 -5
  5. package/dist/{architectureDiagram-5GKGNRK7-qjLjxapm.js → architectureDiagram-5GKGNRK7-XeVhic7Z.js} +1 -1
  6. package/dist/{assertNever-DywGMo-S.js → assertNever-473SFxLt.js} +14 -14
  7. package/dist/{button-qQhINE7z.js → button-Z2R2272J.js} +34 -31
  8. package/dist/{capabilities-DKqMqBzm.js → capabilities-ba3Dyv8n.js} +1 -1
  9. package/dist/{chat-ui-D5YPIONI.js → chat-ui-D1mRz9h6.js} +113 -113
  10. package/dist/{check-jchHMCfs.js → check-DmTIavbZ.js} +1 -1
  11. package/dist/{chunk-IMKFNOWR-BzDY1_I7.js → chunk-IMKFNOWR-DdQni67K.js} +1 -1
  12. package/dist/{chunk-SHT3W25Y-DbHsMKdo.js → chunk-SHT3W25Y-BdK-vMct.js} +1 -1
  13. package/dist/{chunk-SVP7TREG-CtwnwAE6.js → chunk-SVP7TREG-cpFZk4Ca.js} +1 -1
  14. package/dist/{chunk-TICWLB2K-C5Z5QMbO.js → chunk-TICWLB2K-DDgQFRgT.js} +1 -1
  15. package/dist/{classDiagram-ZZMXUADV-B8E5Hn78.js → classDiagram-ZZMXUADV-DeojX9X4.js} +2 -2
  16. package/dist/{classDiagram-v2-VYDZK3BY-DeGsK9bT.js → classDiagram-v2-VYDZK3BY-DPfTAiQ6.js} +2 -2
  17. package/dist/{code-visibility-D8sNdSZw.js → code-visibility-BSe8efVJ.js} +28 -28
  18. package/dist/{common-C1vcGVta.js → common-D4UcPNCP.js} +5102 -5055
  19. package/dist/{config-qTaTHnpE.js → config-D-lhQq-h.js} +31 -32
  20. package/dist/{copy-icon-BI7vZHEW.js → copy-icon-DuxRkh7T.js} +3 -3
  21. package/dist/{createReducer-DdSLRfBT.js → createReducer-D3pBhIVD.js} +2 -2
  22. package/dist/{cynefinDiagram-5FMLGOSQ-NDedRwsw.js → cynefinDiagram-5FMLGOSQ-DyY9TvuI.js} +1 -1
  23. package/dist/{dagre-GXQ25YYZ-De0sSZO7.js → dagre-GXQ25YYZ-BPCOgtKg.js} +1 -1
  24. package/dist/{data-grid-overlay-editor-DbZ4Cn8Q.js → data-grid-overlay-editor-j_uScboj.js} +1 -1
  25. package/dist/{diagram-S7CK7UJ4-wBtVl61y.js → diagram-S7CK7UJ4-KaF-C6kd.js} +1 -1
  26. package/dist/{diagram-UQ7AKVKN-CKWE3c1T.js → diagram-UQ7AKVKN-DkeqoSvK.js} +1 -1
  27. package/dist/{diagram-VX7I27RA-D2Ac5198.js → diagram-VX7I27RA-DExolTAf.js} +1 -1
  28. package/dist/{diagram-Z3DM3KII-CYaFOQcI.js → diagram-Z3DM3KII-BioFuBF3.js} +1 -1
  29. package/dist/{dialog-Ic6dh09m.js → dialog-CvyFEwby.js} +32 -32
  30. package/dist/{dist-BvZpdAuG.js → dist-6B1_Ttbh.js} +1 -1
  31. package/dist/{dist-D1D56-GS.js → dist-B28poF32.js} +2 -2
  32. package/dist/{dist-BozTF_gH.js → dist-BBZ7lnMw.js} +2 -2
  33. package/dist/{dist-BfrgytDR.js → dist-BD8ZKF5t.js} +3 -3
  34. package/dist/{dist-DNkrY12t.js → dist-BG-7Qpaj.js} +3 -3
  35. package/dist/{dist-D92tYjLc.js → dist-BIaGGUbU.js} +13 -11
  36. package/dist/{dist-BagHbFqG.js → dist-BR5PU2Ph.js} +3 -3
  37. package/dist/{dist-DpYpG8Yc.js → dist-BidYR5m4.js} +3 -3
  38. package/dist/{dist-D95Cd4xm.js → dist-BkGYCvFX.js} +3 -3
  39. package/dist/{dist-DneeBk3K.js → dist-BmEyXT7K.js} +2 -2
  40. package/dist/{dist-BdUitvVW.js → dist-Bt0Wt6m9.js} +2 -2
  41. package/dist/{dist-CEomphG1.js → dist-CG2Sl0D4.js} +2 -2
  42. package/dist/{dist-BMz__bo5.js → dist-CQfpgadU.js} +3 -3
  43. package/dist/{dist-BreKIQqQ.js → dist-CVOPvfzN.js} +3 -3
  44. package/dist/{dist-BEcpQbZa.js → dist-Cm0iCeQQ.js} +3 -3
  45. package/dist/{dist-CDVvitRS.js → dist-Cnc14jEq.js} +2 -2
  46. package/dist/{dist-ChcBm3jk.js → dist-D3KPC38e.js} +4 -4
  47. package/dist/{dist-B1qu3Bez.js → dist-D7BXk27E.js} +3 -3
  48. package/dist/{dist-BsE4gQHj.js → dist-D9Qhvxvg.js} +1 -1
  49. package/dist/{dist-OmeAz0fR.js → dist-DJKajXDB.js} +3 -3
  50. package/dist/{dist-ObeTgSmf.js → dist-DYbNRTYG.js} +4 -4
  51. package/dist/{dist-Cshl6jBw.js → dist-DhtDWnzK.js} +2 -2
  52. package/dist/{dist-BunZKA_9.js → dist-_x2Jks2R.js} +2 -2
  53. package/dist/{dist-MggMo7OR.js → dist-m0MWV-aw.js} +1 -1
  54. package/dist/{dist-TGSwzj8a.js → dist-pPbYNVjd.js} +4 -4
  55. package/dist/{dropdown-menu-Dhv4fcNl.js → dropdown-menu-BiXHfje7.js} +2568 -2568
  56. package/dist/{ebnfDiagram-PWID7BFC-Ds7f42dj.js → ebnfDiagram-PWID7BFC-BSb9k1ed.js} +2 -2
  57. package/dist/{erDiagram-RLTQ6QDP-b58Sz2Mc.js → erDiagram-RLTQ6QDP-PWA30a_r.js} +1 -1
  58. package/dist/{error-banner-CJVLr5_a.js → error-banner-B9HQMSaH.js} +35 -35
  59. package/dist/{error-entries-BKlEsuk4.js → error-entries-P6Qpq6wP.js} +1032 -867
  60. package/dist/{esm-B9n0caHs.js → esm-DY8dGAjJ.js} +23 -23
  61. package/dist/{esm-Bwp_FHP0.js → esm-Dw2ZydG_.js} +3 -3
  62. package/dist/{feedback-button-CjWyhzBQ.js → feedback-button-DRcg_ZBP.js} +123 -123
  63. package/dist/{flowDiagram-HODETNUW-BH9U7VZK.js → flowDiagram-HODETNUW-BPtD__Zz.js} +2 -2
  64. package/dist/{formats-BLNFWWhV.js → formats-BF95BoCT.js} +3 -3
  65. package/dist/{glide-data-editor-B0vlSuQn.js → glide-data-editor-DkKBZmyu.js} +43 -43
  66. package/dist/{glide-utils-Ze_7l_91.js → glide-utils-iHKKQPJ8.js} +3 -3
  67. package/dist/{globals-_GdM0yI_.js → globals-D-LCkcIG.js} +3 -3
  68. package/dist/{html-to-image-CNM0ZSFD.js → html-to-image-DhrFZL7t.js} +24150 -24028
  69. package/dist/{infoDiagram-27XIBGKW-xbjwrcNi.js → infoDiagram-27XIBGKW-SJuilBEE.js} +1 -1
  70. package/dist/{ishikawaDiagram-5VMMS53U-DKtukhGS.js → ishikawaDiagram-5VMMS53U-DjzyxMr8.js} +1 -1
  71. package/dist/{kanban-definition-UXKFOSKX-BEhlkZBb.js → kanban-definition-UXKFOSKX-D2_qopGt.js} +1 -1
  72. package/dist/{loader-Bin_dutt.js → loader-qPmiRXZd.js} +1 -1
  73. package/dist/main.js +8860 -8741
  74. package/dist/{mermaid-D1CZDNoB.js → mermaid-DcowNmCx.js} +35 -35
  75. package/dist/{mindmap-definition-YA3MSWOX-DQcnJPcV.js → mindmap-definition-YA3MSWOX-pEra10M0.js} +1 -1
  76. package/dist/{number-overlay-editor-C9qcz20o.js → number-overlay-editor-xQbbd1Ku.js} +1 -1
  77. package/dist/{pegDiagram-XKGWAZYB-BFQuPYfI.js → pegDiagram-XKGWAZYB-CHOPKVOf.js} +2 -2
  78. package/dist/{pencil-DVYzq-iR.js → pencil-FAv6JUvp.js} +1 -1
  79. package/dist/{pieDiagram-E7YTZNPT-l7aqNrem.js → pieDiagram-E7YTZNPT-yGDhsyEN.js} +1 -1
  80. package/dist/{process-output-DthYR2Te.js → process-output-CBPqVQBu.js} +4 -4
  81. package/dist/{railroadDiagram-O6MQD6OU-6R3C1lwQ.js → railroadDiagram-O6MQD6OU-CeKEPdyc.js} +2 -2
  82. package/dist/{requirementDiagram-BXWQKSXE-DdWYu8fn.js → requirementDiagram-BXWQKSXE-DSAbAzKe.js} +1 -1
  83. package/dist/{reveal-component-CGGipwgt.js → reveal-component-DUTEhLsR.js} +1018 -1018
  84. package/dist/{select-CDUxhHZg.js → select-BszV-bbI.js} +135 -135
  85. package/dist/{sequenceDiagram-WJ2MYXX4-Dzp0dgRc.js → sequenceDiagram-WJ2MYXX4-DVhWj_9H.js} +1 -1
  86. package/dist/{spec-ZAt4P01J.js → spec-CRfw-lOm.js} +4 -4
  87. package/dist/{stateDiagram-D77RDMKH-BGnTUhFJ.js → stateDiagram-D77RDMKH-CDQ2MltG.js} +2 -2
  88. package/dist/{stateDiagram-v2-MP3YSRHH-DsJbmDf1.js → stateDiagram-v2-MP3YSRHH-BQmvwBaz.js} +2 -2
  89. package/dist/{static-state-C4bAlKTU.js → static-state-BtDNJuc2.js} +7 -7
  90. package/dist/style.css +1 -1
  91. package/dist/{swimlanes-42K2YHIH-Bd4Bzh9r.js → swimlanes-42K2YHIH-DLOUTCEL.js} +1 -1
  92. package/dist/{swimlanesDiagram-VR7AAH4N-BlY12Jf6.js → swimlanesDiagram-VR7AAH4N-BVKrkNJ6.js} +2 -2
  93. package/dist/{swiper-component-DTdNB9wg.js → swiper-component-B2O8hF7b.js} +2 -2
  94. package/dist/{timeline-definition-24CTP7MA-m0LanyCH.js → timeline-definition-24CTP7MA-Cb2JoCSd.js} +1 -1
  95. package/dist/{toast-U3NpO2x3.js → toast-QsOAIPfq.js} +166 -166
  96. package/dist/{tooltip-UzJukb3F.js → tooltip-BQZ-Bm6h.js} +65 -65
  97. package/dist/{use-restore-focus-DaTVz6S6.js → use-restore-focus-DT1TZACX.js} +1885 -1877
  98. package/dist/{useDateFormatter-LQNtoXyh.js → useDateFormatter-D3gyMY-g.js} +2 -2
  99. package/dist/{useDeepCompareMemoize-CmNbQ9TT.js → useDeepCompareMemoize-CO6rO5Mq.js} +1 -1
  100. package/dist/{useIframeCapabilities-HTZiVlGV.js → useIframeCapabilities-_0KX0nu_.js} +1 -1
  101. package/dist/{useLifecycle-DTMczKkf.js → useLifecycle-C9UTzCY8.js} +2 -2
  102. package/dist/{vega-component-ZTdbCcwI.js → vega-component-i5lZ23n7.js} +19 -19
  103. package/dist/{vennDiagram-4TSXK5OY-BJ7vqDmn.js → vennDiagram-4TSXK5OY-Cm3EcCcP.js} +1 -1
  104. package/dist/{wardleyDiagram-VM6X3IG4-D5kWacsn.js → wardleyDiagram-VM6X3IG4-DjlUs2CC.js} +1 -1
  105. package/dist/{xychartDiagram-S5SC5T6Z-gr15Ws_z.js → xychartDiagram-S5SC5T6Z-DxNDul9l.js} +1 -1
  106. package/package.json +3 -3
  107. package/src/__mocks__/animation-frames.ts +31 -0
  108. package/src/__mocks__/executions.ts +51 -23
  109. package/src/__mocks__/intersection-observer.ts +45 -0
  110. package/src/__mocks__/notebook.ts +1 -1
  111. package/src/__tests__/branded.ts +4 -0
  112. package/src/__tests__/notebook-analysis.ts +48 -0
  113. package/src/__tests__/render-tracker.ts +15 -0
  114. package/src/__tests__/setup.ts +3 -0
  115. package/src/components/data-table/__tests__/export-actions.test.tsx +79 -0
  116. package/src/components/data-table/export-actions.tsx +64 -19
  117. package/src/components/data-table/schemas.ts +1 -0
  118. package/src/components/databases/engine-variable.tsx +2 -2
  119. package/src/components/dependency-graph/panels.tsx +2 -2
  120. package/src/components/editor/__tests__/cell-renders.test.tsx +116 -0
  121. package/src/components/editor/actions/__tests__/name-cell-input.test.tsx +1 -1
  122. package/src/components/editor/actions/useCellActionButton.tsx +2 -8
  123. package/src/components/editor/ai/__tests__/completion-utils.test.ts +28 -61
  124. package/src/components/editor/cell/CreateCellButton.tsx +69 -40
  125. package/src/components/editor/cell/__tests__/CreateCellButton.test.tsx +49 -0
  126. package/src/components/editor/cell/__tests__/cell-context-menu.test.tsx +126 -0
  127. package/src/components/editor/cell/__tests__/useRunCells.test.tsx +5 -5
  128. package/src/components/editor/cell/cell-context-menu.tsx +202 -111
  129. package/src/components/editor/cell/code/__tests__/code-placeholder.test.tsx +40 -0
  130. package/src/components/editor/cell/code/cell-editor.tsx +49 -108
  131. package/src/components/editor/cell/code/code-placeholder.css +61 -11
  132. package/src/components/editor/cell/code/code-placeholder.tsx +52 -27
  133. package/src/components/editor/cell/collapse.tsx +6 -3
  134. package/src/components/editor/cell/useSplitCell.tsx +2 -2
  135. package/src/components/editor/chrome/panels/__tests__/secrets-panel.test.tsx +57 -0
  136. package/src/components/editor/chrome/panels/secrets-panel.tsx +36 -9
  137. package/src/components/editor/chrome/panels/secrets-utils.ts +20 -0
  138. package/src/components/editor/chrome/wrapper/__tests__/document-sync-status.test.tsx +5 -2
  139. package/src/components/editor/chrome/wrapper/__tests__/pending-ai-cells.test.tsx +6 -10
  140. package/src/components/editor/errors/auto-fix.tsx +8 -7
  141. package/src/components/editor/header/status.tsx +5 -2
  142. package/src/components/editor/navigation/__tests__/navigation.test.ts +3 -16
  143. package/src/components/editor/navigation/focus-utils.ts +20 -8
  144. package/src/components/editor/navigation/multi-cell-action-toolbar.tsx +3 -11
  145. package/src/components/editor/navigation/navigation.ts +2 -2
  146. package/src/components/editor/notebook-cell.tsx +15 -24
  147. package/src/components/editor/output/MarimoTracebackOutput.tsx +2 -2
  148. package/src/components/editor/output/console/ConsoleOutput.tsx +77 -50
  149. package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +28 -0
  150. package/src/components/editor/renderers/cells-renderer.tsx +3 -2
  151. package/src/components/editor/renderers/vertical-layout/__tests__/useFocusFirstEditor.test.ts +6 -9
  152. package/src/components/editor/renderers/vertical-layout/useFocusFirstEditor.ts +2 -5
  153. package/src/components/find-replace/find-replace.tsx +3 -7
  154. package/src/components/icons/__tests__/large-spinner.test.tsx +5 -4
  155. package/src/components/scratchpad/scratchpad.tsx +2 -2
  156. package/src/components/tracing/tracing-keyboard.test.tsx +4 -3
  157. package/src/components/ui/__tests__/button-shortcut.test.tsx +22 -0
  158. package/src/components/ui/__tests__/fullscreen.test.tsx +83 -1
  159. package/src/components/ui/button.tsx +5 -1
  160. package/src/components/ui/fullscreen.tsx +43 -89
  161. package/src/components/variables/__tests__/variables-table.test.tsx +1 -2
  162. package/src/core/MarimoApp.tsx +1 -1
  163. package/src/core/__tests__/MarimoApp.test.tsx +147 -0
  164. package/src/core/ai/__tests__/staged-cells.test.ts +6 -39
  165. package/src/core/ai/context/providers/__tests__/error.test.ts +6 -3
  166. package/src/core/ai/staged-cells.ts +8 -35
  167. package/src/core/ai/tools/__tests__/edit-notebook-tool.test.ts +15 -13
  168. package/src/core/ai/tools/edit-notebook-tool.ts +13 -8
  169. package/src/core/cells/__tests__/actions.test.ts +2 -2
  170. package/src/core/cells/__tests__/add-missing-import.test.ts +14 -9
  171. package/src/core/cells/__tests__/arrange.test.ts +1 -1
  172. package/src/core/cells/__tests__/cell-editor-view.test.ts +44 -0
  173. package/src/core/cells/__tests__/cells.test.ts +0 -1
  174. package/src/core/cells/__tests__/focus.test.ts +1 -7
  175. package/src/core/cells/__tests__/harness.ts +9 -8
  176. package/src/core/cells/__tests__/layout.test.ts +1 -1
  177. package/src/core/cells/__tests__/pending-delete-service.test.tsx +121 -11
  178. package/src/core/cells/__tests__/runs.test.ts +14 -14
  179. package/src/core/cells/__tests__/utils.test.ts +3 -2
  180. package/src/core/cells/actions.ts +6 -6
  181. package/src/core/cells/add-missing-import.ts +2 -3
  182. package/src/core/cells/cells.ts +40 -27
  183. package/src/core/cells/document.ts +1 -2
  184. package/src/core/cells/execution-console.ts +10 -5
  185. package/src/core/cells/focus.ts +1 -1
  186. package/src/core/cells/ids.ts +2 -4
  187. package/src/core/cells/pending-delete-service.ts +97 -85
  188. package/src/core/cells/runs.ts +7 -5
  189. package/src/core/cells/scrollCellIntoView.ts +4 -14
  190. package/src/core/cells/session.ts +8 -5
  191. package/src/core/cells/utils.ts +0 -13
  192. package/src/core/codemirror/__tests__/cell-documents.test.ts +79 -0
  193. package/src/core/codemirror/__tests__/debounced-editor-update.test.ts +72 -0
  194. package/src/core/codemirror/__tests__/editor-mount-scheduler.test.ts +75 -105
  195. package/src/core/codemirror/__tests__/format.test.ts +85 -63
  196. package/src/core/codemirror/__tests__/setup.test.ts +61 -1
  197. package/src/core/codemirror/__tests__/use-lazy-editor-mount.test.tsx +198 -0
  198. package/src/core/codemirror/cell-documents.ts +132 -0
  199. package/src/core/codemirror/cells/debugger-decorations.ts +22 -18
  200. package/src/core/codemirror/cells/line-timing-decorations.ts +13 -11
  201. package/src/core/codemirror/cells/traceback-decorations.ts +10 -11
  202. package/src/core/codemirror/code-lens/__tests__/entities.test.ts +7 -11
  203. package/src/core/codemirror/code-lens/__tests__/extension.test.ts +38 -12
  204. package/src/core/codemirror/code-lens/__tests__/perf.test.ts +7 -9
  205. package/src/core/codemirror/code-lens/extension.ts +21 -13
  206. package/src/core/codemirror/copilot/__tests__/getCodes.test.ts +9 -14
  207. package/src/core/codemirror/copilot/getCodes.ts +3 -14
  208. package/src/core/codemirror/debounced-editor-update.ts +41 -0
  209. package/src/core/codemirror/editor-mount-scheduler.ts +41 -48
  210. package/src/core/codemirror/extensions.ts +2 -2
  211. package/src/core/codemirror/find-replace/__tests__/navigate.test.ts +42 -16
  212. package/src/core/codemirror/find-replace/__tests__/search-highlight.test.ts +30 -0
  213. package/src/core/codemirror/find-replace/__tests__/unmounted-cells.test.ts +145 -0
  214. package/src/core/codemirror/find-replace/navigate.ts +88 -129
  215. package/src/core/codemirror/find-replace/search-highlight.ts +3 -1
  216. package/src/core/codemirror/find-replace/state.ts +7 -2
  217. package/src/core/codemirror/format.ts +25 -31
  218. package/src/core/codemirror/go-to-definition/__tests__/underline.test.ts +58 -0
  219. package/src/core/codemirror/go-to-definition/__tests__/utils.test.ts +24 -44
  220. package/src/core/codemirror/go-to-definition/extension.ts +9 -7
  221. package/src/core/codemirror/go-to-definition/underline.ts +39 -48
  222. package/src/core/codemirror/language/__tests__/sql.test.ts +36 -0
  223. package/src/core/codemirror/language/cell-code.ts +7 -0
  224. package/src/core/codemirror/language/embedded/__tests__/embedded-python.test.ts +2 -18
  225. package/src/core/codemirror/language/languages/sql/sql.ts +3 -0
  226. package/src/core/codemirror/lsp/__tests__/notebook-lsp.test.ts +25 -0
  227. package/src/core/codemirror/lsp/notebook-lsp.ts +6 -16
  228. package/src/core/codemirror/placeholder/extensions.ts +26 -24
  229. package/src/core/codemirror/reactive-references/__tests__/extension.test.ts +54 -0
  230. package/src/core/codemirror/reactive-references/extension.ts +30 -21
  231. package/src/core/codemirror/use-lazy-editor-mount.ts +70 -0
  232. package/src/core/codemirror/utils.ts +2 -6
  233. package/src/core/datasets/__tests__/data-source.test.ts +15 -17
  234. package/src/core/datasets/data-source-connections.ts +8 -11
  235. package/src/core/datasets/state.ts +7 -12
  236. package/src/core/executions/__tests__/atoms.test.ts +211 -5
  237. package/src/core/executions/__tests__/freshness.test.ts +65 -56
  238. package/src/core/executions/__tests__/interrupt.test.ts +5 -3
  239. package/src/core/executions/__tests__/output-lifecycle.test.ts +95 -7
  240. package/src/core/executions/__tests__/output.test.ts +5 -3
  241. package/src/core/executions/__tests__/run.test.ts +4 -4
  242. package/src/core/executions/__tests__/select.test.ts +108 -69
  243. package/src/core/executions/atoms.ts +248 -83
  244. package/src/core/executions/freshness.ts +7 -7
  245. package/src/core/executions/hooks.ts +15 -59
  246. package/src/core/executions/index.ts +2 -0
  247. package/src/core/executions/output.ts +49 -35
  248. package/src/core/executions/select.ts +90 -37
  249. package/src/core/export/__tests__/hooks.test.ts +1 -1
  250. package/src/core/islands/__tests__/bridge.test.ts +1 -1
  251. package/src/core/islands/bootstrap.ts +7 -7
  252. package/src/core/islands/bridge.ts +1 -1
  253. package/src/core/meta/__tests__/code-visibility.test.tsx +3 -2
  254. package/src/core/notebook/document/__tests__/codemirror.test.ts +8 -6
  255. package/src/core/notebook/document/__tests__/draft.test.ts +56 -58
  256. package/src/core/notebook/document/__tests__/fixtures.ts +8 -7
  257. package/src/core/notebook/document/__tests__/hooks.test.tsx +39 -35
  258. package/src/core/notebook/document/__tests__/lifecycle-scenarios.test.ts +8 -5
  259. package/src/core/notebook/document/__tests__/model.test.ts +8 -5
  260. package/src/core/notebook/document/__tests__/protocol-fixtures.ts +2 -2
  261. package/src/core/notebook/document/__tests__/recovery-scenarios.test.ts +37 -32
  262. package/src/core/notebook/document/__tests__/scenarios.test.ts +49 -45
  263. package/src/core/notebook/document/__tests__/state.test.ts +59 -56
  264. package/src/core/notebook/document/__tests__/submission.test.ts +15 -12
  265. package/src/core/notebook/document/__tests__/test-host.ts +3 -2
  266. package/src/core/notebook/document/__tests__/user.ts +7 -3
  267. package/src/core/notebook/document/draft.ts +29 -11
  268. package/src/core/notebook/document/state.ts +7 -6
  269. package/src/core/notebook/replica/__tests__/document.test.ts +9 -5
  270. package/src/core/notebook/replica/__tests__/executions.test.ts +90 -25
  271. package/src/core/notebook/replica/__tests__/fixtures.ts +6 -2
  272. package/src/core/notebook/replica/__tests__/frame.test.ts +206 -0
  273. package/src/core/notebook/replica/__tests__/once-per-frame.test.ts +95 -0
  274. package/src/core/notebook/replica/__tests__/replica.test.ts +53 -9
  275. package/src/core/notebook/replica/__tests__/results.test.ts +27 -29
  276. package/src/core/notebook/replica/execution-state.ts +2 -2
  277. package/src/core/notebook/replica/frame.ts +54 -0
  278. package/src/core/notebook/replica/index.ts +1 -0
  279. package/src/core/notebook/replica/once-per-frame.ts +60 -0
  280. package/src/core/notebook/replica/replica.ts +27 -6
  281. package/src/core/notebook/replica/resources/analysis.ts +1 -1
  282. package/src/core/notebook/replica/resources/document.ts +9 -8
  283. package/src/core/notebook/replica/resources/executions.ts +197 -78
  284. package/src/core/notebook/replica/resources/results.ts +8 -14
  285. package/src/core/saving/__tests__/document.test.tsx +1 -1
  286. package/src/core/saving/__tests__/state.test.ts +2 -2
  287. package/src/core/session/__tests__/useNotebookReplica.hook.test.tsx +55 -9
  288. package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +230 -12
  289. package/src/core/session/active-notebook.ts +4 -1
  290. package/src/core/session/useNotebookReplica.ts +15 -2
  291. package/src/core/session/useNotebookSession.tsx +38 -46
  292. package/src/core/state/__tests__/atom-with-selected-inputs.test.ts +48 -0
  293. package/src/core/state/__tests__/create-keyed-selector-hook.test.tsx +137 -0
  294. package/src/core/state/atom-with-selected-inputs.ts +24 -0
  295. package/src/core/state/create-keyed-atom-hook.ts +18 -0
  296. package/src/core/state/create-keyed-selector-hook.ts +22 -0
  297. package/src/core/storage/__tests__/state.test.ts +6 -9
  298. package/src/core/storage/state.ts +5 -8
  299. package/src/core/transports/__tests__/static.test.ts +3 -2
  300. package/src/core/transports/static.ts +2 -2
  301. package/src/core/variables/state.ts +73 -68
  302. package/src/core/variables/types.ts +2 -2
  303. package/src/core/vscode/__tests__/is-in-vscode.test.ts +36 -0
  304. package/src/core/vscode/is-in-vscode.ts +2 -2
  305. package/src/core/wasm/__tests__/bridge.test.ts +73 -1
  306. package/src/core/wasm/bridge.ts +5 -4
  307. package/src/plugins/impl/TextInputPlugin.tsx +2 -1
  308. package/src/plugins/impl/__test__/text-labels.test.tsx +46 -1
  309. package/src/utils/__tests__/lazy.test.tsx +33 -0
  310. package/src/utils/__tests__/shared-intersection-observer.test.ts +49 -0
  311. package/src/utils/__tests__/shared-resource.test.ts +107 -0
  312. package/src/utils/arrays.ts +4 -1
  313. package/src/utils/lazy.tsx +74 -0
  314. package/src/utils/shared-intersection-observer.ts +53 -0
  315. package/src/utils/shared-resource.ts +59 -0
  316. package/src/core/variables/__tests__/state.test.ts +0 -148
  317. package/src/utils/lazy.ts +0 -35
@@ -1,7 +1,7 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import type * as Protocol from "@marimo-team/client/protocol";
4
- import type { NotebookResource } from "@marimo-team/client";
4
+ import type { HandlerContext, NotebookResource } from "@marimo-team/client";
5
5
  import {
6
6
  type Result,
7
7
  type Results,
@@ -18,15 +18,15 @@ type ProducedItem =
18
18
  /** Time the host published the item, when included in a live event. */
19
19
  export type Item = ProducedItem & { readonly time?: string };
20
20
 
21
- /** An execution on the stream, with the items and variables it has produced. */
21
+ type ExecutionItem = Protocol.Output | Protocol.Variable | Item;
22
+
23
+ /** An execution on the stream, with the items it has produced. */
22
24
  export interface Execution extends Result {
23
25
  /** Items by id. `itemsInOrder` sorts them by `seq`. */
24
26
  readonly lastSeq?: number;
25
27
  /** Fast path for a reader displaying exactly the version before an append. */
26
28
  readonly append?: { before: WeakRef<Execution["items"]>; item: Item };
27
29
  readonly items: ReadonlyMap<Protocol.ItemId, Item>;
28
- /** The variables the execution bound, by item id. */
29
- readonly variables: ReadonlyMap<Protocol.ItemId, Protocol.Variable>;
30
30
  }
31
31
 
32
32
  /**
@@ -36,11 +36,21 @@ export interface Execution extends Result {
36
36
  * stays for display while a new execution runs.
37
37
  */
38
38
  export interface Executions {
39
- readonly runs: ReadonlyMap<Protocol.RunId, Protocol.Run>;
39
+ readonly runs: ReadonlyMap<Protocol.RunId, Protocol.RunOutput>;
40
40
  /** Every execution on the stream, scratch included. */
41
41
  readonly executions: ReadonlyMap<Protocol.ExecutionId, Execution>;
42
- /** The execution on the stream for each cell that has one. */
42
+ /** The unfinished execution for each cell, or its latest completed one. */
43
43
  readonly latest: ReadonlyMap<Protocol.CellId, Protocol.ExecutionId>;
44
+ /** Bindings by defining cell and item id, shared across unrelated stream updates. */
45
+ readonly variables: ReadonlyMap<
46
+ Protocol.CellId,
47
+ ReadonlyMap<Protocol.ItemId, Protocol.Variable>
48
+ >;
49
+ /** Items received during snapshot or replay before their owning execution. */
50
+ readonly pendingItems?: ReadonlyMap<
51
+ Protocol.ExecutionId,
52
+ readonly ExecutionItem[]
53
+ >;
44
54
  readonly results: Results;
45
55
  readonly scratch: Result | null;
46
56
  /** The latest scratch execution to start, including one that printed nothing. */
@@ -56,7 +66,7 @@ export interface RunFailure {
56
66
  readonly completedAt: string;
57
67
  }
58
68
 
59
- function hostFailure(run: Protocol.Run): RunFailure | undefined {
69
+ function hostFailure(run: Protocol.RunOutput): RunFailure | undefined {
60
70
  const { state } = run;
61
71
  return state.status === "completed" &&
62
72
  state.outcome.kind === "failed" &&
@@ -115,57 +125,60 @@ function retainScratchConsole(
115
125
  : current;
116
126
  }
117
127
 
118
- /** Replace an execution on the stream, indexed under its cell. */
128
+ /** Replace an execution without changing which execution its cell is running. */
119
129
  function set(state: Executions, execution: Execution): Executions {
120
- const { id, cell_id: cellId } = execution.record;
130
+ const { id } = execution.record;
121
131
  return {
122
132
  ...state,
123
133
  executions: new Map(state.executions).set(id, execution),
124
134
  scratchConsole: retainScratchConsole(state, execution),
125
- latest:
126
- cellId === null || state.latest.get(cellId) === id
127
- ? state.latest
128
- : new Map(state.latest).set(cellId, id),
129
135
  };
130
136
  }
131
137
 
132
138
  function remove(state: Executions, id: Protocol.ExecutionId): Executions {
133
139
  const execution = state.executions.get(id);
134
140
  if (execution === undefined) {
135
- return state;
141
+ return state.pendingItems?.has(id)
142
+ ? { ...state, pendingItems: without(state.pendingItems, id) }
143
+ : state;
136
144
  }
137
145
  const cellId = execution.record.cell_id;
146
+ const isLatest = cellId !== null && state.latest.get(cellId) === id;
147
+ const executions = without(state.executions, id);
148
+ let latest = state.latest;
149
+ if (isLatest) {
150
+ const retained = state.results.get(cellId);
151
+ latest =
152
+ retained && executions.has(retained.record.id)
153
+ ? new Map(latest).set(cellId, retained.record.id)
154
+ : without(latest, cellId);
155
+ }
138
156
  return {
139
157
  ...state,
140
- executions: without(state.executions, id),
158
+ executions,
159
+ latest,
160
+ variables: isLatest ? without(state.variables, cellId) : state.variables,
141
161
  scratchConsole:
142
162
  state.scratchConsole?.record.id === id ? undefined : state.scratchConsole,
143
- latest:
144
- cellId !== null && state.latest.get(cellId) === id
145
- ? without(state.latest, cellId)
146
- : state.latest,
147
163
  };
148
164
  }
149
165
 
150
- function attach(state: Executions, item: Item): Executions {
151
- const execution = state.executions.get(item.execution_id);
152
- if (execution === undefined) {
153
- return state;
154
- }
155
- // Updating an input's status keeps the prompt at its original position.
156
- const original = execution.items.get(item.id);
157
- if (original) {
158
- item = { ...item, time: original.time };
166
+ function withRows(execution: Execution, entries: readonly Item[]): Execution {
167
+ const items = new Map(execution.items);
168
+ let lastSeq = execution.lastSeq ?? -1;
169
+ let append: Execution["append"];
170
+ for (let item of entries) {
171
+ const original = items.get(item.id);
172
+ if (original) {
173
+ // An input keeps the position and time of its first prompt.
174
+ item = { ...item, time: original.time };
175
+ } else if (entries.length === 1 && item.seq > lastSeq) {
176
+ append = { before: new WeakRef(execution.items), item };
177
+ }
178
+ items.set(item.id, item);
179
+ lastSeq = Math.max(lastSeq, item.seq);
159
180
  }
160
- return set(state, {
161
- ...execution,
162
- append:
163
- !original && item.seq > (execution.lastSeq ?? -1)
164
- ? { before: new WeakRef(execution.items), item }
165
- : undefined,
166
- lastSeq: Math.max(execution.lastSeq ?? -1, item.seq),
167
- items: new Map(execution.items).set(item.id, item),
168
- });
181
+ return { ...execution, append, lastSeq, items };
169
182
  }
170
183
 
171
184
  function detach(state: Executions, itemId: Protocol.ItemId): Executions {
@@ -178,27 +191,57 @@ function detach(state: Executions, itemId: Protocol.ItemId): Executions {
178
191
  });
179
192
  }
180
193
  }
181
- return state;
194
+ return removePendingItem(state, itemId);
182
195
  }
183
196
 
184
- function bind(state: Executions, variable: Protocol.Variable): Executions {
185
- const execution = state.executions.get(variable.execution_id);
186
- if (execution === undefined) {
197
+ function bind(
198
+ state: Executions,
199
+ execution: Execution,
200
+ variable: Protocol.Variable,
201
+ ): Executions {
202
+ const cellId = execution.record.cell_id;
203
+ if (cellId === null) {
187
204
  return state;
188
205
  }
189
- return set(state, {
190
- ...execution,
191
- variables: new Map(execution.variables).set(variable.id, variable),
192
- });
206
+ const bindings = new Map(state.variables.get(cellId)).set(
207
+ variable.id,
208
+ variable,
209
+ );
210
+ return {
211
+ ...state,
212
+ variables: new Map(state.variables).set(cellId, bindings),
213
+ };
193
214
  }
194
215
 
195
216
  function unbind(state: Executions, itemId: Protocol.ItemId): Executions {
196
- for (const execution of state.executions.values()) {
197
- if (execution.variables.has(itemId)) {
198
- return set(state, {
199
- ...execution,
200
- variables: without(execution.variables, itemId),
201
- });
217
+ for (const [cellId, bindings] of state.variables) {
218
+ if (bindings.has(itemId)) {
219
+ const variables = new Map(state.variables);
220
+ if (bindings.size === 1) {
221
+ variables.delete(cellId);
222
+ } else {
223
+ variables.set(cellId, without(bindings, itemId));
224
+ }
225
+ return { ...state, variables };
226
+ }
227
+ }
228
+ return removePendingItem(state, itemId);
229
+ }
230
+
231
+ function removePendingItem(
232
+ state: Executions,
233
+ itemId: Protocol.ItemId,
234
+ ): Executions {
235
+ for (const [id, items] of state.pendingItems ?? []) {
236
+ if (items.some((item) => item.id === itemId)) {
237
+ const remaining = items.filter((item) => item.id !== itemId);
238
+ const pendingItems = new Map(state.pendingItems);
239
+ if (remaining.length === 0) {
240
+ pendingItems.delete(id);
241
+ } else {
242
+ pendingItems.set(id, remaining);
243
+ }
244
+ return { ...state, pendingItems };
202
245
  }
203
246
  }
204
247
  return state;
@@ -220,6 +263,37 @@ function update(state: Executions, execution: Execution): Executions {
220
263
  };
221
264
  }
222
265
 
266
+ function receiveItem(
267
+ state: Executions,
268
+ item: ExecutionItem,
269
+ phase: HandlerContext["phase"],
270
+ ): Executions {
271
+ const id = item.execution_id;
272
+ const execution = state.executions.get(id);
273
+ if (execution === undefined) {
274
+ if (phase === "live") {
275
+ return state;
276
+ }
277
+ const items = state.pendingItems?.get(id) ?? [];
278
+ return {
279
+ ...state,
280
+ pendingItems: new Map(state.pendingItems).set(id, [...items, item]),
281
+ };
282
+ }
283
+ if ("kind" in item) {
284
+ return set(state, withRows(execution, [item]));
285
+ }
286
+ if ("revision" in item) {
287
+ return bind(state, execution, item);
288
+ }
289
+ const next = { ...execution, output: item };
290
+ return update(state, {
291
+ ...next,
292
+ outputVersion:
293
+ execution.outputVersion + (sameShown(execution, next) ? 0 : 1),
294
+ });
295
+ }
296
+
223
297
  /** Carry displayed results and their revisions through a replacement snapshot. */
224
298
  export function resumeResults(
225
299
  next: Executions,
@@ -282,14 +356,25 @@ export const executions: NotebookResource<Executions, Kind> = {
282
356
  runs: new Map(),
283
357
  executions: new Map(),
284
358
  latest: new Map(),
359
+ variables: new Map(),
285
360
  results: new Map(),
286
361
  scratch: null,
287
362
  },
288
363
  on: {
289
- cell: (state, { data }) =>
290
- state.results.has(data.cell.id)
291
- ? state
292
- : { ...state, results: new Map(state.results).set(data.cell.id, null) },
364
+ cell: (state, { data: { cell } }, { phase }) => {
365
+ if (state.results.has(cell.id)) {
366
+ return state;
367
+ }
368
+ let results: Results = new Map(state.results).set(cell.id, null);
369
+ if (phase !== "live" && state.latest.has(cell.id)) {
370
+ for (const execution of state.executions.values()) {
371
+ if (execution.record.cell_id === cell.id) {
372
+ results = retainResult(results, execution);
373
+ }
374
+ }
375
+ }
376
+ return { ...state, results };
377
+ },
293
378
  "cell.removed": (state, { data }) => ({
294
379
  ...state,
295
380
  results: without(state.results, data.id),
@@ -307,10 +392,10 @@ export const executions: NotebookResource<Executions, Kind> = {
307
392
  state.runs.has(data.id)
308
393
  ? { ...state, runs: without(state.runs, data.id) }
309
394
  : state,
310
- execution: (state, { data: { execution: record } }) => {
395
+ execution: (state, { data: { execution: record } }, { phase }) => {
311
396
  const previous = state.executions.get(record.id);
312
397
  const next = { record, output: previous?.output ?? null };
313
- return update(state, {
398
+ const execution: Execution = {
314
399
  ...next,
315
400
  outputVersion:
316
401
  previous === undefined
@@ -319,30 +404,64 @@ export const executions: NotebookResource<Executions, Kind> = {
319
404
  append: previous?.append,
320
405
  lastSeq: previous?.lastSeq,
321
406
  items: previous?.items ?? new Map(),
322
- variables: previous?.variables ?? new Map(),
323
- });
324
- },
325
- "execution.removed": (state, { data }) => remove(state, data.id),
326
- output: (state, { data: { output } }) => {
327
- const execution = state.executions.get(output.execution_id);
328
- if (execution === undefined) {
329
- return state;
407
+ };
408
+ const items = state.pendingItems?.get(record.id);
409
+ // All buffered console rows and prompts appear in this single update.
410
+ const rows = items?.filter((item) => "kind" in item);
411
+ let updated = update(
412
+ state,
413
+ rows?.length ? withRows(execution, rows) : execution,
414
+ );
415
+ if (items && state.pendingItems) {
416
+ updated = {
417
+ ...updated,
418
+ pendingItems: without(state.pendingItems, record.id),
419
+ };
420
+ for (const item of items) {
421
+ if (!("kind" in item)) {
422
+ updated = receiveItem(updated, item, phase);
423
+ }
424
+ }
330
425
  }
331
- const next = { ...execution, output };
332
- return update(state, {
333
- ...next,
334
- outputVersion:
335
- execution.outputVersion + (sameShown(execution, next) ? 0 : 1),
336
- });
426
+ const cellId = record.cell_id;
427
+ if (cellId === null || previous !== undefined) {
428
+ return updated;
429
+ }
430
+ const latest = state.latest.get(cellId);
431
+ // A snapshot can deliver the completed predecessor after its successor.
432
+ if (
433
+ phase === "snapshot" &&
434
+ latest !== undefined &&
435
+ record.state.status === "completed" &&
436
+ state.executions.get(latest)?.record.state.status !== "completed"
437
+ ) {
438
+ return updated;
439
+ }
440
+ return {
441
+ ...updated,
442
+ latest: new Map(state.latest).set(cellId, record.id),
443
+ };
337
444
  },
338
- // The output leaves with its execution, and a retained result keeps its copy.
339
- "output.removed": (state) => state,
340
- console: (state, { data }) =>
341
- attach(state, { ...data.console, kind: "console", time: data.time }),
445
+ "execution.removed": (state, { data }) => remove(state, data.id),
446
+ output: (state, { data }, { phase }) =>
447
+ receiveItem(state, data.output, phase),
448
+ console: (state, { data }, { phase }) =>
449
+ receiveItem(
450
+ state,
451
+ { ...data.console, kind: "console", time: data.time },
452
+ phase,
453
+ ),
342
454
  "console.removed": (state, { data }) => detach(state, data.id),
343
- input: (state, { data }) =>
344
- attach(state, { ...data.input, kind: "input", time: data.time }),
345
- variable: (state, { data }) => bind(state, data.variable),
455
+ input: (state, { data }, { phase }) =>
456
+ receiveItem(
457
+ state,
458
+ { ...data.input, kind: "input", time: data.time },
459
+ phase,
460
+ ),
461
+ variable: (state, { data }, { phase }) =>
462
+ receiveItem(state, data.variable, phase),
346
463
  "variable.removed": (state, { data }) => unbind(state, data.id),
464
+ ready: (state) =>
465
+ state.pendingItems ? { ...state, pendingItems: undefined } : state,
347
466
  },
348
467
  };
@@ -5,7 +5,7 @@ import { completedAt, shown, startedAt } from "../execution-state";
5
5
 
6
6
  /** An execution record and its output, with the local revision of what it shows. */
7
7
  export interface Result {
8
- readonly record: Protocol.Execution;
8
+ readonly record: Protocol.ExecutionOutput;
9
9
  /** The execution's output item, null until it sets one. */
10
10
  readonly output: Protocol.Output | null;
11
11
  /** Unchanged by lifecycle-only events. */
@@ -13,21 +13,15 @@ export interface Result {
13
13
  }
14
14
 
15
15
  /**
16
- * Each document cell's last completed execution record.
16
+ * Each document cell's last completed execution that was not superseded.
17
17
  *
18
- * The host removes a cell's previous execution before it publishes the
19
- * next one. A result stays until a newer execution for the cell completes
20
- * or the cell leaves the document, so a cell can show its last outcome
21
- * while it runs again. The record, its output, and the output revision are
22
- * kept; the items and variables stay with the stream's copy of the execution.
18
+ * A superseded attempt leaves the previous result visible while its replacement
19
+ * is queued or running. The result holds the record, its output, and the
20
+ * output revision. Other items stay with the stream's copy of the execution.
23
21
  *
24
22
  * A cell has an entry from its `cell` event until its removal, null until
25
- * it completes once. Cells precede their executions on the stream, so a
26
- * completion for a cell without an entry belongs to a cell the document
27
- * no longer has.
28
- *
29
- * An execution the host skipped as superseded never ran, and a newer one
30
- * for the same cell is on its way, so it does not replace the result.
23
+ * it has a result. If the cell arrives after its execution during catch-up,
24
+ * the replica fills its entry from the execution it has already received.
31
25
  */
32
26
  export type Results = ReadonlyMap<Protocol.CellId, Result | null>;
33
27
 
@@ -55,7 +49,7 @@ export function retainScratchResult(
55
49
  if (record.cell_id !== null || shown(result) === null) {
56
50
  return previous;
57
51
  }
58
- const time = (execution: Protocol.Execution) =>
52
+ const time = (execution: Protocol.ExecutionOutput) =>
59
53
  Date.parse(
60
54
  completedAt(execution) ?? startedAt(execution) ?? "1970-01-01T00:00:00Z",
61
55
  );
@@ -17,7 +17,7 @@ import { activeNotebookReplicaAtom } from "@/core/session/active-notebook";
17
17
  import { Deferred } from "@/utils/Deferred";
18
18
  import { useNotebookDocumentSave } from "../document";
19
19
 
20
- const confirmed: Protocol.Document = {
20
+ const confirmed: Protocol.DocumentOutput = {
21
21
  notebook_id: "n1",
22
22
  order: [],
23
23
  app_config: {},
@@ -17,8 +17,8 @@ import { initialLayoutState, layoutStateAtom } from "../../layout/state";
17
17
  import { documentVersionAtom, needsSaveAtom, savedLayoutAtom } from "../state";
18
18
 
19
19
  function revision(
20
- overrides: Partial<Protocol.Document> = {},
21
- ): Protocol.Document {
20
+ overrides: Partial<Protocol.DocumentOutput> = {},
21
+ ): Protocol.DocumentOutput {
22
22
  return {
23
23
  notebook_id: "nb",
24
24
  order: [],
@@ -4,7 +4,7 @@
4
4
  import { act, renderHook } from "@testing-library/react";
5
5
  import { createStore, Provider } from "jotai";
6
6
  import type { PropsWithChildren } from "react";
7
- import { beforeEach, describe, expect, it, vi } from "vitest";
7
+ import { beforeEach, describe, expect, it, vi, onTestFinished } from "vitest";
8
8
  import type { NotebookTransport } from "@marimo-team/client";
9
9
  import type { AttachmentOutput } from "@marimo-team/client/protocol";
10
10
  import { ConnectionState } from "../types";
@@ -14,15 +14,19 @@ import {
14
14
  fakeBackend,
15
15
  fixtureMessages,
16
16
  } from "../../notebook/replica/__tests__/fixtures";
17
+ import { mockAnimationFrames } from "@/__mocks__/animation-frames";
17
18
  import { useNotebookAttachments } from "@/core/notebook";
18
- import { activeNotebookReplicaAtom } from "../active-notebook";
19
+ import {
20
+ activeNotebookReplicaAtom,
21
+ activeNotebookFrameAtom,
22
+ } from "../active-notebook";
19
23
 
20
24
  vi.mock("../backend", () => ({ createEditorBackend: vi.fn() }));
21
25
 
22
26
  /** A host-framed native notification. */
23
27
  const notification = {
24
28
  event: "marimo",
25
- data: { marimo: { op: "interrupted" } },
29
+ data: { marimo: { op: "reload" } },
26
30
  };
27
31
 
28
32
  /** A transport whose connections the test drives. */
@@ -95,9 +99,12 @@ describe("useNotebookReplica", () => {
95
99
  await act(async () => Promise.resolve());
96
100
  expect(store.get(activeNotebookReplicaAtom)).toBe(result.current);
97
101
  const [connection] = fake.opened;
102
+ const receive = (message: unknown) => {
103
+ connection.receive(message);
104
+ };
98
105
  act(() => {
99
106
  connection.open();
100
- fixtureMessages("notebook-events.sse").forEach(connection.receive);
107
+ fixtureMessages("notebook-events.sse").forEach(receive);
101
108
  });
102
109
  expect(attachments.result.current.agents).toEqual([
103
110
  {
@@ -120,7 +127,7 @@ describe("useNotebookReplica", () => {
120
127
  (attachment) => attachment.kind === "browser",
121
128
  )!;
122
129
  act(() =>
123
- connection.receive({
130
+ receive({
124
131
  event: "attachment",
125
132
  data: { attachment: { ...browser, name: "Firefox" } },
126
133
  }),
@@ -129,7 +136,7 @@ describe("useNotebookReplica", () => {
129
136
 
130
137
  const renamedAgent = { ...agents[0], name: "Renamed agent" };
131
138
  act(() =>
132
- connection.receive({
139
+ receive({
133
140
  event: "attachment",
134
141
  data: { attachment: renamedAgent },
135
142
  }),
@@ -151,10 +158,12 @@ describe("useNotebookReplica", () => {
151
158
  await act(async () => Promise.resolve());
152
159
  const onNotification = vi.fn();
153
160
  rerender({ ...options, onNotification, url: () => "ws://redirected/ws" });
154
- act(() => fake.notify());
161
+ act(() => {
162
+ fake.notify();
163
+ });
155
164
  expect(options.onNotification).not.toHaveBeenCalled();
156
165
  expect(onNotification).toHaveBeenCalledExactlyOnceWith({
157
- data: { op: "interrupted" },
166
+ data: { op: "reload" },
158
167
  });
159
168
  const [{ url }] = vi.mocked(createEditorBackend).mock.calls[0];
160
169
  expect(url()).toBe("ws://redirected/ws");
@@ -176,7 +185,9 @@ describe("useNotebookReplica", () => {
176
185
  expect(store.get(result.current.connectionAtom)).toEqual({
177
186
  state: ConnectionState.OPEN,
178
187
  });
179
- act(() => fake.opened.forEach((attempt) => attempt.receive(notification)));
188
+ act(() => {
189
+ fake.opened.forEach((attempt) => attempt.receive(notification));
190
+ });
180
191
  expect(options.onNotification).toHaveBeenCalledOnce();
181
192
  unmount();
182
193
  expect(active.signal.aborted).toBe(true);
@@ -185,3 +196,38 @@ describe("useNotebookReplica", () => {
185
196
  expect(fake.opened).toHaveLength(attempts);
186
197
  });
187
198
  });
199
+
200
+ it("publishes views once per frame while delivering notifications immediately", async () => {
201
+ const advanceFrame = mockAnimationFrames();
202
+ const fake = makeTransport();
203
+ vi.mocked(createEditorBackend).mockReturnValue(
204
+ fakeBackend({ transport: fake.transport }),
205
+ );
206
+ const { result, options, store, unmount } = setup();
207
+ onTestFinished(unmount);
208
+ await act(async () => Promise.resolve());
209
+ const [connection] = fake.opened;
210
+ act(() => {
211
+ connection.open();
212
+ fixtureMessages("notebook-events.sse").forEach(connection.receive);
213
+ });
214
+ act(advanceFrame);
215
+ const changed = vi.fn();
216
+ const frame = store.get(activeNotebookFrameAtom)!;
217
+ onTestFinished(store.sub(frame.executionsAtom, changed));
218
+ options.onNotification.mockClear();
219
+ act(() => {
220
+ fixtureMessages("run-cells.sse").forEach(connection.receive);
221
+ connection.receive(notification);
222
+ });
223
+ expect(changed).not.toHaveBeenCalled();
224
+ expect(options.onNotification).toHaveBeenCalledOnce();
225
+ expect(store.get(result.current.executionsAtom)).not.toBe(
226
+ store.get(frame.executionsAtom),
227
+ );
228
+ act(advanceFrame);
229
+ expect(changed).toHaveBeenCalledTimes(1);
230
+ expect(options.onNotification).toHaveBeenCalledExactlyOnceWith({
231
+ data: { op: "reload" },
232
+ });
233
+ });