:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
perf(navigation): improve side panel resize performance (#118745)
Matt Puaef39c6a21e9d
diff --git a/frontend/src/layout/navigation-3000/Navigation.tsx b/frontend/src/layout/navigation-3000/Navigation.tsxindex be4ee9b711d4..ac9648f7385c 100644--- a/frontend/src/layout/navigation-3000/Navigation.tsx+++ b/frontend/src/layout/navigation-3000/Navigation.tsx@@ -253,7 +253,10 @@ export function Navigation({{/* The attribute rides a spread with the empty-string form: React 18'stypes lack `inert`, and its runtime serializes `inert={false}` to astring, which is still inert (presence-based attribute). */}- <div className="contents" {...(sceneTakeoverActive ? { inert: '' } : {})}>+ <div+ className="contents [--side-panel-width:initial]"+ {...(sceneTakeoverActive ? { inert: '' } : {})}+ >{!sceneMenuBarEnabled && !sceneConfig?.hideProjectNotice && (<divclassName={cn({diff --git a/frontend/src/layout/navigation-3000/sidepanel/SidePanel.tsx b/frontend/src/layout/navigation-3000/sidepanel/SidePanel.tsxindex f469b46173c8..6c9cf6c9b75f 100644--- a/frontend/src/layout/navigation-3000/sidepanel/SidePanel.tsx+++ b/frontend/src/layout/navigation-3000/sidepanel/SidePanel.tsx@@ -1,16 +1,14 @@import './SidePanel.scss'import { useActions, useValues } from 'kea'-import { Suspense, useEffect, useRef } from 'react'+import { memo, useEffect, useRef } from 'react'import { IconApps, IconChat, IconLock, IconLogomark, IconNotebook, IconPulse } from '@posthog/icons'import { Resizer } from 'lib/components/Resizer/Resizer'import { ResizerLogicProps, resizerLogic } from 'lib/components/Resizer/resizerLogic'-import { Spinner } from 'lib/lemon-ui/Spinner'import { cn } from 'lib/utils/css-classes'import { lazyWithRetry } from 'lib/utils/retryImport'-import { ChunkLoadErrorBoundary } from 'scenes/ChunkLoadErrorBoundary'const NotebookPanel = lazyWithRetry(() =>import('scenes/notebooks/NotebookPanel/NotebookPanel').then((m) => ({ default: m.NotebookPanel }))@@ -41,7 +39,6 @@ const SidePanelActivity = lazyWithRetry(() =>import { useWindowSize } from 'lib/hooks/useWindowSize'-import { ErrorBoundary } from '~/layout/ErrorBoundary'import { themeLogic } from '~/layout/navigation-3000/themeLogic'import { panelLayoutLogic } from '~/layout/panel-layout/panelLayoutLogic'import { SidePanelTab } from '~/types'@@ -53,8 +50,8 @@ import { SidePanelDiscussionIcon } from './panels/discussion/SidePanelDiscussionimport { SidePanelExportsIcon } from './panels/exports/SidePanelExportsIcon'import { SidePanelInfo, SidePanelInfoIcon } from './panels/info/SidePanelInfo'import { SidePanelMax } from './panels/max/SidePanelMax'+import { SidePanelContent } from './SidePanelContent'import { sidePanelLogic } from './sidePanelLogic'-import { SidePanelNavigation } from './SidePanelNavigation'import { sidePanelStateLogic } from './sidePanelStateLogic'export const SIDE_PANEL_TABS: Record<SidePanelTab, { label: string; Icon: any; Content: any }> = {@@ -123,7 +120,7 @@ export const SIDE_PANEL_TABS: Record<SidePanelTab, { label: string; Icon: any; Cconst DEFAULT_WIDTH = 512const SIDE_PANEL_MIN_WIDTH_COMPACT = 330-export function SidePanel({ className }: { className?: string }): JSX.Element | null {+export const SidePanel = memo(function SidePanel({ className }: { className?: string }): JSX.Element | null {const { theme } = useValues(themeLogic)const { enabledTabs, visibleTabs } = useValues(sidePanelLogic)const { selectedTab, sidePanelOpen } = useValues(sidePanelStateLogic)@@ -148,8 +145,7 @@ export function SidePanel({ className }: { className?: string }): JSX.Element |}const { desiredSize, isResizeInProgress } = useValues(resizerLogic(resizerLogicProps))- const { setMainContentRect, setSidePanelWidth } = useActions(panelLayoutLogic)- const { mainContentRef } = useValues(panelLayoutLogic)+ const { setSidePanelWidth } = useActions(panelLayoutLogic)useEffect(() => {setSidePanelAvailable(true)@@ -158,13 +154,6 @@ export function SidePanel({ className }: { className?: string }): JSX.Element |}}, [setSidePanelAvailable])- // Trigger scene width recalculation when SidePanel size changes- useEffect(() => {- if (mainContentRef?.current) {- setMainContentRect(mainContentRef.current.getBoundingClientRect())- }- }, [desiredSize, sidePanelOpen, setMainContentRect, mainContentRef])-// A tab is unavailable both when the scene will never offer it and while the scene is still// loading the object it describes. Staying open renders nothing until the tab resolves, which// keeps deep links like #panel=access-control working on a cold load. Leaving a scene is what@@ -197,6 +186,7 @@ export function SidePanel({ className }: { className?: string }): JSX.Element |sidePanelOpenAndAvailable && 'SidePanel3000--open justify-end',isResizeInProgress && 'SidePanel3000--resizing','@container/side-panel bg-surface-secondary absolute top-0 right-0 bottom-0 h-full flex flex-col border-t-none',+ '[--side-panel-width:initial] [--scene-layout-rect-width:initial] [--scene-layout-rect-right:initial]',!sidePanelOpen && 'hidden',className)}@@ -225,18 +215,7 @@ export function SidePanel({ className }: { className?: string }): JSX.Element |</>)}- {PanelContent && (- <SidePanelNavigation activeTab={activeTab as SidePanelTab} onTabChange={(tab) => openSidePanel(tab)}>- <ErrorBoundary>- {/* Keep chunk-load failures out of the panel error reporter so stale assets reload once instead. */}- <ChunkLoadErrorBoundary>- <Suspense fallback={<Spinner className="text-4xl mx-auto mt-16" />}>- <PanelContent />- </Suspense>- </ChunkLoadErrorBoundary>- </ErrorBoundary>- </SidePanelNavigation>- )}+ {PanelContent && <SidePanelContent activeTab={activeTab as SidePanelTab} Content={PanelContent} />}</div>)-}+})diff --git a/frontend/src/layout/navigation-3000/sidepanel/SidePanelContent.tsx b/frontend/src/layout/navigation-3000/sidepanel/SidePanelContent.tsxnew file mode 100644index 000000000000..4c3c38e186db--- /dev/null+++ b/frontend/src/layout/navigation-3000/sidepanel/SidePanelContent.tsx@@ -0,0 +1,33 @@+import { useActions } from 'kea'+import { ComponentType, memo, Suspense } from 'react'++import { Spinner } from 'lib/lemon-ui/Spinner'+import { ChunkLoadErrorBoundary } from 'scenes/ChunkLoadErrorBoundary'++import { ErrorBoundary } from '~/layout/ErrorBoundary'+import { SidePanelTab } from '~/types'++import { SidePanelNavigation } from './SidePanelNavigation'+import { sidePanelStateLogic } from './sidePanelStateLogic'++export const SidePanelContent = memo(function SidePanelContent({+ activeTab,+ Content,+}: {+ activeTab: SidePanelTab+ Content: ComponentType+}): JSX.Element {+ const { openSidePanel } = useActions(sidePanelStateLogic)++ return (+ <SidePanelNavigation activeTab={activeTab} onTabChange={openSidePanel}>+ <ErrorBoundary>+ <ChunkLoadErrorBoundary>+ <Suspense fallback={<Spinner className="text-4xl mx-auto mt-16" />}>+ <Content />+ </Suspense>+ </ChunkLoadErrorBoundary>+ </ErrorBoundary>+ </SidePanelNavigation>+ )+})diff --git a/frontend/src/layout/panel-layout/PanelLayout.tsx b/frontend/src/layout/panel-layout/PanelLayout.tsxindex 517a737f6c0e..b20c3a13e0fb 100644--- a/frontend/src/layout/panel-layout/PanelLayout.tsx+++ b/frontend/src/layout/panel-layout/PanelLayout.tsx@@ -1,5 +1,6 @@import { cva } from 'cva'import { useActions, useMountedLogic, useValues } from 'kea'+import { memo } from 'react'import { IconX } from '@posthog/icons'@@ -66,7 +67,7 @@ const panelLayoutStyles = cva({],})-export function PanelLayout({ className }: { className?: string }): JSX.Element {+export const PanelLayout = memo(function PanelLayout({ className }: { className?: string }): JSX.Element {const {isLayoutPanelVisible,isLayoutNavbarVisibleForMobile,@@ -105,6 +106,7 @@ export function PanelLayout({ className }: { className?: string }): JSX.ElementisMobileLayout,isLayoutNavCollapsed,}),+ '[--side-panel-width:initial] [--scene-layout-rect-width:initial] [--scene-layout-rect-right:initial]',className)}// eslint-disable-next-line react/forbid-dom-props@@ -187,4 +189,4 @@ export function PanelLayout({ className }: { className?: string }): JSX.Element/></>)-}+})