@marimo-team/islands 0.23.10-dev8 → 0.23.10

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 (188) hide show
  1. package/dist/{ConnectedDataExplorerComponent-CyV83R2m.js → ConnectedDataExplorerComponent-Z3RP7Vmm.js} +31 -31
  2. package/dist/{ErrorBoundary-rULOrC_p.js → ErrorBoundary-DpbaKVv7.js} +1 -1
  3. package/dist/{any-language-editor-CiES2a2h.js → any-language-editor-CAgFD4Kd.js} +20 -20
  4. package/dist/assets/__vite-browser-external-eshhtsgZ.js +1 -0
  5. package/dist/assets/worker-CC0Oul9k.js +73 -0
  6. package/dist/{chat-ui-K84W5ecY.js → chat-ui-C4-GMW9y.js} +77 -77
  7. package/dist/{check-DTbrK0zt.js → check-BCaJeT-J.js} +1 -1
  8. package/dist/{chunk-5FQGJX7Z-BNjes6Yx.js → chunk-5FQGJX7Z-BbqSm5gU.js} +1227 -1222
  9. package/dist/{code-block-37QAKDTI-m92Yc8pv.js → code-block-37QAKDTI-O6IH6wAi.js} +1 -1
  10. package/dist/{code-visibility-ChnpTxqU.js → code-visibility-DrFozVlm.js} +1943 -1223
  11. package/dist/{copy-5jQ_kGE1.js → copy-UqRYxiOg.js} +1 -1
  12. package/dist/dist-7QfXoMdB.js +5 -0
  13. package/dist/{dist-DgnE8F-r.js → dist-A2846XWO.js} +1 -1
  14. package/dist/dist-BEXXyZig.js +5 -0
  15. package/dist/{dist-B3pZ0Ab6.js → dist-BR_gyG9L.js} +3 -3
  16. package/dist/{dist-CcXxepx6.js → dist-BSAt6RhH.js} +27 -27
  17. package/dist/{dist-Bde4a2kU.js → dist-BY018Paw.js} +8 -8
  18. package/dist/dist-BYj57OV4.js +5 -0
  19. package/dist/{dist-CUCNs1ja.js → dist-BaoDKvdy.js} +2 -2
  20. package/dist/{dist-Cy1WxgBD.js → dist-Bf7SHuNp.js} +5 -5
  21. package/dist/{dist-Bz_sYWbr.js → dist-Bk75fBZA.js} +2 -2
  22. package/dist/dist-BlSvQzNr.js +5 -0
  23. package/dist/{dist-C5VC_yzu.js → dist-BzEzfugY.js} +1 -1
  24. package/dist/dist-CCBlxAgS.js +8 -0
  25. package/dist/dist-CIDTVIUf.js +5 -0
  26. package/dist/{dist-CLUtPrdy.js → dist-CIYBwstr.js} +1 -1
  27. package/dist/{dist-BotSqB48.js → dist-C_Y3oV3C.js} +12 -12
  28. package/dist/{dist-BTfv03uy.js → dist-CcWX6tmx.js} +2 -2
  29. package/dist/{dist-BhM8gdSO.js → dist-CoXAujgg.js} +4 -4
  30. package/dist/{dist-4j4c7bjm.js → dist-CpxNdDkw.js} +3 -3
  31. package/dist/dist-CqQyhAM8.js +8 -0
  32. package/dist/dist-CwRu2Xzh.js +5 -0
  33. package/dist/{dist-BcuoonNH.js → dist-CxJDU6Bh.js} +9 -9
  34. package/dist/{dist-DxvORzUR.js → dist-D-W5ny5a.js} +8 -8
  35. package/dist/dist-D8CDTVgf.js +6 -0
  36. package/dist/dist-D8DNB0nO.js +8 -0
  37. package/dist/dist-DL6N_q-A.js +5 -0
  38. package/dist/{dist-BbbIBDiQ.js → dist-DMjWuVs8.js} +1 -1
  39. package/dist/dist-DOFbNV_b.js +8 -0
  40. package/dist/dist-DPrYzMY0.js +6 -0
  41. package/dist/{dist-h2c8sZvT.js → dist-DZORgqKY.js} +1 -1
  42. package/dist/{dist-B3P2fFpz.js → dist-DZo4nSS0.js} +14 -14
  43. package/dist/{dist-D4CewLk6.js → dist-Dax--nl9.js} +1 -1
  44. package/dist/{dist-DRfcqpxJ.js → dist-DgGbNavJ.js} +2 -2
  45. package/dist/{dist-C1BYNeCR.js → dist-Dk6PV_d3.js} +10 -10
  46. package/dist/{dist-fQ0ViXGs.js → dist-Dv_Y15yk.js} +107 -107
  47. package/dist/{dist-Bfwsv11D.js → dist-DyyjKEYf.js} +2 -2
  48. package/dist/{dist-p2qyWijU.js → dist-GZXUmt0b.js} +2 -2
  49. package/dist/{dist-CLJWPTX2.js → dist-LTU8Hdvn.js} +3 -3
  50. package/dist/{dist-DqAWR3CS.js → dist-M9Vag9Y0.js} +20 -20
  51. package/dist/{dist-DNdhYsgW.js → dist-U4F-tbMs.js} +79 -62
  52. package/dist/{dist-RqXTaiir.js → dist-abid3KgM.js} +11 -11
  53. package/dist/dist-cdmMjgsn.js +5 -0
  54. package/dist/dist-hT4QzYX-.js +1247 -0
  55. package/dist/{dist-luvabDEB.js → dist-t9Kf7xqC.js} +2 -2
  56. package/dist/{error-banner-5bz0L9hS.js → error-banner-CJXYJ6Sb.js} +11 -6
  57. package/dist/esm-BaH2eg5-.js +1171 -0
  58. package/dist/{esm-Duie8iU-.js → esm-ga2Bf3O2.js} +43 -43
  59. package/dist/{extends-CkydH1Q5.js → extends-D_hDsj6R.js} +4 -4
  60. package/dist/files/wasm-intro.py +11 -8
  61. package/dist/{formats-DHxc-FdY.js → formats-C4wO47tk.js} +1 -1
  62. package/dist/{glide-data-editor-CgIxTzAP.js → glide-data-editor-BPkCPs7L.js} +255 -255
  63. package/dist/{html-to-image-B93KtAVY.js → html-to-image-BwfcJJxA.js} +2412 -2282
  64. package/dist/{input-_2sjvfne.js → input-OdWHkobi.js} +263 -245
  65. package/dist/{label-LWtdw5i8.js → label-CC4ytI1X.js} +1 -1
  66. package/dist/main.js +7630 -7558
  67. package/dist/{mermaid-4DMBBIKO-DIdL224_.js → mermaid-4DMBBIKO-Eg3D4FVz.js} +1 -1
  68. package/dist/{mermaid-lXOw5Py9.js → mermaid-BotvIKg9.js} +4 -4
  69. package/dist/{process-output-BOXi9fnS.js → process-output-DsloEDna.js} +3 -3
  70. package/dist/{reveal-component-OrljHylW.js → reveal-component-3YQBHWuD.js} +698 -620
  71. package/dist/{spec-B96zNUEA.js → spec-X7FwLJni.js} +4 -4
  72. package/dist/{strings-Bu3vlb6W.js → strings-J57tzLr3.js} +47 -46
  73. package/dist/style.css +1 -1
  74. package/dist/{toDate-x-WRDCH7.js → toDate-d8RCRrRd.js} +2 -2
  75. package/dist/{tooltip-C5FYOpQc.js → tooltip-DpcyNkQ2.js} +2 -2
  76. package/dist/{types-CVvp1fKr.js → types-ChtMFmZ2.js} +1 -1
  77. package/dist/{useAsyncData-iRgKDT5s.js → useAsyncData-PonK__yh.js} +1 -1
  78. package/dist/{useDateFormatter-BA4FCquG.js → useDateFormatter-QB-3MpYr.js} +2 -2
  79. package/dist/{useDeepCompareMemoize-CkQ57VS2.js → useDeepCompareMemoize-D3NGWke6.js} +1 -1
  80. package/dist/{useLifecycle-BBO9PIph.js → useLifecycle-00mO3OSS.js} +2 -2
  81. package/dist/{useTheme-DHIrRQOe.js → useTheme-DEhDzATN.js} +1 -1
  82. package/dist/{vega-component-Dq-SH463.js → vega-component-DGPUhbDs.js} +8 -8
  83. package/dist/{zod-CoBiJ5v4.js → zod-aLSua2NL.js} +24 -23
  84. package/package.json +4 -3
  85. package/src/__tests__/setup.ts +16 -0
  86. package/src/components/chat/chat-display.tsx +2 -2
  87. package/src/components/data-table/TableBottomBar.tsx +1 -15
  88. package/src/components/data-table/TableTopBar.tsx +8 -13
  89. package/src/components/data-table/__tests__/TableBottomBar.test.tsx +6 -12
  90. package/src/components/data-table/__tests__/column-visibility-dropdown.test.tsx +227 -0
  91. package/src/components/data-table/column-visibility-dropdown.tsx +204 -0
  92. package/src/components/data-table/data-table.tsx +1 -1
  93. package/src/components/data-table/filter-by-values-picker.tsx +39 -17
  94. package/src/components/data-table/filter-pills.tsx +1 -1
  95. package/src/components/datasources/__tests__/filter-empty.test.ts +183 -0
  96. package/src/components/datasources/datasources.tsx +92 -3
  97. package/src/components/editor/cell/code/cell-editor.tsx +70 -32
  98. package/src/components/editor/cell/code/code-placeholder.css +18 -0
  99. package/src/components/editor/cell/code/code-placeholder.tsx +47 -0
  100. package/src/components/editor/cell/code/language-toggle.tsx +7 -1
  101. package/src/components/editor/chrome/wrapper/app-chrome.tsx +97 -52
  102. package/src/components/editor/chrome/wrapper/lazy-panels.ts +91 -0
  103. package/src/components/editor/chrome/wrapper/sidebar.tsx +2 -0
  104. package/src/components/editor/connections/storage/__tests__/__snapshots__/as-code.test.ts.snap +9 -2
  105. package/src/components/editor/connections/storage/__tests__/as-code.test.ts +62 -27
  106. package/src/components/editor/connections/storage/add-storage-form.tsx +5 -1
  107. package/src/components/editor/connections/storage/as-code.ts +20 -6
  108. package/src/components/editor/documentation.css +35 -0
  109. package/src/components/editor/file-tree/file-explorer.tsx +8 -18
  110. package/src/components/editor/file-tree/tree-actions.tsx +46 -1
  111. package/src/components/editor/notebook-cell.tsx +3 -3
  112. package/src/components/editor/renderers/slides-layout/__tests__/plugin.test.ts +20 -0
  113. package/src/components/editor/renderers/slides-layout/types.ts +1 -0
  114. package/src/components/markdown/__tests__/markdown-renderer.test.tsx +43 -0
  115. package/src/components/markdown/markdown-renderer.tsx +24 -1
  116. package/src/components/slides/__tests__/minimap-actions.test.tsx +166 -0
  117. package/src/components/slides/__tests__/reveal-component.test.ts +425 -0
  118. package/src/components/slides/minimap.tsx +127 -10
  119. package/src/components/slides/reveal-component.tsx +287 -61
  120. package/src/components/slides/slide-cell-view.tsx +26 -2
  121. package/src/components/slides/slide-form.tsx +26 -4
  122. package/src/components/storage/__tests__/storage-inspector.test.ts +180 -0
  123. package/src/components/storage/storage-inspector.tsx +535 -81
  124. package/src/components/ui/combobox.tsx +51 -32
  125. package/src/components/ui/number-field.tsx +5 -1
  126. package/src/components/ui/reorderable-list.tsx +13 -0
  127. package/src/components/ui/select-core/__tests__/use-select-list.test.ts +294 -0
  128. package/src/components/ui/select-core/__tests__/utils.test.ts +222 -0
  129. package/src/components/ui/select-core/index.ts +16 -0
  130. package/src/components/ui/select-core/option-row.tsx +33 -0
  131. package/src/components/ui/select-core/render-slot.ts +20 -0
  132. package/src/components/ui/select-core/select-list.tsx +248 -0
  133. package/src/components/ui/select-core/types.ts +44 -0
  134. package/src/components/ui/select-core/use-select-list.ts +347 -0
  135. package/src/components/ui/select-core/utils.ts +121 -0
  136. package/src/components/ui/toast.tsx +1 -0
  137. package/src/core/cells/__tests__/document-changes.test.ts +2 -2
  138. package/src/core/cells/__tests__/focus.test.ts +45 -2
  139. package/src/core/cells/focus.ts +1 -1
  140. package/src/core/cells/scrollCellIntoView.ts +4 -0
  141. package/src/core/cells/utils.ts +1 -1
  142. package/src/core/codemirror/__tests__/editor-mount-scheduler.test.ts +143 -0
  143. package/src/core/codemirror/copilot/getCodes.ts +3 -1
  144. package/src/core/codemirror/editor-mount-scheduler.ts +101 -0
  145. package/src/core/codemirror/language/languages/python.ts +2 -0
  146. package/src/core/codemirror/language/languages/sql/utils.ts +3 -1
  147. package/src/core/codemirror/lsp/__tests__/markdown-renderer.test.ts +41 -0
  148. package/src/core/codemirror/lsp/markdown-renderer.ts +59 -0
  149. package/src/core/datasets/data-source-connections.ts +2 -0
  150. package/src/core/errors/errors.ts +1 -1
  151. package/src/core/storage/__tests__/state.test.ts +49 -0
  152. package/src/core/storage/__tests__/useStorageEntries.test.tsx +199 -3
  153. package/src/core/storage/state.ts +124 -13
  154. package/src/core/storage/types.ts +6 -0
  155. package/src/core/wasm/worker/bootstrap.ts +12 -4
  156. package/src/plugins/core/__test__/registerReactComponent.test.ts +96 -0
  157. package/src/plugins/core/registerReactComponent.tsx +42 -10
  158. package/src/plugins/impl/MultiselectPlugin.tsx +19 -142
  159. package/src/plugins/impl/SearchableSelect.tsx +16 -97
  160. package/src/plugins/impl/SliderPlugin.tsx +132 -18
  161. package/src/plugins/impl/__tests__/DropdownPlugin.test.tsx +5 -2
  162. package/src/plugins/impl/__tests__/MultiSelectPlugin.test.ts +1 -1
  163. package/src/plugins/impl/__tests__/SliderPlugin.test.tsx +278 -8
  164. package/src/utils/__tests__/numbers.test.ts +20 -0
  165. package/src/utils/errors.ts +9 -0
  166. package/src/utils/lazy.ts +6 -1
  167. package/src/utils/numbers.ts +27 -0
  168. package/src/utils/schedule-task.ts +71 -0
  169. package/dist/assets/__vite-browser-external-Ci2ZQfXU.js +0 -1
  170. package/dist/assets/worker-ip3AI_sN.js +0 -73
  171. package/dist/dist-0Fif7jnk.js +0 -5
  172. package/dist/dist-B5h_9sHB.js +0 -6
  173. package/dist/dist-B9M6R5ye.js +0 -5
  174. package/dist/dist-BCt3tnck.js +0 -8
  175. package/dist/dist-BUIJwMwn.js +0 -8
  176. package/dist/dist-BpquMd3k.js +0 -5
  177. package/dist/dist-BzJsqYfz.js +0 -5
  178. package/dist/dist-CA5ELXAf.js +0 -6
  179. package/dist/dist-CLBRs6Uv.js +0 -5
  180. package/dist/dist-CStVCMbq.js +0 -5
  181. package/dist/dist-CZRIEY3Y.js +0 -8
  182. package/dist/dist-CuUHbFD0.js +0 -5
  183. package/dist/dist-DV7Iabxb.js +0 -8
  184. package/dist/dist-DhHh0jLg.js +0 -1247
  185. package/dist/dist-DuEeHMvL.js +0 -5
  186. package/dist/esm-CCuYCd3R.js +0 -1171
  187. package/src/plugins/impl/multiselectFilterFn.tsx +0 -22
  188. /package/src/components/{data-table → ui}/value-chips.tsx +0 -0
