Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

perf: lazy-load command pallete and sidebar panels (#6232)

Myles Scolnickf32b85c5031d
diff --git a/frontend/src/components/chat/chat-panel.tsx b/frontend/src/components/chat/chat-panel.tsx
index 7134f1552d..0e54db8098 100644
--- a/frontend/src/components/chat/chat-panel.tsx
+++ b/frontend/src/components/chat/chat-panel.tsx
@@ -442,7 +442,7 @@ const ChatInput: React.FC<ChatInputProps> = memo(
ChatInput.displayName = "ChatInput";
-export const ChatPanel = () => {
+const ChatPanel = () => {
const aiEnabled = useAtomValue(aiEnabledAtom);
const { handleClick } = useOpenSettingsToTab();
@@ -935,3 +935,5 @@ async function convertToChatAttachments(
return attachments;
}
+
+export default ChatPanel;
diff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsx
index 17cfccfe68..585f2b2497 100644
--- a/frontend/src/components/editor/actions/useNotebookActions.tsx
+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx
@@ -73,8 +73,8 @@ import { newNotebookURL } from "@/utils/urls";
import { useRunAllCells } from "../cell/useRunCells";
import { useChromeActions, useChromeState } from "../chrome/state";
import { PANELS } from "../chrome/types";
-import { commandPaletteAtom } from "../controls/command-palette";
import { keyboardShortcutsAtom } from "../controls/keyboard-shortcuts";
+import { commandPaletteAtom } from "../controls/state";
import { AddDatabaseDialogContent } from "../database/add-database-form";
import { displayLayoutName, getLayoutIcon } from "../renderers/layout-select";
import { LAYOUT_TYPES } from "../renderers/types";
diff --git a/frontend/src/components/editor/chrome/panels/datasources-panel.tsx b/frontend/src/components/editor/chrome/panels/datasources-panel.tsx
index 528be40aef..f370ab13be 100644
--- a/frontend/src/components/editor/chrome/panels/datasources-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/datasources-panel.tsx
@@ -1,6 +1,8 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { DataSources } from "@/components/datasources/datasources";
-export const DataSourcesPanel: React.FC = () => {
+const DataSourcesPanel: React.FC = () => {
return <DataSources />;
};
+
+export default DataSourcesPanel;
diff --git a/frontend/src/components/editor/chrome/panels/dependency-graph-panel.tsx b/frontend/src/components/editor/chrome/panels/dependency-graph-panel.tsx
index 8d05b057a0..6849ef5050 100644
--- a/frontend/src/components/editor/chrome/panels/dependency-graph-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/dependency-graph-panel.tsx
@@ -6,7 +6,7 @@ import { useVariables } from "@/core/variables/state";
import { cn } from "@/utils/cn";
import { DependencyGraph } from "../../../dependency-graph/dependency-graph";
-export const DependencyGraphPanel: React.FC = () => {
+const DependencyGraphPanel: React.FC = () => {
const variables = useVariables();
const cellIds = useCellIds();
const [cells] = useCellDataAtoms();
@@ -21,3 +21,5 @@ export const DependencyGraphPanel: React.FC = () => {
</div>
);
};
+
+export default DependencyGraphPanel;
diff --git a/frontend/src/components/editor/chrome/panels/documentation-panel.tsx b/frontend/src/components/editor/chrome/panels/documentation-panel.tsx
index 3a0e3f6ec7..65d2024912 100644
--- a/frontend/src/components/editor/chrome/panels/documentation-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/documentation-panel.tsx
@@ -8,7 +8,7 @@ import "../../documentation.css";
import { TextSearchIcon } from "lucide-react";
import { PanelEmptyState } from "./empty-state";
-export const DocumentationPanel: React.FC = () => {
+const DocumentationPanel: React.FC = () => {
const { documentation } = useAtomValue(documentationAtom);
if (!documentation) {
@@ -27,3 +27,5 @@ export const DocumentationPanel: React.FC = () => {
</div>
);
};
+
+export default DocumentationPanel;
diff --git a/frontend/src/components/editor/chrome/panels/error-panel.tsx b/frontend/src/components/editor/chrome/panels/error-panel.tsx
index c85d7a445e..0b946bd7b5 100644
--- a/frontend/src/components/editor/chrome/panels/error-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/error-panel.tsx
@@ -7,7 +7,7 @@ import { useCellErrors } from "../../../../core/cells/cells";
import { MarimoErrorOutput } from "../../output/MarimoErrorOutput";
import { PanelEmptyState } from "./empty-state";
-export const ErrorsPanel: React.FC = () => {
+const ErrorsPanel: React.FC = () => {
const errors = useCellErrors();
if (errors.length === 0) {
@@ -33,3 +33,5 @@ export const ErrorsPanel: React.FC = () => {
</div>
);
};
+
+export default ErrorsPanel;
diff --git a/frontend/src/components/editor/chrome/panels/file-explorer-panel.tsx b/frontend/src/components/editor/chrome/panels/file-explorer-panel.tsx
index e375113ae2..c71acd70dd 100644
--- a/frontend/src/components/editor/chrome/panels/file-explorer-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/file-explorer-panel.tsx
@@ -6,7 +6,7 @@ import { cn } from "@/utils/cn";
import { FileExplorer } from "../../file-tree/file-explorer";
import { useFileExplorerUpload } from "../../file-tree/upload";
-export const FileExplorerPanel: React.FC = () => {
+const FileExplorerPanel: React.FC = () => {
const { ref, height = 1 } = useResizeObserver<HTMLDivElement>();
const { getRootProps, getInputProps, isDragActive } = useFileExplorerUpload({
noClick: true,
@@ -31,3 +31,5 @@ export const FileExplorerPanel: React.FC = () => {
</div>
);
};
+
+export default FileExplorerPanel;
diff --git a/frontend/src/components/editor/chrome/panels/logs-panel.tsx b/frontend/src/components/editor/chrome/panels/logs-panel.tsx
index 47ee419a61..60370513de 100644
--- a/frontend/src/components/editor/chrome/panels/logs-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/logs-panel.tsx
@@ -14,7 +14,7 @@ interface Props {
logs: CellLog[];
}
-export const LogsPanel: React.FC = () => {
+const LogsPanel: React.FC = () => {
const logs = useCellLogs();
const { clearLogs } = useCellActions();
@@ -46,6 +46,8 @@ export const LogsPanel: React.FC = () => {
);
};
+export default LogsPanel;
+
export const LogViewer: React.FC<Props> = ({ logs, className }) => {
const hover = "opacity-70 group-hover:bg-(--gray-3) group-hover:opacity-100";
return (
diff --git a/frontend/src/components/editor/chrome/panels/outline-panel.tsx b/frontend/src/components/editor/chrome/panels/outline-panel.tsx
index 087a8341b7..f21d648783 100644
--- a/frontend/src/components/editor/chrome/panels/outline-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/outline-panel.tsx
@@ -13,7 +13,7 @@ import {
useActiveOutline,
} from "./outline/useActiveOutline";
-export const OutlinePanel: React.FC = () => {
+const OutlinePanel: React.FC = () => {
const { items } = useAtomValue(notebookOutline);
const headerElements = useMemo(() => findOutlineElements(items), [items]);
const { activeHeaderId, activeOccurrences } =
@@ -37,3 +37,5 @@ export const OutlinePanel: React.FC = () => {
/>
);
};
+
+export default OutlinePanel;
diff --git a/frontend/src/components/editor/chrome/panels/packages-panel.tsx b/frontend/src/components/editor/chrome/panels/packages-panel.tsx
index bb8bb2a9d3..ca2d980881 100644
--- a/frontend/src/components/editor/chrome/panels/packages-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/packages-panel.tsx
@@ -65,7 +65,7 @@ const PackageActionButton: React.FC<{
);
};
-export const PackagesPanel: React.FC = () => {
+const PackagesPanel: React.FC = () => {
const [config] = useResolvedMarimoConfig();
const packageManager = config.package_management.manager;
const { getDependencyTree, getPackageList } = useRequestClient();
@@ -162,6 +162,8 @@ export const PackagesPanel: React.FC = () => {
);
};
+export default PackagesPanel;
+
const InstallPackageForm: React.FC<{
packageManager: string;
onSuccess: () => void;
diff --git a/frontend/src/components/editor/chrome/panels/scratchpad-panel.tsx b/frontend/src/components/editor/chrome/panels/scratchpad-panel.tsx
index 179f4745db..4a14364c7f 100644
--- a/frontend/src/components/editor/chrome/panels/scratchpad-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/scratchpad-panel.tsx
@@ -3,6 +3,8 @@
import type React from "react";
import { ScratchPad } from "@/components/scratchpad/scratchpad";
-export const ScratchpadPanel: React.FC = () => {
+const ScratchpadPanel: React.FC = () => {
return <ScratchPad />;
};
+
+export default ScratchpadPanel;
diff --git a/frontend/src/components/editor/chrome/panels/secrets-panel.tsx b/frontend/src/components/editor/chrome/panels/secrets-panel.tsx
index a4b7d27ba6..f5da34d1ef 100644
--- a/frontend/src/components/editor/chrome/panels/secrets-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/secrets-panel.tsx
@@ -22,7 +22,7 @@ import { copyToClipboard } from "@/utils/copy";
import { PanelEmptyState } from "./empty-state";
import { sortProviders, WriteSecretModal } from "./write-secret-modal";
-export const SecretsPanel: React.FC = () => {
+const SecretsPanel: React.FC = () => {
const { openModal, closeModal } = useImperativeModal();
const {
data: secretKeyProviders,
@@ -125,6 +125,8 @@ export const SecretsPanel: React.FC = () => {
);
};
+export default SecretsPanel;
+
const CopyButton: React.FC<{
className?: string;
ariaLabel: string;
diff --git a/frontend/src/components/editor/chrome/panels/snippets-panel.tsx b/frontend/src/components/editor/chrome/panels/snippets-panel.tsx
index 6ce6390574..b302c519b7 100644
--- a/frontend/src/components/editor/chrome/panels/snippets-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/snippets-panel.tsx
@@ -32,7 +32,7 @@ import { ContributeSnippetButton } from "../components/contribute-snippet-button
const extensions = [EditorView.lineWrapping];
-export const SnippetsPanel: React.FC = () => {
+const SnippetsPanel: React.FC = () => {
const { readSnippets } = useRequestClient();
const [selectedSnippet, setSelectedSnippet] = React.useState<Snippet>();
const {
@@ -98,6 +98,8 @@ export const SnippetsPanel: React.FC = () => {
);
};
+export default SnippetsPanel;
+
const SnippetViewer: React.FC<{ snippet: Snippet; onClose: () => void }> = ({
snippet,
onClose,
diff --git a/frontend/src/components/editor/chrome/panels/tracing-panel.tsx b/frontend/src/components/editor/chrome/panels/tracing-panel.tsx
index 8d84135e64..c954ef343b 100644
--- a/frontend/src/components/editor/chrome/panels/tracing-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/tracing-panel.tsx
@@ -11,7 +11,7 @@ const LazyTracing = React.lazy(() =>
}),
);
-export const TracingPanel: React.FC = () => {
+const TracingPanel: React.FC = () => {
return (
<React.Suspense fallback={<Loading />}>
<LazyTracing />
@@ -19,6 +19,8 @@ export const TracingPanel: React.FC = () => {
);
};
+export default TracingPanel;
+
const Loading = () => {
return (
<div className="flex flex-col items-center justify-center h-full">
diff --git a/frontend/src/components/editor/chrome/panels/variable-panel.tsx b/frontend/src/components/editor/chrome/panels/variable-panel.tsx
index d777250258..d3e6da095e 100644
--- a/frontend/src/components/editor/chrome/panels/variable-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/variable-panel.tsx
@@ -7,7 +7,7 @@ import { useCellIds } from "@/core/cells/cells";
import { useVariables } from "@/core/variables/state";
import { PanelEmptyState } from "./empty-state";
-export const VariablePanel: React.FC = () => {
+const VariablePanel: React.FC = () => {
const variables = useVariables();
const cellIds = useCellIds();
@@ -29,3 +29,5 @@ export const VariablePanel: React.FC = () => {
/>
);
};
+
+export default VariablePanel;
diff --git a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
index 63daae844d..fc09126591 100644
--- a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
+++ b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
@@ -11,26 +11,12 @@ import { Sidebar } from "./sidebar";
import "./app-chrome.css";
import { TooltipProvider } from "@radix-ui/react-tooltip";
import { XIcon } from "lucide-react";
-import { ChatPanel } from "@/components/chat/chat-panel";
-import { DependencyGraphPanel } from "@/components/editor/chrome/panels/dependency-graph-panel";
import { Button } from "@/components/ui/button";
import { LazyMount } from "@/components/utils/lazy-mount";
import { IfCapability } from "@/core/config/if-capability";
import { cn } from "@/utils/cn";
import { ErrorBoundary } from "../../boundary/ErrorBoundary";
import { ContextAwarePanel } from "../panels/context-aware-panel/context-aware-panel";
-import { DataSourcesPanel } from "../panels/datasources-panel";
-import { DocumentationPanel } from "../panels/documentation-panel";
-import { ErrorsPanel } from "../panels/error-panel";
-import { FileExplorerPanel } from "../panels/file-explorer-panel";
-import { LogsPanel } from "../panels/logs-panel";
-import { OutlinePanel } from "../panels/outline-panel";
-import { PackagesPanel } from "../panels/packages-panel";
-import { ScratchpadPanel } from "../panels/scratchpad-panel";
-import { SecretsPanel } from "../panels/secrets-panel";
-import { SnippetsPanel } from "../panels/snippets-panel";
-import { TracingPanel } from "../panels/tracing-panel";
-import { VariablePanel } from "../panels/variable-panel";
import { useChromeActions, useChromeState } from "../state";
import { Minimap } from "./minimap";
import { PanelsWrapper } from "./panels";
@@ -38,6 +24,30 @@ import { createStorage } from "./storage";
import { handleDragging } from "./utils";
const LazyTerminal = React.lazy(() => import("@/components/terminal/terminal"));
+const LazyChatPanel = React.lazy(() => import("@/components/chat/chat-panel"));
+const LazyDependencyGraphPanel = React.lazy(
+ () => import("@/components/editor/chrome/panels/dependency-graph-panel"),
+);
+const LazyDataSourcesPanel = React.lazy(
+ () => import("../panels/datasources-panel"),
+);
+const LazyDocumentationPanel = React.lazy(
+ () => import("../panels/documentation-panel"),
+);
+const LazyErrorsPanel = React.lazy(() => import("../panels/error-panel"));
+const LazyFileExplorerPanel = React.lazy(
+ () => import("../panels/file-explorer-panel"),
+);
+const LazyLogsPanel = React.lazy(() => import("../panels/logs-panel"));
+const LazyOutlinePanel = React.lazy(() => import("../panels/outline-panel"));
+const LazyPackagesPanel = React.lazy(() => import("../panels/packages-panel"));
+const LazyScratchpadPanel = React.lazy(
+ () => import("../panels/scratchpad-panel"),
+);
+const LazySecretsPanel = React.lazy(() => import("../panels/secrets-panel"));
+const LazySnippetsPanel = React.lazy(() => import("../panels/snippets-panel"));
+const LazyTracingPanel = React.lazy(() => import("../panels/tracing-panel"));
+const LazyVariablePanel = React.lazy(() => import("../panels/variable-panel"));
export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
const { isSidebarOpen, isTerminalOpen, selectedPanel } = useChromeState();
@@ -140,20 +150,20 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
</div>
<Suspense>
<TooltipProvider>
- {selectedPanel === "files" && <FileExplorerPanel />}
- {selectedPanel === "errors" && <ErrorsPanel />}
- {selectedPanel === "variables" && <VariablePanel />}
- {selectedPanel === "dependencies" && <DependencyGraphPanel />}
- {selectedPanel === "packages" && <PackagesPanel />}
- {selectedPanel === "outline" && <OutlinePanel />}
- {selectedPanel === "datasources" && <DataSourcesPanel />}
- {selectedPanel === "documentation" && <DocumentationPanel />}
- {selectedPanel === "snippets" && <SnippetsPanel />}
- {selectedPanel === "scratchpad" && <ScratchpadPanel />}
- {selectedPanel === "chat" && <ChatPanel />}
- {selectedPanel === "logs" && <LogsPanel />}
- {selectedPanel === "tracing" && <TracingPanel />}
- {selectedPanel === "secrets" && <SecretsPanel />}
+ {selectedPanel === "files" && <LazyFileExplorerPanel />}
+ {selectedPanel === "errors" && <LazyErrorsPanel />}
+ {selectedPanel === "variables" && <LazyVariablePanel />}
+ {selectedPanel === "dependencies" && <LazyDependencyGraphPanel />}
+ {selectedPanel === "packages" && <LazyPackagesPanel />}
+ {selectedPanel === "outline" && <LazyOutlinePanel />}
+ {selectedPanel === "datasources" && <LazyDataSourcesPanel />}
+ {selectedPanel === "documentation" && <LazyDocumentationPanel />}
+ {selectedPanel === "snippets" && <LazySnippetsPanel />}
+ {selectedPanel === "scratchpad" && <LazyScratchpadPanel />}
+ {selectedPanel === "chat" && <LazyChatPanel />}
+ {selectedPanel === "logs" && <LazyLogsPanel />}
+ {selectedPanel === "tracing" && <LazyTracingPanel />}
+ {selectedPanel === "secrets" && <LazySecretsPanel />}
</TooltipProvider>
</Suspense>
</div>
diff --git a/frontend/src/components/editor/controls/command-palette-button.tsx b/frontend/src/components/editor/controls/command-palette-button.tsx
index bd6d3a912d..91b0fd6d39 100644
--- a/frontend/src/components/editor/controls/command-palette-button.tsx
+++ b/frontend/src/components/editor/controls/command-palette-button.tsx
@@ -6,7 +6,7 @@ import React from "react";
import { renderShortcut } from "@/components/shortcuts/renderShortcut";
import { Tooltip } from "@/components/ui/tooltip";
import { Button } from "../inputs/Inputs";
-import { commandPaletteAtom } from "./command-palette";
+import { commandPaletteAtom } from "./state";
export const CommandPaletteButton: React.FC = () => {
const setCommandPaletteOpen = useSetAtom(commandPaletteAtom);
diff --git a/frontend/src/components/editor/controls/command-palette.tsx b/frontend/src/components/editor/controls/command-palette.tsx
index b6c2845f97..c69fe9ea75 100644
--- a/frontend/src/components/editor/controls/command-palette.tsx
+++ b/frontend/src/components/editor/controls/command-palette.tsx
@@ -1,6 +1,6 @@
/* Copyright 2024 Marimo. All rights reserved. */
-import { atom, useAtom, useAtomValue } from "jotai";
+import { useAtom, useAtomValue } from "jotai";
import {
CommandDialog,
CommandEmpty,
@@ -28,10 +28,9 @@ import {
import { useCellActionButtons } from "../actions/useCellActionButton";
import { useConfigActions } from "../actions/useConfigActions";
import { useNotebookActions } from "../actions/useNotebookActions";
+import { commandPaletteAtom } from "./state";
-export const commandPaletteAtom = atom(false);
-
-export const CommandPalette = () => {
+const CommandPalette = () => {
const [open, setOpen] = useAtom(commandPaletteAtom);
const registeredActions = useRegisteredActions();
const lastFocusedCell = useAtomValue(lastFocusedCellAtom);
@@ -208,3 +207,5 @@ export const CommandPalette = () => {
</CommandDialog>
);
};
+
+export default CommandPalette;
diff --git a/frontend/src/components/editor/controls/state.ts b/frontend/src/components/editor/controls/state.ts
new file mode 100644
index 0000000000..36a6c7e29a
--- /dev/null
+++ b/frontend/src/components/editor/controls/state.ts
@@ -0,0 +1,3 @@
+import { atom } from "jotai";
+
+export const commandPaletteAtom = atom(false);
diff --git a/frontend/src/components/pages/edit-page.tsx b/frontend/src/components/pages/edit-page.tsx
index 7922aac898..ef425d0e5f 100644
--- a/frontend/src/components/pages/edit-page.tsx
+++ b/frontend/src/components/pages/edit-page.tsx
@@ -1,10 +1,14 @@
/* Copyright 2024 Marimo. All rights reserved. */
+import { lazy } from "react";
import type { AppConfig, UserConfig } from "@/core/config/config-schema";
import { KnownQueryParams } from "@/core/constants";
import { EditApp } from "@/core/edit-app";
import { AppChrome } from "../editor/chrome/wrapper/app-chrome";
-import { CommandPalette } from "../editor/controls/command-palette";
+
+const LazyCommandPalette = lazy(
+ () => import("../editor/controls/command-palette"),
+);
interface Props {
userConfig: UserConfig;
@@ -21,7 +25,7 @@ const EditPage = (props: Props) => {
return (
<>
<EditApp hideControls={true} {...props} />
- <CommandPalette />
+ <LazyCommandPalette />
</>
);
}
@@ -29,7 +33,7 @@ const EditPage = (props: Props) => {
return (
<AppChrome>
<EditApp {...props} />
- <CommandPalette />
+ <LazyCommandPalette />
</AppChrome>
);
};