@marimo-team/islands 0.23.10-dev22 → 0.23.10-dev23

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.23.10-dev22",
3
+ "version": "0.23.10-dev23",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -34,6 +34,26 @@ import { ErrorBoundary } from "../../boundary/ErrorBoundary";
34
34
  import { raf2 } from "../../navigation/focus-utils";
35
35
  import { ContextAwarePanel } from "../panels/context-aware-panel/context-aware-panel";
36
36
  import { PanelSectionProvider } from "../panels/panel-context";
37
+ import { useTheme } from "@/theme/useTheme";
38
+ import {
39
+ LazyAgentPanel,
40
+ LazyCachePanel,
41
+ LazyChatPanel,
42
+ LazyDependencyGraphPanel,
43
+ LazyDocumentationPanel,
44
+ LazyErrorsPanel,
45
+ LazyFileExplorerPanel,
46
+ LazyLogsPanel,
47
+ LazyOutlinePanel,
48
+ LazyPackagesPanel,
49
+ LazyScratchpadPanel,
50
+ LazySecretsPanel,
51
+ LazySessionPanel,
52
+ LazySnippetsPanel,
53
+ LazyTerminal,
54
+ LazyTracingPanel,
55
+ PANEL_PRELOADERS,
56
+ } from "./lazy-panels";
37
57
  import { panelLayoutAtom, useChromeActions, useChromeState } from "../state";