@@ -1,11 +1,15 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
- import { renderHook, waitFor } from "@testing-library/react";
3
+ import { act, renderHook, waitFor } from "@testing-library/react";
4
4
  import { createStore, Provider } from "jotai";
5
5
  import type { ReactNode } from "react";
6
6
  import * as React from "react";
7
7
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
8
- import { storageAtom, useStorageEntries } from "../state";
8
+ import {
9
+ storageAtom,
10
+ useStorageEntries,
11
+ useStoragePageFetcher,
12
+ } from "../state";
9
13
  import type { StorageEntry, StorageState } from "../types";
10
14
 
11
15
  const mockRequest = vi.fn();
@@ -175,13 +179,205 @@ describe("useStorageEntries", () => {
175
179
 
176
180
  it("should store fetched entries in the atom", async () => {
177
181
  const entries = [makeEntry({ path: "new.txt" })];
178
- mockRequest.mockResolvedValue({ entries });
182
+ mockRequest.mockResolvedValue({
183
+ entries,
184
+ next_page_token: "150",
185
+ });
179
186
 
180
187
  renderHook(() => useStorageEntries("ns", "sub/"), { wrapper });
181
188
 
182
189
  await waitFor(() => {
183
190
  const state = store.get(storageAtom);
184
191
  expect(state.entriesByPath.get("ns::sub/")).toEqual(entries);
192
+ expect(state.pageMetadataByPath.get("ns::sub/")?.nextPageToken).toBe(
193
+ "150",
194
+ );
195
+ });
196
+ });
197
+
198
+ it("should load more entries when a next page token exists", async () => {
199
+ const firstPage = [makeEntry({ path: "a.txt" })];
200
+ const secondPage = [makeEntry({ path: "b.txt" })];
201
+ mockRequest
202
+ .mockResolvedValueOnce({
203
+ entries: firstPage,
204
+ next_page_token: "150",
205
+ })
206
+ .mockResolvedValueOnce({
207
+ entries: secondPage,
208
+ next_page_token: null,
209
+ });
210
+
211
+ const { result } = renderHook(() => useStorageEntries("ns", "sub/"), {
212
+ wrapper,
213
+ });
214
+
215
+ await waitFor(() => {
216
+ expect(result.current.entries).toEqual(firstPage);
217
+ });
218
+ expect(result.current.hasMore).toBe(true);
219
+
220
+ await act(async () => {
221
+ await result.current.loadMore();
222
+ });
223
+
224
+ expect(result.current.entries).toEqual([...firstPage, ...secondPage]);
225
+ expect(result.current.hasMore).toBe(false);
226
+ expect(mockRequest).toHaveBeenLastCalledWith({
227
+ namespace: "ns",
228
+ prefix: "sub/",
229
+ limit: 150,
230
+ pageToken: "150",
231
+ });
232
+ });
233
+
234
+ it("should load more entries when the next page token is an empty string", async () => {
235
+ const firstPage = [makeEntry({ path: "a.txt" })];
236
+ const secondPage = [makeEntry({ path: "b.txt" })];
237
+ mockRequest
238
+ .mockResolvedValueOnce({
239
+ entries: firstPage,
240
+ next_page_token: "",
241
+ })
242
+ .mockResolvedValueOnce({
243
+ entries: secondPage,
244
+ next_page_token: null,
245
+ });
246
+
247
+ const { result } = renderHook(() => useStorageEntries("ns", "sub/"), {
248
+ wrapper,
249
+ });
250
+
251
+ await waitFor(() => {
252
+ expect(result.current.entries).toEqual(firstPage);
253
+ });
254
+ expect(result.current.hasMore).toBe(true);
255
+
256
+ await act(async () => {
257
+ await result.current.loadMore();
258
+ });
259
+
260
+ expect(result.current.entries).toEqual([...firstPage, ...secondPage]);
261
+ expect(result.current.hasMore).toBe(false);
262
+ expect(mockRequest).toHaveBeenLastCalledWith({
263
+ namespace: "ns",
264
+ prefix: "sub/",
265
+ limit: 150,
266
+ pageToken: "",
267
+ });
268
+ });
269
+
270
+ it("should ignore duplicate load more calls while a page is loading", async () => {
271
+ const firstPage = [makeEntry({ path: "a.txt" })];
272
+ const secondPage = [makeEntry({ path: "b.txt" })];
273
+ let resolveLoadMore!: (value: {
274
+ entries: StorageEntry[];
275
+ next_page_token: string | null;
276
+ }) => void;
277
+ const loadMorePromise = new Promise<{
278
+ entries: StorageEntry[];
279
+ next_page_token: string | null;
280
+ }>((resolve) => {
281
+ resolveLoadMore = resolve;
282
+ });
283
+ mockRequest
284
+ .mockResolvedValueOnce({
285
+ entries: firstPage,
286
+ next_page_token: "150",
287
+ })
288
+ .mockReturnValueOnce(loadMorePromise);
289
+
290
+ const { result } = renderHook(() => useStorageEntries("ns", "sub/"), {
291
+ wrapper,
292
+ });
293
+
294
+ await waitFor(() => {
295
+ expect(result.current.entries).toEqual(firstPage);
296
+ });
297
+
298
+ await act(async () => {
299
+ const firstLoad = result.current.loadMore();
300
+ const secondLoad = result.current.loadMore();
301
+
302
+ expect(mockRequest).toHaveBeenCalledTimes(2);
303
+ resolveLoadMore({
304
+ entries: secondPage,
305
+ next_page_token: null,
306
+ });
307
+ await Promise.all([firstLoad, secondLoad]);
308
+ });
309
+
310
+ expect(result.current.entries).toEqual([...firstPage, ...secondPage]);
311
+ expect(mockRequest).toHaveBeenCalledTimes(2);
312
+ });
313
+
314
+ it("should fetch arbitrary storage pages", async () => {
315
+ const firstPage = [makeEntry({ path: "folder/a.txt" })];
316
+ const secondPage = [makeEntry({ path: "folder/b.txt" })];
317
+ mockRequest
318
+ .mockResolvedValueOnce({
319
+ entries: firstPage,
320
+ next_page_token: "150",
321
+ })
322
+ .mockResolvedValueOnce({
323
+ entries: secondPage,
324
+ next_page_token: null,
325
+ });
326
+
327
+ const { result } = renderHook(() => useStoragePageFetcher(), {
328
+ wrapper,
329
+ });
330
+
331
+ await act(async () => {
332
+ await result.current({
333
+ namespace: "ns",
334
+ prefix: "folder/",
335
+ });
336
+ });
337
+ await act(async () => {
338
+ await result.current({
339
+ namespace: "ns",
340
+ prefix: "folder/",
341
+ pageToken: "150",
342
+ append: true,
343
+ });
344
+ });
345
+
346
+ expect(store.get(storageAtom).entriesByPath.get("ns::folder/")).toEqual([
347
+ ...firstPage,
348
+ ...secondPage,
349
+ ]);
350
+ expect(mockRequest).toHaveBeenLastCalledWith({
351
+ namespace: "ns",
352
+ prefix: "folder/",
353
+ limit: 150,
354
+ pageToken: "150",
355
+ });
356
+ });
357
+
358
+ it("should forward an empty string page token", async () => {
359
+ mockRequest.mockResolvedValue({
360
+ entries: [],
361
+ next_page_token: null,
362
+ });
363
+
364
+ const { result } = renderHook(() => useStoragePageFetcher(), {
365
+ wrapper,
366
+ });
367
+
368
+ await act(async () => {
369
+ await result.current({
370
+ namespace: "ns",
371
+ prefix: "folder/",
372
+ pageToken: "",
373
+ });
374
+ });
375
+
376
+ expect(mockRequest).toHaveBeenLastCalledWith({
377
+ namespace: "ns",
378
+ prefix: "folder/",
379
+ limit: 150,
380
+ pageToken: "",
185
381
  });
186
382
  });
187
383
  });
