🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
perf(frontend): reduce tree related re-renders and reduce initial bundle size (#10544)
Aman Thakur90ff7a992677
diff --git a/web/src/components/layouts/MobileDrawer.tsx b/web/src/components/layouts/MobileDrawer.tsxnew file mode 100644index 0000000000..2404c548f9--- /dev/null+++ b/web/src/components/layouts/MobileDrawer.tsx@@ -0,0 +1,44 @@+import { type PropsWithChildren } from "react";+import {+ Drawer,+ DrawerContent,+ DrawerDescription,+ DrawerHeader,+ DrawerTitle,+} from "@/src/components/ui/drawer";+import { useSupportDrawer } from "@/src/features/support-chat/SupportDrawerProvider";+import { SupportDrawer } from "@/src/features/support-chat/SupportDrawer";++export function MobileDrawer({ children }: PropsWithChildren) {+ const { open, setOpen } = useSupportDrawer();++ return (+ <>+ <main className="h-full flex-1" style={{ overscrollBehaviorY: "none" }}>+ {children}+ </main>++ <Drawer open={open} onOpenChange={setOpen} forceDirection="bottom">+ <DrawerContent+ id="support-drawer"+ className="inset-x-0 bottom-0 top-[calc(var(--banner-offset)+10px)] min-h-screen-with-banner"+ size="full"+ >+ <DrawerHeader className="absolute inset-x-0 top-0 p-0 text-left">+ <div className="flex w-full items-center justify-center pt-3">+ <div className="h-2 w-20 rounded-full bg-muted" />+ </div>+ {/* sr-only for screen readers and accessibility */}+ <DrawerTitle className="sr-only">Support</DrawerTitle>+ <DrawerDescription className="sr-only">+ A list of resources and options to help you with your questions.+ </DrawerDescription>+ </DrawerHeader>+ <div className="mt-4 max-h-full">+ <SupportDrawer showCloseButton={false} className="h-full pb-20" />+ </div>+ </DrawerContent>+ </Drawer>+ </>+ );+}diff --git a/web/src/components/layouts/ResizableDesktopLayout.tsx b/web/src/components/layouts/ResizableDesktopLayout.tsxnew file mode 100644index 0000000000..a1aa26b721--- /dev/null+++ b/web/src/components/layouts/ResizableDesktopLayout.tsx@@ -0,0 +1,101 @@+import { type ReactNode, useLayoutEffect, useRef } from "react";+import {+ ResizableHandle,+ ResizablePanel,+ ResizablePanelGroup,+ type ImperativePanelHandle,+} from "@/src/components/ui/resizable";++interface ResizableDesktopLayoutProps {+ mainContent: ReactNode;+ sidebarContent: ReactNode;+ open: boolean;+ defaultMainSize?: number;+ defaultSidebarSize?: number;+ minMainSize?: number;+ maxSidebarSize?: number;+ autoSaveId?: string;+ className?: string;+ sidebarPosition?: "left" | "right";+}++/**+ * Reusable component to show/hide resizable panels with a consistent DOM tree.+ * Always renders the same DOM tree to prevent remounting children and preserve their state.+ */+export function ResizableDesktopLayout({+ mainContent,+ sidebarContent,+ open,+ defaultMainSize = 70,+ defaultSidebarSize = 30,+ minMainSize = 30,+ maxSidebarSize = 60,+ autoSaveId,+ className = "flex h-full w-full",+ sidebarPosition = "right",+}: ResizableDesktopLayoutProps) {+ const sidebarPanelRef = useRef<ImperativePanelHandle>(null);+ const mainPanelRef = useRef<ImperativePanelHandle>(null);++ useLayoutEffect(() => {+ if (open) {+ sidebarPanelRef.current?.resize(defaultSidebarSize);+ mainPanelRef.current?.resize(defaultMainSize);+ } else {+ sidebarPanelRef.current?.resize(0);+ mainPanelRef.current?.resize(100);+ }+ }, [open, defaultMainSize, defaultSidebarSize]);++ return (+ <ResizablePanelGroup+ direction="horizontal"+ className={className}+ autoSaveId={autoSaveId}+ storage={autoSaveId ? sessionStorage : undefined}+ >+ {sidebarPosition === "left" && (+ <ResizablePanel+ ref={sidebarPanelRef}+ defaultSize={0}+ minSize={0}+ maxSize={maxSidebarSize}+ collapsible={true}+ collapsedSize={0}+ className={open ? "visible" : "invisible"}+ style={{ overscrollBehaviorY: "none" }}+ >+ {sidebarContent}+ </ResizablePanel>+ )}+ {open && <ResizableHandle withHandle />}+ <ResizablePanel+ ref={mainPanelRef}+ defaultSize={defaultMainSize}+ minSize={minMainSize}+ >+ <div+ className="relative h-full w-full overflow-scroll"+ style={{ overscrollBehaviorY: "none" }}+ >+ {mainContent}+ </div>+ </ResizablePanel>+ {sidebarPosition === "right" && (+ <ResizablePanel+ ref={sidebarPanelRef}+ defaultSize={0}+ minSize={0}+ maxSize={maxSidebarSize}+ collapsible={true}+ collapsedSize={0}+ className={open ? "visible" : "invisible"}+ style={{ overscrollBehaviorY: "none" }}+ >+ {sidebarContent}+ </ResizablePanel>+ )}+ </ResizablePanelGroup>+ );+}diff --git a/web/src/components/layouts/app-layout/components/ResizableContent.tsx b/web/src/components/layouts/app-layout/components/ResizableContent.tsxindex 75862d8d87..28747062b8 100644--- a/web/src/components/layouts/app-layout/components/ResizableContent.tsx+++ b/web/src/components/layouts/app-layout/components/ResizableContent.tsx@@ -6,23 +6,38 @@* Extracted from original layout.tsx (lines 414-493)*/-import { type PropsWithChildren, useRef, useLayoutEffect } from "react";-import { useIsMobile } from "@/src/hooks/use-mobile";import { useSupportDrawer } from "@/src/features/support-chat/SupportDrawerProvider";-import { SupportDrawer } from "@/src/features/support-chat/SupportDrawer";-import {- ResizableHandle,- ResizablePanel,- ResizablePanelGroup,- type ImperativePanelHandle,-} from "@/src/components/ui/resizable";-import {- Drawer,- DrawerContent,- DrawerDescription,- DrawerHeader,- DrawerTitle,-} from "@/src/components/ui/drawer";+import { type PropsWithChildren } from "react";+import { useMediaQuery } from "react-responsive";+import dynamic from "next/dynamic";++const MobileLayout = dynamic(+ () =>+ import("@/src/components/layouts/MobileDrawer").then((mod) => ({+ default: mod.MobileDrawer,+ })),+ {+ ssr: false,+ },+);+const DesktopLayout = dynamic(+ () =>+ import("@/src/components/layouts/ResizableDesktopLayout").then((mod) => ({+ default: mod.ResizableDesktopLayout,+ })),+ {+ ssr: false,+ },+);+const SupportDrawer = dynamic(+ () =>+ import("@/src/features/support-chat/SupportDrawer").then((mod) => ({+ default: mod.SupportDrawer,+ })),+ {+ ssr: false,+ },+);/*** Resizable content for support drawer on the right side of the screen (desktop).@@ -32,79 +47,22 @@ import {* remounting children when drawer opens/closes. Uses refs for programmatic control.*/export function ResizableContent({ children }: PropsWithChildren) {- const { open, setOpen } = useSupportDrawer();- const isMobile = useIsMobile();- const isDesktop = !isMobile;-- // 👉 DESKTOP: Always render ResizablePanelGroup to prevent remounting children- // Use refs to programmatically control panel sizes when drawer opens/closes- const drawerPanelRef = useRef<ImperativePanelHandle>(null);- const mainPanelRef = useRef<ImperativePanelHandle>(null);-- useLayoutEffect(() => {- if (!isDesktop) return;+ const isDesktop = useMediaQuery({ query: "(min-width: 768px)" });+ const { open } = useSupportDrawer();- if (open) {- // Open drawer: resize main to 70%, drawer to 30%- drawerPanelRef.current?.resize(30);- mainPanelRef.current?.resize(70);- } else {- // Close drawer: resize main to 100%, drawer to 0%- drawerPanelRef.current?.resize(0);- mainPanelRef.current?.resize(100);- }- }, [open, isDesktop]);-- // 👉 MOBILE: Render bottom drawerif (!isDesktop) {- return (- <>- <main className="h-full flex-1">{children}</main>-- <Drawer open={open} onOpenChange={setOpen} forceDirection="bottom">- <DrawerContent- id="support-drawer"- className="inset-x-0 bottom-0 top-[calc(var(--banner-offset)+10px)] min-h-screen-with-banner"- size="full"- >- <DrawerHeader className="absolute inset-x-0 top-0 p-0 text-left">- <div className="flex w-full items-center justify-center pt-3">- <div className="h-2 w-20 rounded-full bg-muted" />- </div>- {/* sr-only for screen readers and accessibility */}- <DrawerTitle className="sr-only">Support</DrawerTitle>- <DrawerDescription className="sr-only">- A list of resources and options to help you with your questions.- </DrawerDescription>- </DrawerHeader>- <div className="mt-4 max-h-full">- <SupportDrawer showCloseButton={false} className="h-full pb-20" />- </div>- </DrawerContent>- </Drawer>- </>- );+ return <MobileLayout>{children}</MobileLayout>;}- // 👉 DESKTOP: Always render ResizablePanelGroup to prevent remounting childrenreturn (- <ResizablePanelGroup direction="horizontal" className="flex h-full w-full">- <ResizablePanel ref={mainPanelRef} defaultSize={100} minSize={30}>- <main className="relative h-full w-full overflow-scroll">- {children}- </main>- </ResizablePanel>- {open && <ResizableHandle withHandle />}- <ResizablePanel- ref={drawerPanelRef}- defaultSize={0}- minSize={0}- maxSize={60}- collapsible={true}- collapsedSize={0}- >- {open && <SupportDrawer />}- </ResizablePanel>- </ResizablePanelGroup>+ <DesktopLayout+ mainContent={children}+ sidebarContent={<SupportDrawer />}+ open={open}+ defaultMainSize={70}+ defaultSidebarSize={30}+ minMainSize={30}+ maxSidebarSize={60}+ />);}diff --git a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsxindex 0c4d37dd9d..40f8e9451d 100644--- a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx+++ b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx@@ -8,17 +8,34 @@ import type { PropsWithChildren } from "react";import Head from "next/head";import { SidebarProvider, SidebarInset } from "@/src/components/ui/sidebar";import { AppSidebar } from "@/src/components/nav/app-sidebar";-import { CommandMenu } from "@/src/features/command-k-menu/CommandMenu";import { Toaster } from "@/src/components/ui/sonner";-import {- PaymentBanner,- PaymentBannerProvider,-} from "@/src/features/payment-banner";+import { PaymentBannerProvider } from "@/src/features/payment-banner";import { ResizableContent } from "../components/ResizableContent";import { ThemeToggle } from "@/src/features/theming/ThemeToggle";import type { Session } from "next-auth";import type { NavigationItem } from "@/src/components/layouts/utilities/routes";import type { RouteGroup } from "@/src/components/layouts/routes";+import dynamic from "next/dynamic";++const CommandMenu = dynamic(+ () =>+ import("@/src/features/command-k-menu/CommandMenu").then((mod) => ({+ default: mod.CommandMenu,+ })),+ {+ ssr: false,+ },+);++const PaymentBanner = dynamic(+ () =>+ import("@/src/features/payment-banner").then((mod) => ({+ default: mod.PaymentBanner,+ })),+ {+ ssr: false,+ },+);/** Grouped navigation structure returned by processNavigation */type GroupedNavigation = {diff --git a/web/src/components/table/resizable-filter-layout.tsx b/web/src/components/table/resizable-filter-layout.tsxindex 5a95cf388f..7ff57e272f 100644--- a/web/src/components/table/resizable-filter-layout.tsx+++ b/web/src/components/table/resizable-filter-layout.tsx@@ -2,11 +2,7 @@import { type PropsWithChildren, Children } from "react";import { useMediaQuery } from "react-responsive";-import {- ResizableHandle,- ResizablePanel,- ResizablePanelGroup,-} from "@/src/components/ui/resizable";+import { ResizableDesktopLayout } from "@/src/components/layouts/ResizableDesktopLayout";import { useDataTableControls } from "./data-table-controls";/** Resizable layout for filter sidebar and table content.@@ -17,11 +13,6 @@ export function ResizableFilterLayout({ children }: PropsWithChildren) {const { open, tableName } = useDataTableControls();const isDesktop = useMediaQuery({ query: "(min-width: 768px)" });- // On mobile, render children as-is (stacked layout)- if (!isDesktop) {- return <div className="flex flex-1 overflow-hidden">{children}</div>;- }-// Extract filter sidebar and table content from childrenconst childrenArray = Children.toArray(children).filter(Boolean);@@ -32,11 +23,16 @@ export function ResizableFilterLayout({ children }: PropsWithChildren) {? childrenArray.slice(1): childrenArray;+ // On mobile, render children as-is (stacked layout)+ if (!isDesktop) {+ return <div className="flex flex-1 overflow-hidden">{children}</div>;+ }+const filterDefault = 15;const tableDefault = 85;- // If sidebar is collapsed or doesn't exist, render only the table content- if (!open || !filterSidebar) {+ // If sidebar doesn't exist, render only the table content+ if (!filterSidebar) {return (<div className="flex flex-1 flex-col overflow-hidden">{tableContent}</div>);@@ -45,21 +41,20 @@ export function ResizableFilterLayout({ children }: PropsWithChildren) {const autoSaveId = tableName ? `filter-layout-${tableName}` : "filter-layout";return (- <ResizablePanelGroup- direction="horizontal"- className="flex h-full w-full"- autoSaveId={autoSaveId}- storage={sessionStorage}- >- <ResizablePanel defaultSize={filterDefault} minSize={12} maxSize={50}>- {filterSidebar}- </ResizablePanel>- <ResizableHandle />- <ResizablePanel defaultSize={tableDefault} minSize={50}>+ <ResizableDesktopLayout+ mainContent={<div className="flex h-full flex-col overflow-hidden">{tableContent}</div>- </ResizablePanel>- </ResizablePanelGroup>+ }+ sidebarContent={filterSidebar}+ open={open}+ defaultMainSize={tableDefault}+ defaultSidebarSize={filterDefault}+ minMainSize={50}+ maxSidebarSize={50}+ autoSaveId={autoSaveId}+ sidebarPosition="left"+ />);}diff --git a/web/src/features/command-k-menu/CommandMenu.tsx b/web/src/features/command-k-menu/CommandMenu.tsxindex 0936bc978a..d059e4ab74 100644--- a/web/src/features/command-k-menu/CommandMenu.tsx+++ b/web/src/features/command-k-menu/CommandMenu.tsx@@ -8,7 +8,7 @@ import {CommandSeparator,} from "@/src/components/ui/command";import { useRouter } from "next/router";-import { useEffect } from "react";+import { useEffect, memo } from "react";import { useSession } from "next-auth/react";import { env } from "@/src/env.mjs";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";@@ -21,18 +21,138 @@ import { useQueryProjectOrOrganization } from "@/src/features/projects/hooks";import { api } from "@/src/utils/api";import { type NavigationItem } from "@/src/components/layouts/utilities/routes";-export function CommandMenu({- mainNavigation,+function MainNavigationGroup({+ navItems,+ onNavigate,}: {- mainNavigation: NavigationItem[];+ navItems: Array<{ title: string; url: string }>;+ onNavigate: (item: { title: string; url: string }) => void;}) {- const { open, setOpen } = useCommandMenu();const router = useRouter();+ const capture = usePostHogClientCapture();++ return (+ <CommandGroup heading="Main Navigation">+ {navItems.map((item) => (+ <CommandItem+ key={item.url}+ value={item.url}+ keywords={[item.title]}+ onSelect={() => {+ router.push(item.url);+ capture("cmd_k_menu:navigated", {+ type: "main_navigation",+ title: item.title,+ url: item.url,+ });+ onNavigate(item);+ }}+ >+ {item.title}+ </CommandItem>+ ))}+ </CommandGroup>+ );+}++function ProjectsGroup({ onNavigate }: { onNavigate: () => void }) {+ const router = useRouter();+ const capture = usePostHogClientCapture();const { allProjectItems } = useNavigationItems();++ if (allProjectItems.length === 0) return null;++ return (+ <>+ <CommandSeparator />+ <CommandGroup heading="Projects">+ {allProjectItems.map((item) => (+ <CommandItem+ key={item.url}+ value={item.title}+ keywords={item.keywords}+ disabled={item.active}+ onSelect={() => {+ router.push(item.url);+ capture("cmd_k_menu:navigated", {+ type: "project",+ title: item.title,+ url: item.url,+ });+ onNavigate();+ }}+ >+ {item.title}+ </CommandItem>+ ))}+ </CommandGroup>+ </>+ );+}++function DashboardsGroup({ onNavigate }: { onNavigate: () => void }) {+ const router = useRouter();+ const capture = usePostHogClientCapture();+ const { project } = useQueryProjectOrOrganization();+ const { open } = useCommandMenu();++ const dashboardsQuery = api.dashboard.allDashboards.useQuery(+ {+ projectId: project?.id ?? "",+ orderBy: {+ column: "updatedAt",+ order: "DESC",+ },+ limit: 100,+ page: 0,+ },+ {+ enabled: open && Boolean(project?.id),+ },+ );++ const dashboards = dashboardsQuery.data?.dashboards ?? [];++ if (dashboards.length === 0) return null;++ return (+ <>+ <CommandSeparator />+ <CommandGroup heading="Dashboards">+ {dashboards.map((dashboard) => (+ <CommandItem+ key={dashboard.id}+ value={`Dashboard > ${dashboard.name}`}+ keywords={[+ "dashboard",+ dashboard.name.toLowerCase(),+ (dashboard.description ?? "").toLowerCase(),+ ]}+ disabled={router.query.dashboardId === dashboard.id}+ onSelect={() => {+ const url = `/project/${project?.id}/dashboards/${dashboard.id}`;+ router.push(url);+ capture("cmd_k_menu:navigated", {+ type: "dashboard",+ title: `Dashboard > ${dashboard.name}`,+ url: url,+ });+ onNavigate();+ }}+ >+ {dashboard.name}+ </CommandItem>+ ))}+ </CommandGroup>+ </>+ );+}++function ProjectSettingsGroup({ onNavigate }: { onNavigate: () => void }) {+ const router = useRouter();+ const capture = usePostHogClientCapture();const settingsPages = useProjectSettingsPages();- const orgSettingsPages = useOrganizationSettingsPages();- const accountSettingsPages = useAccountSettingsPages();- const { organization, project } = useQueryProjectOrOrganization();+ const { project } = useQueryProjectOrOrganization();const projectSettingsItems = settingsPages.filter((page) => page.show !== false && !("href" in page))@@ -42,6 +162,41 @@ export function CommandMenu({keywords: page.cmdKKeywords || [],}));+ if (projectSettingsItems.length === 0) return null;++ return (+ <>+ <CommandSeparator />+ <CommandGroup heading="Project Settings">+ {projectSettingsItems.map((item) => (+ <CommandItem+ key={item.url}+ value={item.title}+ keywords={item.keywords}+ onSelect={() => {+ router.push(item.url);+ capture("cmd_k_menu:navigated", {+ type: "project_settings",+ title: item.title,+ url: item.url,+ });+ onNavigate();+ }}+ >+ {item.title}+ </CommandItem>+ ))}+ </CommandGroup>+ </>+ );+}++function OrganizationSettingsGroup({ onNavigate }: { onNavigate: () => void }) {+ const router = useRouter();+ const capture = usePostHogClientCapture();+ const orgSettingsPages = useOrganizationSettingsPages();+ const { organization } = useQueryProjectOrOrganization();+const orgSettingsItems = orgSettingsPages.filter((page) => page.show !== false && !("href" in page)).map((page) => ({@@ -50,12 +205,81 @@ export function CommandMenu({keywords: page.cmdKKeywords || [],}));+ if (orgSettingsItems.length === 0) return null;++ return (+ <>+ <CommandSeparator />+ <CommandGroup heading="Organization Settings">+ {orgSettingsItems.map((item) => (+ <CommandItem+ key={item.url}+ value={item.title}+ keywords={item.keywords}+ onSelect={() => {+ router.push(item.url);+ capture("cmd_k_menu:navigated", {+ type: "organization_settings",+ title: item.title,+ url: item.url,+ });+ onNavigate();+ }}+ >+ {item.title}+ </CommandItem>+ ))}+ </CommandGroup>+ </>+ );+}++function AccountSettingsGroup({ onNavigate }: { onNavigate: () => void }) {+ const router = useRouter();+ const capture = usePostHogClientCapture();+ const accountSettingsPages = useAccountSettingsPages();+const accountSettingsItems = accountSettingsPages.map((page) => ({title: `Account Settings > ${page.title}`,url: `/account/settings${page.slug === "index" ? "" : `/${page.slug}`}`,keywords: page.cmdKKeywords || [],}));+ if (accountSettingsItems.length === 0) return null;++ return (+ <>+ <CommandSeparator />+ <CommandGroup heading="Account Settings">+ {accountSettingsItems.map((item) => (+ <CommandItem+ key={item.url}+ value={item.title}+ keywords={item.keywords}+ onSelect={() => {+ router.push(item.url);+ capture("cmd_k_menu:navigated", {+ type: "account_settings",+ title: item.title,+ url: item.url,+ });+ onNavigate();+ }}+ >+ {item.title}+ </CommandItem>+ ))}+ </CommandGroup>+ </>+ );+}++function CommandMenuComponent({+ mainNavigation,+}: {+ mainNavigation: NavigationItem[];+}) {+ const { open, setOpen } = useCommandMenu();const capture = usePostHogClientCapture();const debouncedSearchChange = useDebounce(@@ -84,39 +308,9 @@ export function CommandMenu({},];})- .filter(- (item) =>- Boolean(item.url) && // no empty urls- !item.url.includes("["), // no dynamic routes without inserted values- );-- const dashboardsQuery = api.dashboard.allDashboards.useQuery(- {- projectId: project?.id ?? "",- orderBy: {- column: "updatedAt",- order: "DESC",- },- limit: 100,- page: 0,- },- {- enabled: open && Boolean(project?.id),- },- );-- const dashboardItems =- dashboardsQuery.data?.dashboards.map((d) => ({- title: `Dashboard > ${d.name}`,- url: `/project/${project?.id}/dashboards/${d.id}`,- keywords: [- "dashboard",- d.name.toLowerCase(),- (d.description ?? "").toLowerCase(),- ],- active: router.query.dashboardId === d.id,- })) ?? [];+ .filter((item) => Boolean(item.url) && !item.url.includes("["));+ // Keyboard shortcut effectuseEffect(() => {const down = (e: KeyboardEvent) => {if (e.key === "k" && (e.metaKey || e.ctrlKey)) {@@ -133,6 +327,10 @@ export function CommandMenu({return () => document.removeEventListener("keydown", down);}, [capture, setOpen, open]);+ const handleNavigate = () => {+ setOpen(false);+ };+return (<CommandDialogopen={open}@@ -154,158 +352,59 @@ export function CommandMenu({/><CommandList><CommandEmpty>No results found.</CommandEmpty>- <CommandGroup heading="Main Navigation">- {navItems.map((item) => (- <CommandItem- key={item.url}- value={item.url}- keywords={[item.title]}- onSelect={() => {- router.push(item.url);- capture("cmd_k_menu:navigated", {- type: "main_navigation",- title: item.title,- url: item.url,- });- setOpen(false);- }}- >- {item.title}- </CommandItem>- ))}- </CommandGroup>- {allProjectItems.length > 0 && (- <>- <CommandSeparator />- <CommandGroup heading="Projects">- {allProjectItems.map((item) => (- <CommandItem- key={item.url}- value={item.title}- keywords={item.keywords}- disabled={item.active}- onSelect={() => {- router.push(item.url);- capture("cmd_k_menu:navigated", {- type: "project",- title: item.title,- url: item.url,- });- setOpen(false);- }}- >- {item.title}- </CommandItem>- ))}- </CommandGroup>- </>- )}- {dashboardItems.length > 0 && (- <>- <CommandSeparator />- <CommandGroup heading="Dashboards">- {dashboardItems.map((item) => (- <CommandItem- key={item.url}- value={item.title}- keywords={item.keywords}- disabled={item.active}- onSelect={() => {- router.push(item.url);- capture("cmd_k_menu:navigated", {- type: "dashboard",- title: item.title,- url: item.url,- });- setOpen(false);- }}- >- {item.title}- </CommandItem>- ))}- </CommandGroup>- </>- )}- {projectSettingsItems.length > 0 && (- <>- <CommandSeparator />- <CommandGroup heading="Project Settings">- {projectSettingsItems.map((item) => (- <CommandItem- key={item.url}- value={item.title}- keywords={item.keywords}- onSelect={() => {- router.push(item.url);- capture("cmd_k_menu:navigated", {- type: "project_settings",- title: item.title,- url: item.url,- });- setOpen(false);- }}- >- {item.title}- </CommandItem>- ))}- </CommandGroup>- </>- )}- {orgSettingsItems.length > 0 && (- <>- <CommandSeparator />- <CommandGroup heading="Organization Settings">- {orgSettingsItems.map((item) => (- <CommandItem- key={item.url}- value={item.title}- keywords={item.keywords}- onSelect={() => {- router.push(item.url);- capture("cmd_k_menu:navigated", {- type: "organization_settings",- title: item.title,- url: item.url,- });- setOpen(false);- }}- >- {item.title}- </CommandItem>- ))}- </CommandGroup>- </>- )}- {accountSettingsItems.length > 0 && (- <>- <CommandSeparator />- <CommandGroup heading="Account Settings">- {accountSettingsItems.map((item) => (- <CommandItem- key={item.url}- value={item.title}- keywords={item.keywords}- onSelect={() => {- router.push(item.url);- capture("cmd_k_menu:navigated", {- type: "account_settings",- title: item.title,- url: item.url,- });- setOpen(false);- }}- >- {item.title}- </CommandItem>- ))}- </CommandGroup>- </>- )}+ <MainNavigationGroup navItems={navItems} onNavigate={handleNavigate} />+ <ProjectsGroup onNavigate={handleNavigate} />+ <DashboardsGroup onNavigate={handleNavigate} />+ <ProjectSettingsGroup onNavigate={handleNavigate} />+ <OrganizationSettingsGroup onNavigate={handleNavigate} />+ <AccountSettingsGroup onNavigate={handleNavigate} /></CommandList></CommandDialog>);}+export const CommandMenu = memo(+ CommandMenuComponent,+ (prevProps, nextProps) => {+ // Only re-render if mainNavigation titles or urls change+ if (prevProps.mainNavigation.length !== nextProps.mainNavigation.length) {+ return false;+ }++ const isSame = prevProps.mainNavigation.every((item, idx) => {+ const nextItem = nextProps.mainNavigation[idx];+ const itemTitleUrl =+ item.title === nextItem.title && item.url === nextItem.url;++ if (!itemTitleUrl) {+ return false;+ }++ // Check children if they exist+ if (item.items && nextItem.items) {+ if (item.items.length !== nextItem.items.length) {+ return false;+ }+ const childrenMatch = item.items.every((child, childIdx) => {+ const nextChild = nextItem.items![childIdx];+ const match =+ child.title === nextChild.title && child.url === nextChild.url;+ return match;+ });+ return itemTitleUrl && childrenMatch;+ }++ if ((item.items || nextItem.items) && !(item.items && nextItem.items)) {+ return false;+ }++ return itemTitleUrl && !item.items && !nextItem.items;+ });++ return isSame;+ },+);+export const useNavigationItems = () => {const router = useRouter();const session = useSession();diff --git a/web/src/features/command-k-menu/CommandMenuProvider.tsx b/web/src/features/command-k-menu/CommandMenuProvider.tsxindex eb2255ae7a..1636f77bab 100644--- a/web/src/features/command-k-menu/CommandMenuProvider.tsx+++ b/web/src/features/command-k-menu/CommandMenuProvider.tsx@@ -1,4 +1,10 @@-import { createContext, useContext, useState, type ReactNode } from "react";+import {+ createContext,+ useContext,+ useMemo,+ useState,+ type ReactNode,+} from "react";interface CommandMenuContextType {open: boolean;@@ -12,8 +18,12 @@ const CommandMenuContext = createContext<CommandMenuContextType | undefined>(export function CommandMenuProvider({ children }: { children: ReactNode }) {const [open, setOpen] = useState(false);+ const value = useMemo(() => {+ return { open, setOpen };+ }, [open]);+return (- <CommandMenuContext.Provider value={{ open, setOpen }}>+ <CommandMenuContext.Provider value={value}>{children}</CommandMenuContext.Provider>);