: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(frontend): load the today layout only when its flag is on (#122608)
Paul D'Ambra9a7749803287
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjsindex 036de65537d9..4bbf4639b5f7 100644--- a/frontend/bin/check-eager-graph.mjs+++ b/frontend/bin/check-eager-graph.mjs@@ -117,6 +117,11 @@ const ROOTS = ['src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts',// The wizard run card opens this drawer on click, and the drawer pulls in quill primitives.'products/wizard/frontend/runs/WizardRunDetailsDrawer.tsx',+ // The Today layout renders only behind the today-rail-nav flag, and it pulls in quill primitives.+ 'src/layout/today/TodayShell.tsx',+ 'src/layout/today/TodayContextPanelFloating.tsx',+ 'src/layout/today/TodaySidePanel.tsx',+ 'src/layout/today/TodayTopBar.tsx',// The zod-en-locale-only plugin in common/esbuilder/utils.mjs keeps every locale except// `en` out of the build. A hit on another locale means zod moved its locales barrel and// the plugin no longer matches it.diff --git a/frontend/src/layout/navigation-3000/Navigation.tsx b/frontend/src/layout/navigation-3000/Navigation.tsxindex fc8b24ebcdcf..013cebd44df8 100644--- a/frontend/src/layout/navigation-3000/Navigation.tsx+++ b/frontend/src/layout/navigation-3000/Navigation.tsx@@ -1,12 +1,13 @@import './Navigation.scss'import { useActions, useMountedLogic, useValues } from 'kea'-import { ReactNode, useCallback, useEffect, useLayoutEffect, useRef } from 'react'+import { ReactNode, Suspense, useCallback, useEffect, useLayoutEffect, useRef } from 'react'import { mcpHintLogic } from 'lib/components/MCPHint/mcpHintLogic'import { ScrollableShadows } from 'lib/components/ScrollableShadows/ScrollableShadows'import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { cn } from 'lib/utils/css-classes'+import { lazyWithRetry } from 'lib/utils/retryImport'import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'import { sceneLogic } from 'scenes/sceneLogic'import { Scene, SceneConfig } from 'scenes/sceneTypes'@@ -14,11 +15,8 @@ import { Scene, SceneConfig } from 'scenes/sceneTypes'import { PanelLayout } from '~/layout/panel-layout/PanelLayout'import { panelLayoutLogic } from '~/layout/panel-layout/panelLayoutLogic'import { ProjectDragAndDropProvider } from '~/layout/panel-layout/ProjectTree/ProjectDragAndDropContext'-import { TodayContextPanelFloating } from '~/layout/today/TodayContextPanelFloating'-import { TodayShell } from '~/layout/today/TodayShell'+import { todayPanelChatSessionLogic } from '~/layout/today/todayPanelChatSessionLogic'import { TODAY_RAIL_WIDTH, todayShellLogic } from '~/layout/today/todayShellLogic'-import { TodaySidePanel } from '~/layout/today/TodaySidePanel'-import { TodayTopBar } from '~/layout/today/TodayTopBar'import { navigationLogic } from '../navigation/navigationLogic'import { ProjectNotice } from '../navigation/ProjectNotice'@@ -31,6 +29,16 @@ import { SidePanel } from './sidepanel/SidePanel'import { sidePanelStateLogic } from './sidepanel/sidePanelStateLogic'import { themeLogic } from './themeLogic'+// The Today layout renders only behind the today-rail-nav flag, and its quill UI would otherwise load on every logged-in page.+const TodayContextPanelFloating = lazyWithRetry(() =>+ import('~/layout/today/TodayContextPanelFloating').then((m) => ({ default: m.TodayContextPanelFloating }))+)+const TodayShell = lazyWithRetry(() => import('~/layout/today/TodayShell').then((m) => ({ default: m.TodayShell })))+const TodaySidePanel = lazyWithRetry(() =>+ import('~/layout/today/TodaySidePanel').then((m) => ({ default: m.TodaySidePanel }))+)+const TodayTopBar = lazyWithRetry(() => import('~/layout/today/TodayTopBar').then((m) => ({ default: m.TodayTopBar })))+export function Navigation({children,sceneConfig,@@ -117,6 +125,11 @@ export function Navigation({const noPaddingScene = sceneConfig?.layout === 'app-raw-no-header' || sceneConfig?.layout === 'app-raw'+ // The chat session restores a saved run when it mounts. A layout effect runs before any scene's passive effect,+ // so a scene that clears the panel on show (the AI-first composer) clears it after the restore. The lazy TodayShell+ // loads too late to mount it.+ useLayoutEffect(() => (todayRail ? todayPanelChatSessionLogic.mount() : undefined), [todayRail])+const todayPhoneBodyClass = todayPhone && mode === 'full'useLayoutEffect(() => {if (!todayPhoneBodyClass) {@@ -201,8 +214,18 @@ export function Navigation({}><ProjectDragAndDropProvider>- {todayFramed && <TodayTopBar />}- {todayRail ? <TodayShell className="left-nav" /> : <PanelLayout className="left-nav" />}+ {todayFramed && (+ <Suspense fallback={null}>+ <TodayTopBar />+ </Suspense>+ )}+ {todayRail ? (+ <Suspense fallback={null}>+ <TodayShell className="left-nav" />+ </Suspense>+ ) : (+ <PanelLayout className="left-nav" />+ )}{todayFramed && <div aria-hidden className="TodayAppLayout__shadow" />}{todayFramed && (// The chrome token exists only inside a quill scope, so the backdrop that fills the gap above the frame carries data-quill.@@ -330,9 +353,17 @@ export function Navigation({</div></>)}- {todayFramed && !todayOnAiPage && <TodayContextPanelFloating />}+ {todayFramed && !todayOnAiPage && (+ <Suspense fallback={null}>+ <TodayContextPanelFloating />+ </Suspense>+ )}</div>- {todayFramed && <TodaySidePanel />}+ {todayFramed && (+ <Suspense fallback={null}>+ <TodaySidePanel />+ </Suspense>+ )}</ProjectDragAndDropProvider></div></>diff --git a/frontend/src/layout/today/TodayShell.tsx b/frontend/src/layout/today/TodayShell.tsxindex 60923e516a24..11f37057cdcb 100644--- a/frontend/src/layout/today/TodayShell.tsx+++ b/frontend/src/layout/today/TodayShell.tsx@@ -1,6 +1,6 @@import './TodayShell.scss'-import { useActions, useMountedLogic, useValues } from 'kea'+import { useActions, useValues } from 'kea'import { Suspense, useEffect, useRef } from 'react'import { Skeleton, ToastProvider } from '@posthog/quill'@@ -15,7 +15,6 @@ import { lazyWithRetry } from 'lib/utils/retryImport'import { QuillSceneHeader } from '~/layout/scenes/components/QuillSceneHeader'-import { todayPanelChatSessionLogic } from './todayPanelChatSessionLogic'import { TodayPhoneHeader } from './TodayPhoneHeader'import { TodayRail } from './TodayRail'import { TODAY_PANES } from './todayRailItems'@@ -43,7 +42,6 @@ const NewSpaceDialog = lazyWithRetry(() =>export function TodayShell({ className }: { className?: string }): JSX.Element {const { activePane, mobileLayout, phoneLayout, sidebarVisible, sidebarWidth, phoneHeaderHidden } =useValues(todayShellLogic)- useMountedLogic(todayPanelChatSessionLogic)const { setMobileSidebarOpen, setSidebarOpen, setSidebarWidth, toggleSidebar } = useActions(todayShellLogic)useShortcut({name: 'ToggleLeftNav',