@@ -1,11 +1,15 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { atom, useAtomValue } from "jotai";
4
+ import { useCallback, useRef, useState } from "react";
4
5
  import { useAsyncData } from "@/hooks/useAsyncData";
5
6
  import { createReducerAndAtoms } from "@/utils/createReducer";
6
7
  import type { NotificationMessageData } from "../kernel/messages";
7
8
  import type { VariableName } from "../variables/types";
8
- import { ListStorageEntries } from "./request-registry";
9
+ import {
10
+ ListStorageEntries,
11
+ type StorageEntriesResult,
12
+ } from "./request-registry";
9
13
  import type { StorageEntry, StorageState } from "./types";
10
14
  import {
11
15
  DEFAULT_FETCH_LIMIT,
@@ -18,6 +22,7 @@ function initialState(): StorageState {
18
22
  return {
19
23
  namespaces: [],
20
24
  entriesByPath: new Map(),
25
+ pageMetadataByPath: new Map(),
21
26
  };
22
27
  }
23
28
 
@@ -48,23 +53,48 @@ const {
48
53
  namespace: string;
49
54
  prefix: string | null | undefined;
50
55
  entries: StorageEntry[];
56
+ nextPageToken?: string | null;
57
+ append?: boolean;
51
58
  },
52
59
  ) => {
53
60
  const key = storagePathKey(opts.namespace, opts.prefix);
54
61
  const entriesByPath = new Map(state.entriesByPath);
55
- entriesByPath.set(key, opts.entries);
56
- return { ...state, entriesByPath };
62
+ const entries =
63
+ opts.append && entriesByPath.has(key)
64
+ ? [...(entriesByPath.get(key) ?? []), ...opts.entries]
65
+ : opts.entries;
66
+ entriesByPath.set(key, entries);
67
+
68
+ const pageMetadataByPath = new Map(state.pageMetadataByPath);
69
+ pageMetadataByPath.set(key, {
70
+ nextPageToken: opts.nextPageToken ?? null,
71
+ });
72
+ return {
73
+ ...state,
74
+ entriesByPath,
75
+ pageMetadataByPath,
76
+ };
57
77
  },