38
58
  import {
39
59
  isPanelHidden,
@@ -50,33 +70,26 @@ import { useAiPanelTab } from "./useAiPanel";
50
70
  import { useDependencyPanelTab } from "./useDependencyPanelTab";
51
71
  import { handleDragging } from "./utils";
52
72
 
53
- const LazyTerminal = React.lazy(() => import("@/components/terminal/terminal"));
54
- const LazyChatPanel = React.lazy(() => import("@/components/chat/chat-panel"));
55
- const LazyAgentPanel = React.lazy(
56
- () => import("@/components/chat/acp/agent-panel"),
57
- );
58
- const LazyDependencyGraphPanel = React.lazy(
59
- () => import("@/components/editor/chrome/panels/dependency-graph-panel"),
60
- );
61
- const LazySessionPanel = React.lazy(() => import("../panels/session-panel"));
62
- const LazyDocumentationPanel = React.lazy(
63
- () => import("../panels/documentation-panel"),
64
- );
65
- const LazyErrorsPanel = React.lazy(() => import("../panels/error-panel"));
66
- const LazyFileExplorerPanel = React.lazy(
67
- () => import("../panels/file-explorer-panel"),
68
- );
69
- const LazyLogsPanel = React.lazy(() => import("../panels/logs-panel"));
70
- const LazyOutlinePanel = React.lazy(() => import("../panels/outline-panel"));
71
- const LazyPackagesPanel = React.lazy(() => import("../panels/packages-panel"));
72
- const LazyScratchpadPanel = React.lazy(
73
- () => import("../panels/scratchpad-panel"),
74
- );
75
- const LazySecretsPanel = React.lazy(() => import("../panels/secrets-panel"));
76
- const LazySnippetsPanel = React.lazy(() => import("../panels/snippets-panel"));
77
- const LazyTracingPanel = React.lazy(() => import("../panels/tracing-panel"));
78
- const LazyCachePanel = React.lazy(() => import("../panels/cache-panel"));
79
-
73
+ // Placeholder that matches the eventual xterm theme background so the
74
+ // transition into the loaded terminal is seamless rather than a blank flash.
75
+ const TerminalSkeleton: React.FC = () => {
76
+ const { theme } = useTheme();
77
+ const isDark = theme === "dark";
78
+ return (
79
+ <div
80
+ aria-label="Loading terminal"
81
+ role="status"
82
+ className="w-full h-full flex items-start p-3 font-mono text-xs select-none"
83
+ style={{
84
+ background: isDark ? "#0f172a" : "#ffffff",
85
+ color: isDark ? "#94a3b8" : "#64748b",
86
+ }}
87
+ >
88
+ <span className="opacity-70">Starting terminal</span>
89
+ <span className="ml-1 inline-block w-2 h-3.5 align-middle bg-current animate-pulse" />
90
+ </div>
91
+ );
92
+ };
80
93
  export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
81
94
  const {
82
95
  isSidebarOpen,
@@ -96,6 +109,33 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
96
109
  const capabilities = useAtomValue(capabilitiesAtom);
97
110
  const aiEnabled = useAtomValue(aiEnabledAtom);
98
111
 
112
+ // On mount, idle-preload whichever panels the user had open at last unload,
113
+ // so the first interaction with the sidebar/dev panel doesn't hit a cold
114
+ // chunk fetch. Runs once.
115
+ // oxlint-disable-next-line react-hooks/exhaustive-deps
116
+ useEffect(() => {
117
+ const preloadOpenPanels = () => {
118
+ if (isSidebarOpen && selectedPanel) {
119
+ PANEL_PRELOADERS[selectedPanel]?.();
120
+ }
121
+ if (isDeveloperPanelOpen && selectedDeveloperPanelTab) {
122
+ PANEL_PRELOADERS[selectedDeveloperPanelTab]?.();
123
+ }
124
+ };
125
+
126
+ const canIdle =
127
+ typeof window !== "undefined" &&
128
+ typeof window.requestIdleCallback === "function";
129
+ if (canIdle) {
130
+ const handle = window.requestIdleCallback(preloadOpenPanels, {
131
+ timeout: 2000,
132
+ });
133
+ return () => window.cancelIdleCallback(handle);
134
+ }
135
+ const handle = setTimeout(preloadOpenPanels, 300);
136
+ return () => clearTimeout(handle);
137
+ }, []);
138
+
99
139
  // Convert current developer panel items to PanelDescriptors
100
140
  // Filter out hidden panels (e.g., terminal when capability is not available)
101
141
  const devPanelItems = useMemo(() => {
@@ -256,32 +296,34 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
256
296
 
257
297
  const renderAiPanel = () => {
258
298
  if (agentsEnabled && aiPanelTab === "agents") {
259
- return <LazyAgentPanel />;
299
+ return <LazyAgentPanel.Component />;
260
300
  }
261
- return <LazyChatPanel />;
301
+ return <LazyChatPanel.Component />;
262
302
  };
263
303
 
264
304
  const SIDEBAR_PANELS: Record<PanelType, React.ReactNode> = {
265
- files: <LazyFileExplorerPanel />,
266
- variables: <LazySessionPanel />,
267
- dependencies: <LazyDependencyGraphPanel />,
268
- packages: <LazyPackagesPanel />,
269
- outline: <LazyOutlinePanel />,
270
- documentation: <LazyDocumentationPanel />,
271
- snippets: <LazySnippetsPanel />,
305
+ files: <LazyFileExplorerPanel.Component />,
306
+ variables: <LazySessionPanel.Component />,
307
+ dependencies: <LazyDependencyGraphPanel.Component />,
308
+ packages: <LazyPackagesPanel.Component />,
309
+ outline: <LazyOutlinePanel.Component />,
310
+ documentation: <LazyDocumentationPanel.Component />,
311
+ snippets: <LazySnippetsPanel.Component />,
272
312
  ai: renderAiPanel(),
273
- errors: <LazyErrorsPanel />,
274
- scratchpad: <LazyScratchpadPanel />,
275
- tracing: <LazyTracingPanel />,
276
- secrets: <LazySecretsPanel />,
277
- logs: <LazyLogsPanel />,
313
+ errors: <LazyErrorsPanel.Component />,
314
+ scratchpad: <LazyScratchpadPanel.Component />,
315
+ tracing: <LazyTracingPanel.Component />,
316
+ secrets: <LazySecretsPanel.Component />,
317
+ logs: <LazyLogsPanel.Component />,
278
318
  terminal: (
279
- <LazyTerminal
280
- visible={isSidebarOpen && selectedPanel === "terminal"}
281
- onClose={() => setIsSidebarOpen(false)}
282
- />
319
+ <Suspense fallback={<TerminalSkeleton />}>
320
+ <LazyTerminal.Component
321
+ visible={isSidebarOpen && selectedPanel === "terminal"}
322
+ onClose={() => setIsSidebarOpen(false)}
323
+ />
324
+ </Suspense>
283
325
  ),
284
- cache: <LazyCachePanel />,
326
+ cache: <LazyCachePanel.Component />,
285
327
  };
286
328
 
287
329
  const helpPaneBody = (
@@ -414,12 +456,14 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
414
456
  const DEVELOPER_PANELS: Record<PanelType, React.ReactNode> = {
415
457
  ...SIDEBAR_PANELS,
416
458
  terminal: (
417
- <LazyTerminal
418
- visible={
419
- isDeveloperPanelOpen && selectedDeveloperPanelTab === "terminal"
420
- }
421
- onClose={() => setIsDeveloperPanelOpen(false)}
422
- />
459
+ <Suspense fallback={<TerminalSkeleton />}>
460
+ <LazyTerminal.Component
461
+ visible={
462
+ isDeveloperPanelOpen && selectedDeveloperPanelTab === "terminal"
463
+ }
464
+ onClose={() => setIsDeveloperPanelOpen(false)}
465
+ />
466
+ </Suspense>
423
467
  ),
424
468
  };
425
469
 
@@ -474,6 +518,7 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
474
518
  className="flex flex-row gap-1"
475
519
  minItems={0}
476
520
  onAction={(panel) => openApplication(panel.type)}
521
+ onItemPreloadHint={(panel) => PANEL_PRELOADERS[panel.type]?.()}
477
522
  renderItem={(panel) => (
478
523
  <div
479
524
  className={cn(
@@ -0,0 +1,91 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { reactLazyWithPreload } from "@/utils/lazy";
4
+ import { Logger } from "@/utils/Logger";
5
+ import type { PanelType } from "../types";
6
+
7
+ // Preloading is best-effort: a chunk-load failure here should not surface as
8
+ // an unhandled rejection (the panel will retry the import when actually
9
+ // rendered, where Suspense/ErrorBoundary handle the failure).
10
+ const safePreload = (lazy: { preload: () => Promise<unknown> }) => (): void => {
11
+ void lazy.preload().catch((error) => {
12
+ Logger.debug("Failed to preload panel chunk", error);
13
+ });
14
+ };
15
+
16
+ // Centralized lazy panels. Using reactLazyWithPreload (instead of React.lazy)
17
+ // gives each panel a .preload() method so the chunk can be fetched on intent
18
+ // (hovering the sidebar icon or developer-panel tab) before the user clicks.
19
+
20
+ export const LazyTerminal = reactLazyWithPreload(
21
+ () => import("@/components/terminal/terminal"),
22
+ );
23
+ export const LazyChatPanel = reactLazyWithPreload(
24
+ () => import("@/components/chat/chat-panel"),
25
+ );
26
+ export const LazyAgentPanel = reactLazyWithPreload(
27
+ () => import("@/components/chat/acp/agent-panel"),
28
+ );
29
+ export const LazyDependencyGraphPanel = reactLazyWithPreload(
30
+ () => import("../panels/dependency-graph-panel"),
31
+ );
32
+ export const LazySessionPanel = reactLazyWithPreload(
33
+ () => import("../panels/session-panel"),
34
+ );
35
+ export const LazyDocumentationPanel = reactLazyWithPreload(
36
+ () => import("../panels/documentation-panel"),
37
+ );
38
+ export const LazyErrorsPanel = reactLazyWithPreload(
39
+ () => import("../panels/error-panel"),
40
+ );
41
+ export const LazyFileExplorerPanel = reactLazyWithPreload(
42
+ () => import("../panels/file-explorer-panel"),
43
+ );
44
+ export const LazyLogsPanel = reactLazyWithPreload(
45
+ () => import("../panels/logs-panel"),
46
+ );
47
+ export const LazyOutlinePanel = reactLazyWithPreload(
48
+ () => import("../panels/outline-panel"),
49
+ );
50
+ export const LazyPackagesPanel = reactLazyWithPreload(
51
+ () => import("../panels/packages-panel"),
52
+ );
53
+ export const LazyScratchpadPanel = reactLazyWithPreload(
54
+ () => import("../panels/scratchpad-panel"),
55
+ );
56
+ export const LazySecretsPanel = reactLazyWithPreload(
57
+ () => import("../panels/secrets-panel"),
58
+ );
59
+ export const LazySnippetsPanel = reactLazyWithPreload(
60
+ () => import("../panels/snippets-panel"),
61
+ );
62
+ export const LazyTracingPanel = reactLazyWithPreload(
63
+ () => import("../panels/tracing-panel"),
64
+ );
65
+ export const LazyCachePanel = reactLazyWithPreload(
66
+ () => import("../panels/cache-panel"),
67
+ );
68
+
69
+ // Preloader registry: hovering an icon/tab calls into this map to warm the
70
+ // corresponding chunk. Two panel types (chat and agents) share the "ai" slot,
71
+ // so we preload both.
72
+ export const PANEL_PRELOADERS: Record<PanelType, () => void> = {
73
+ files: safePreload(LazyFileExplorerPanel),
74
+ variables: safePreload(LazySessionPanel),
75
+ dependencies: safePreload(LazyDependencyGraphPanel),
76
+ packages: safePreload(LazyPackagesPanel),
77
+ outline: safePreload(LazyOutlinePanel),
78
+ documentation: safePreload(LazyDocumentationPanel),
79
+ snippets: safePreload(LazySnippetsPanel),
80
+ ai: () => {
81
+ safePreload(LazyChatPanel)();
82
+ safePreload(LazyAgentPanel)();
83
+ },
84
+ errors: safePreload(LazyErrorsPanel),
85
+ scratchpad: safePreload(LazyScratchpadPanel),
86
+ tracing: safePreload(LazyTracingPanel),
87
+ secrets: safePreload(LazySecretsPanel),
88
+ logs: safePreload(LazyLogsPanel),
89
+ terminal: safePreload(LazyTerminal),
90
+ cache: safePreload(LazyCachePanel),
91
+ };
@@ -22,6 +22,7 @@ import {
22
22
  PANELS,
23
23
  type PanelDescriptor,
24
24
  } from "../types";
25
+ import { PANEL_PRELOADERS } from "./lazy-panels";
25
26
 
26
27
  export const Sidebar: React.FC = () => {
27
28
  const { selectedPanel, selectedDeveloperPanelTab, isSidebarOpen } =
@@ -141,6 +142,7 @@ export const Sidebar: React.FC = () => {
141
142
  className="flex flex-col gap-0"
142
143
  minItems={0}
143
144
  onAction={(panel) => toggleApplication(panel.type)}
145
+ onItemPreloadHint={(panel) => PANEL_PRELOADERS[panel.type]?.()}
144
146
  renderItem={(panel) => (
145
147
  <SidebarItem
146
148
  tooltip={panel.tooltip}
@@ -57,6 +57,12 @@ export interface ReorderableListProps<T> {
57
57
  * Callback when an item is clicked
58
58
  */
59
59
  onAction?: (item: T) => void;
60
+ /**
61
+ * Fired when an item is hovered or focused. Useful for preloading the
62
+ * resource the item points to before it is activated. Attached to the
63
+ * focusable list item so it works for both pointer and keyboard users.
64
+ */
65
+ onItemPreloadHint?: (item: T) => void;
60
66
  /**
61
67
  * All available items that can be added to the list
62
68
  */
@@ -142,6 +148,7 @@ export const ReorderableList = <T extends object>({
142
148
  ariaLabel = "Reorderable list",
143
149
  className,
144
150
  crossListDrag,
151
+ onItemPreloadHint,
145
152
  }: ReorderableListProps<T>) => {
146
153
  const mimeType = crossListDrag
147
154
  ? getDragMimeType(crossListDrag.dragType)
@@ -294,6 +301,12 @@ export const ReorderableList = <T extends object>({
294
301
  key={getKey(item)}
295
302
  id={getKey(item)}
296
303
  className="active:cursor-grabbing data-[dragging]:opacity-60 outline-none"
304
+ onHoverStart={
305
+ onItemPreloadHint ? () => onItemPreloadHint(item) : undefined
306
+ }
307
+ onFocus={
308
+ onItemPreloadHint ? () => onItemPreloadHint(item) : undefined
309
+ }
297
310
  >
298
311
  {renderItem(item)}
299
312
  </ListBoxItem>
package/src/utils/lazy.ts CHANGED
@@ -3,7 +3,12 @@
3
3
  import React from "react";
4
4
 
5
5
  interface LazyComponentWithPreload<T> {
6
- preload: () => void;
6
+ /**
7
+ * Eagerly trigger the dynamic import. Returns the import promise so callers
8
+ * can await it or attach error handling; safe to call multiple times (the
9
+ * import is memoized).
10
+ */
11
+ preload: () => Promise<{ default: React.ComponentType<T> }>;
7
12
  Component: React.LazyExoticComponent<React.ComponentType<T>>;
8
13
  }
9
14