58
78
 
59
79
  clearNamespaceCache: (state, namespace: string) => {
60
80
  const entriesByPath = new Map(state.entriesByPath);
81
+ const pageMetadataByPath = new Map(state.pageMetadataByPath);
61
82
  const prefix = storageNamespacePrefix(namespace);
62
83
  for (const key of entriesByPath.keys()) {
63
84
  if (key.startsWith(prefix)) {
64
85
  entriesByPath.delete(key);
65
86
  }
66
87
  }
67
- return { ...state, entriesByPath };
88
+ for (const key of pageMetadataByPath.keys()) {
89
+ if (key.startsWith(prefix)) {
90
+ pageMetadataByPath.delete(key);
91
+ }
92
+ }
93
+ return {
94
+ ...state,
95
+ entriesByPath,
96
+ pageMetadataByPath,
97
+ };
68
98
  },
69
99
 
70
100
  filterFromVariables: (state, variableNames: VariableName[]) => {
@@ -93,38 +123,119 @@ export function useStorageActions() {
93
123
 
94
124
  export { storageAtom };
95
125
 
126
+ async function fetchStorageEntriesPage({
127
+ namespace,
128
+ prefix,
129
+ pageToken,
130
+ append,
131
+ setEntries,
132
+ }: {
133
+ namespace: string;
134
+ prefix: string | null | undefined;
135
+ pageToken?: string | null;
136
+ append?: boolean;
137
+ setEntries: ReturnType<typeof useStorageActions>["setEntries"];
138
+ }): Promise<StorageEntriesResult> {
139
+ const result = await ListStorageEntries.request({
140
+ namespace,
141
+ prefix: prefix ?? ROOT_PATH,
142
+ limit: DEFAULT_FETCH_LIMIT,
143
+ ...(pageToken != null ? { pageToken } : {}),
144
+ });
145
+ if (result.error) {
146
+ throw new Error(result.error);
147
+ }
148
+ setEntries({
149
+ namespace,
150
+ prefix,
151
+ entries: result.entries,
152
+ nextPageToken: result.next_page_token,
153
+ append,
154
+ });
155
+ return result;
156
+ }
157
+
96
158
  /**
97
159
  * Hook that fetches and caches storage entries for a given namespace/prefix.
98
160
  * Entries are fetched on first access and cached in the store for subsequent renders.
99
161
  */
100
162
  export function useStorageEntries(namespace: string, prefix?: string) {
101
- const { entriesByPath } = useStorage();
163
+ const { entriesByPath, pageMetadataByPath } = useStorage();
102
164
  const { setEntries } = useStorageActions();
103
- const cached = entriesByPath.get(storagePathKey(namespace, prefix));
165
+ const key = storagePathKey(namespace, prefix);
166
+ const cached = entriesByPath.get(key);
167
+ const metadata = pageMetadataByPath.get(key);
168
+ const nextPageToken = metadata?.nextPageToken ?? null;
169
+ const isLoadingMoreRef = useRef(false);
170
+ const [isLoadingMore, setIsLoadingMore] = useState(false);
171
+ const [loadMoreError, setLoadMoreError] = useState<Error | undefined>();
104
172
 
105
173
  const { isPending, error, refetch } = useAsyncData(async () => {
106
174
  if (cached) {
107
175
  return;
108
176
  }
109
- const result = await ListStorageEntries.request({
177
+ await fetchStorageEntriesPage({
110
178
  namespace,
111
- prefix: prefix ?? ROOT_PATH,
112
- limit: DEFAULT_FETCH_LIMIT,
179
+ prefix,
180
+ setEntries,
113
181
  });
114
- if (result.error) {
115
- throw new Error(result.error);
116
- }
117
- setEntries({ namespace, prefix, entries: result.entries });
118
182
  }, [namespace, prefix, cached === undefined]);
119
183
 
184
+ const loadMore = useCallback(async () => {
185
+ if (nextPageToken == null || isLoadingMoreRef.current) {
186
+ return;
187
+ }
188
+
189
+ isLoadingMoreRef.current = true;
190
+ setIsLoadingMore(true);
191
+ setLoadMoreError(undefined);
192
+ try {
193
+ await fetchStorageEntriesPage({
194
+ namespace,
195
+ prefix,
196
+ pageToken: nextPageToken,
197
+ append: true,
198
+ setEntries,
199
+ });
200
+ } catch (error) {
201
+ setLoadMoreError(
202
+ error instanceof Error ? error : new Error(String(error)),
203
+ );
204
+ } finally {
205
+ isLoadingMoreRef.current = false;
206
+ setIsLoadingMore(false);
207
+ }
208
+ }, [namespace, prefix, nextPageToken, setEntries]);
209
+
120
210
  return {
121
211
  entries: cached ?? [],
122
212
  isPending: isPending && !cached,
123
213
  error: cached ? undefined : error,
214
+ hasMore: nextPageToken !== null,
215
+ loadMore,
216
+ isLoadingMore,
217
+ loadMoreError,
124
218
  refetch,
125
219
  };
126
220
  }
127
221
 
222
+ export function useStoragePageFetcher() {
223
+ const { setEntries } = useStorageActions();
224
+ return useCallback(
225
+ (opts: {
226
+ namespace: string;
227
+ prefix: string | null | undefined;
228
+ pageToken?: string | null;
229
+ append?: boolean;
230
+ }) =>
231
+ fetchStorageEntriesPage({
232
+ ...opts,
233
+ setEntries,
234
+ }),
235
+ [setEntries],
236
+ );
237
+ }
238
+
128
239
  export const exportedForTesting = {
129
240
  reducer,
130
241
  createActions,
@@ -30,6 +30,12 @@ export interface StorageState {
30
30
  namespaces: StorageNamespace[];
31
31
  /** Lazy-loaded entries keyed by "namespace::prefix" */
32
32
  entriesByPath: ReadonlyMap<StoragePathKey, StorageEntry[]>;
33
+ /** Pagination metadata keyed by "namespace::prefix" */
34
+ pageMetadataByPath: ReadonlyMap<StoragePathKey, StoragePageMetadata>;
35
+ }
36
+
37
+ export interface StoragePageMetadata {
38
+ nextPageToken: string | null;
33
39
  }
34
40
 
35
41
  export function storageUrl(
@@ -55,6 +55,10 @@ export class DefaultWasmController implements WasmController {
55
55
  // Load pyodide and packages
56
56
  const span = t.startSpan("loadPyodide");
57
57
  try {
58
+ // Without this, this fails in Firefox with
59
+ // `Could not extract indexURL path from pyodide module`
60
+ // This fixes for Firefox and does not break Chrome/others
61
+ const indexURL = `https://cdn.jsdelivr.net/pyodide/${opts.pyodideVersion}/full/`;
58
62
  const pyodide = await loadPyodide({
59
63
  // Perf: These get loaded while pyodide is being bootstrapped
60
64
  packages: [
@@ -68,10 +72,14 @@ export class DefaultWasmController implements WasmController {
68
72
  ],
69
73
  _makeSnapshot: MAKE_SNAPSHOT,
70
74
  lockFileURL: `https://wasm.marimo.app/pyodide-lock.json?v=${opts.version}&pyodide=${opts.pyodideVersion}`,
71
- // Without this, this fails in Firefox with
72
- // `Could not extract indexURL path from pyodide module`
73
- // This fixes for Firefox and does not break Chrome/others
74
- indexURL: `https://cdn.jsdelivr.net/pyodide/${opts.pyodideVersion}/full/`,
75
+ indexURL,
76
+ // Since Pyodide 0.28.0, when lockFileURL is set, the package base URL
77
+ // defaults to the lockfile's URL (wasm.marimo.app) instead of indexURL.
78
+ // Unlike Node, browsers get no CDN fallback on a failed fetch, so we
79
+ // should pin packageBaseUrl back to the jsDelivr CDN to restore
80
+ // the resolution akin to pre-0.28.
81
+ packageBaseUrl: indexURL,
82
+ convertNullToNone: true,
75
83
  });
76
84
  this.pyodide = pyodide;
77
85
  span.end("ok");
@@ -3,11 +3,20 @@
3
3
  import ReactDOM from "react-dom/client";
4
4
  import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
5
5
  import { z } from "zod";
6
+ import { FUNCTIONS_REGISTRY } from "@/core/functions/FunctionRegistry";
7
+ import type { FunctionCallResultMessage } from "@/core/kernel/messages";
8
+ import { FunctionNotFoundError } from "@/utils/errors";
6
9
  import {
7
10
  isCustomMarimoElement,
8
11
  registerReactComponent,
9
12
  } from "../registerReactComponent";
10
13
 
14
+ vi.mock("@/core/functions/FunctionRegistry", () => ({
15
+ FUNCTIONS_REGISTRY: { request: vi.fn() },
16
+ }));
17
+
18
+ const requestMock = vi.mocked(FUNCTIONS_REGISTRY.request);
19
+
11
20
  // Each custom element name can only be registered once per jsdom window,
12
21
  // so we use a counter to generate unique tag names across tests.
13
22
  let tagCounter = 0;
@@ -202,3 +211,90 @@ describe("connectedCallback - light DOM nesting detection", () => {
202
211
  outer.remove();
203
212
  });
204
213
  });
214
+
215
+ describe("plugin function: not-found recovery", () => {
216
+ const NOT_FOUND: FunctionCallResultMessage = {
217
+ function_call_id:
218
+ "call-id" as FunctionCallResultMessage["function_call_id"],
219
+ status: { code: "error", message: "Function not found" },
220
+ found: false,
221
+ return_value: null,
222
+ };
223
+ const OK: FunctionCallResultMessage = {
224
+ function_call_id:
225
+ "call-id" as FunctionCallResultMessage["function_call_id"],
226
+ status: { code: "ok" },
227
+ found: true,
228
+ return_value: { ok: true },
229
+ };
230
+
231
+ // Mount a plugin exposing a single callable function and resolve the
232
+ // function map that PluginSlot hands to render(), so tests can invoke the
233
+ // request path directly.
234
+ async function mountWithFunction(): Promise<
235
+ (args: Record<string, unknown>) => Promise<unknown>
236
+ > {
237
+ const tag = uniqueTag("fn");
238
+ let captured:
239
+ | ((args: Record<string, unknown>) => Promise<unknown>)
240
+ | undefined;
241
+ registerReactComponent({
242
+ tagName: tag,
243
+ validator: z.any(),
244
+ functions: { run: { input: z.any(), output: z.any() } },
245
+ render: ({ functions }) => {
246
+ captured = (functions as Record<string, typeof captured>).run;
247
+ return null as never;
248
+ },
249
+ });
250
+
251
+ const wrapper = document.createElement("marimo-ui-element");
252
+ wrapper.setAttribute("object-id", "test-object-id");
253
+ const el = document.createElement(tag);
254
+ wrapper.append(el);
255
+ document.body.append(wrapper);
256
+
257
+ await vi.waitFor(() => expect(captured).toBeDefined());
258
+ return captured as (args: Record<string, unknown>) => Promise<unknown>;
259
+ }
260
+
261
+ beforeEach(() => {
262
+ requestMock.mockReset();
263
+ });
264
+
265
+ afterEach(() => {
266
+ document.body.innerHTML = "";
267
+ });
268
+
269
+ test("retries on found:false and resolves once the function appears", async () => {
270
+ const run = await mountWithFunction();
271
+ requestMock.mockResolvedValueOnce(NOT_FOUND).mockResolvedValueOnce(OK);
272
+
273
+ await expect(run({})).resolves.toEqual({ ok: true });
274
+ expect(requestMock).toHaveBeenCalledTimes(2);
275
+ });
276
+
277
+ test("throws FunctionNotFoundError after retries are exhausted", async () => {
278
+ const run = await mountWithFunction();
279
+ requestMock.mockResolvedValue(NOT_FOUND);
280
+
281
+ await expect(run({})).rejects.toBeInstanceOf(FunctionNotFoundError);
282
+ // Initial attempt plus three retries.
283
+ expect(requestMock).toHaveBeenCalledTimes(4);
284
+ });
285
+
286
+ test("does not retry once the function is found (found:true)", async () => {
287
+ const run = await mountWithFunction();
288
+ requestMock.mockResolvedValue({
289
+ function_call_id:
290
+ "call-id" as FunctionCallResultMessage["function_call_id"],
291
+ status: { code: "error", message: "boom" },
292
+ found: true,
293
+ return_value: null,
294
+ });
295
+
296
+ const promise = run({});
297
+ await expect(promise).rejects.toThrow("boom");
298
+ expect(requestMock).toHaveBeenCalledTimes(1);
299
+ });
300
+ });
@@ -40,7 +40,10 @@ import {
40
40
  } from "@/hooks/useEventListener";
41
41
  import { StyleNamespace } from "@/theme/namespace";
42
42
  import { useTheme } from "@/theme/useTheme";
43
- import { CellNotInitializedError } from "@/utils/errors.ts";
43
+ import {
44
+ CellNotInitializedError,
45
+ FunctionNotFoundError,
46
+ } from "@/utils/errors.ts";
44
47
  import { Functions } from "@/utils/functions";
45
48
  import { shallowCompare } from "@/utils/shallow-compare";
46
49
  import { defineCustomElement } from "../../core/dom/defineCustomElement";
@@ -80,6 +83,12 @@ export interface IMarimoHTMLElement extends HTMLElement {
80
83
  rerender: () => void;
81
84
  }
82
85
 
86
+ // Bounded exponential backoff for re-issuing a request whose function the
87
+ // kernel reported as not found. Short enough to fail fast on a genuinely
88
+ // missing function, long enough to outlast a transient object-id desync.
89
+ const FUNCTION_NOT_FOUND_MAX_RETRIES = 3;
90
+ const FUNCTION_NOT_FOUND_BASE_DELAY_MS = 150;
91
+
83
92
  interface PluginSlotProps<T> {
84
93
  hostElement: HTMLElement;
85
94
  plugin: IPlugin<T, unknown>;
@@ -188,8 +197,6 @@ function PluginSlotInternal<T>(
188
197
  args.length <= 1,
189
198
  `Plugin functions only supports a single argument. Called ${key}`,
190
199
  );
191
- const objectId = getUIElementObjectId(hostElement);
192
- invariant(objectId, "Object ID should exist");
193
200
 
194
201
  const isStatic = isStaticNotebook();
195
202
 
@@ -218,16 +225,41 @@ function PluginSlotInternal<T>(
218
225
  Logger.warn(`Cell ID ${cellId} cannot be found`);
219
226
  }
220
227
 
221
- const response = await FUNCTIONS_REGISTRY.request({
222
- args: prettyParse(input, args[0]),
223
- functionName: key,
224
- namespace: objectId,
225
- });
226
- if (response.status.code !== "ok") {
228
+ // A "function not found" response means the kernel never ran the
229
+ // function, so re-issuing the request is side-effect-safe regardless
230
+ // of whether the function is idempotent. This recovers from a
231
+ // transient window where the frontend's object-id leads the kernel's
232
+ // registry. The object-id is re-read each attempt so a corrected id
233
+ // from a re-render is picked up. Once the function is found
234
+ // (found === true) the request is never retried, since the failure
235
+ // is unrelated to lookup and retrying would not help.
236
+ const parsedArgs = prettyParse(input, args[0]);
237
+ for (let attempt = 0; ; attempt++) {
238
+ const namespace = getUIElementObjectId(hostElement);
239
+ invariant(namespace, "Object ID should exist");
240
+
241
+ const response = await FUNCTIONS_REGISTRY.request({
242
+ args: parsedArgs,
243
+ functionName: key,
244
+ namespace,
245
+ });
246
+ if (response.status.code === "ok") {
247
+ return prettyParse(output, response.return_value);
248
+ }
249
+
250
+ const recoverable = response.found === false;
251
+ if (recoverable && attempt < FUNCTION_NOT_FOUND_MAX_RETRIES) {
252
+ const delay = FUNCTION_NOT_FOUND_BASE_DELAY_MS * 2 ** attempt;
253
+ await new Promise((resolve) => setTimeout(resolve, delay));
254
+ continue;
255
+ }
256
+
227
257
  Logger.error(response.status);
258
+ if (recoverable) {
259
+ throw new FunctionNotFoundError();
260
+ }
228
261
  throw new Error(response.status.message || "Unknown error");
229
262
  }
230
- return prettyParse(output, response.return_value);
231
263
  };
232
264
  }
233
265