Skip to content

: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.

perf(posthog-ai): load the side panel and onboarding lazily (#126328)

Paul D'Ambrac7f5c09816d2
diff --git a/frontend/src/layout/GlobalModals.tsx b/frontend/src/layout/GlobalModals.tsx
index 08c4a37a6592..41fa041c81eb 100644
--- a/frontend/src/layout/GlobalModals.tsx
+++ b/frontend/src/layout/GlobalModals.tsx
@@ -15,7 +15,6 @@ import { useKeepMountedWhileOpen } from 'lib/hooks/useKeepMountedWhileOpen'
import { lazyWithRetry } from 'lib/utils/retryImport'
import { TwoFactorSetupModal } from 'scenes/authentication/two-factor-setup/TwoFactorSetupModal'
import { PaymentEntryModal } from 'scenes/billing/PaymentEntryModal'
-import { MaybePhaiOnboarding } from 'scenes/max/components/MaybePhaiOnboarding'
import { CreateOrganizationModal } from 'scenes/organization/CreateOrganizationModal'
import { CreateProjectModal } from 'scenes/project/CreateProjectModal'
import { sessionPlayerModalLogic } from 'scenes/session-recordings/player/modal/sessionPlayerModalLogic'
@@ -58,6 +57,12 @@ const ComposeTicketModal = lazyWithRetry(() =>
}))
)
+const MaybePhaiOnboarding = lazyWithRetry(() =>
+ import('scenes/max/components/MaybePhaiOnboarding').then((m) => ({
+ default: m.MaybePhaiOnboarding,
+ }))
+)
+
export function GlobalModals(): JSX.Element {
const { isCreateOrganizationModalShown, isCreateProjectModalShown } = useValues(globalModalsLogic)
const { hideCreateOrganizationModal, hideCreateProjectModal } = useActions(globalModalsLogic)
@@ -107,7 +112,9 @@ export function GlobalModals(): JSX.Element {
{superpowersEnabled && <SuperpowersModal />}
<MaybeWelcomeDialog />
<MaybeProductPushWelcome />
- <MaybePhaiOnboarding />
+ <Suspense fallback={null}>
+ <MaybePhaiOnboarding />
+ </Suspense>
{shouldRenderComposeTicketModal ? (
<Suspense fallback={null}>
<ComposeTicketModal />
diff --git a/frontend/src/layout/navigation-3000/sidepanel/sidePanelTabs.tsx b/frontend/src/layout/navigation-3000/sidepanel/sidePanelTabs.tsx
index c995f5e8c774..ddb96cc0e540 100644
--- a/frontend/src/layout/navigation-3000/sidepanel/sidePanelTabs.tsx
+++ b/frontend/src/layout/navigation-3000/sidepanel/sidePanelTabs.tsx
@@ -10,8 +10,8 @@ import { SidePanelActivityIcon } from './panels/activity/SidePanelActivityIcon'
import { SidePanelDiscussionIcon } from './panels/discussion/SidePanelDiscussionIcon'
import { SidePanelExportsIcon } from './panels/exports/SidePanelExportsIcon'
import { SidePanelInfo, SidePanelInfoIcon } from './panels/info/SidePanelInfo'
-import { SidePanelMax } from './panels/max/SidePanelMax'
+const SidePanelMax = lazyWithRetry(() => import('./panels/max/SidePanelMax').then((m) => ({ default: m.SidePanelMax })))
const NotebookPanel = lazyWithRetry(() =>
import('scenes/notebooks/NotebookPanel/NotebookPanel').then((m) => ({ default: m.NotebookPanel }))
)
diff --git a/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx b/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx
index 8448fe60635d..3c00d80e458d 100644
--- a/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx
+++ b/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx
@@ -29,8 +29,9 @@ import {
} from 'lib/ui/quill'
import { copyToClipboard } from 'lib/utils/copyToClipboard'
import { cn } from 'lib/utils/css-classes'
-import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'
+import { newInternalTab } from 'lib/utils/newInternalTab'
import { projectLogic } from 'scenes/projectLogic'
+import { urls } from 'scenes/urls'
import { todayShellLogic } from '~/layout/today/todayShellLogic'
@@ -111,7 +112,6 @@ interface AgentDef {
}
interface AgentOpenContext {
- askSidePanelMax: (prompt: string) => void
actionLabel: string
repository?: string
}
@@ -209,7 +209,7 @@ const AGENTS: AgentDef[] = [
name: 'PostHog AI',
logo: <IconSparkles className="size-4 shrink-0 text-ai" />,
verb: 'Open',
- open: (prompt, { askSidePanelMax }) => askSidePanelMax(prompt),
+ open: (prompt) => newInternalTab(urls.ai(undefined, prompt)),
},
{
key: 'posthog-code',
@@ -313,7 +313,6 @@ export function AgentPromptButton({
const { rememberedAgentKey, rememberedActionKeys } = useValues(agentPromptButtonLogic)
const { rememberAgent, rememberAction } = useActions(agentPromptButtonLogic)
const [open, setOpen] = useState(defaultOpen)
- const { askSidePanelMax } = useActions(maxGlobalLogic)
const { todayRailEnabled } = useValues(todayShellLogic)
const { currentProjectId } = useValues(projectLogic)
const { isCloudOrDev } = useValues(preflightLogic)
@@ -349,7 +348,7 @@ export function AgentPromptButton({
if (!agent) {
return
}
- agent.open(prompt, { askSidePanelMax, actionLabel: action.label, repository })
+ agent.open(prompt, { actionLabel: action.label, repository })
}
const selectAgent = (agentKey: AgentPromptDestination): void => {
diff --git a/frontend/src/lib/components/Superpowers/Superpowers.tsx b/frontend/src/lib/components/Superpowers/Superpowers.tsx
index 1a5014ca957c..694d3ab08481 100644
--- a/frontend/src/lib/components/Superpowers/Superpowers.tsx
+++ b/frontend/src/lib/components/Superpowers/Superpowers.tsx
@@ -8,8 +8,8 @@ import { LemonButton, LemonDivider, LemonSelect, LemonSwitch, LemonTag } from '@
import { pngHoggie } from 'lib/brand/hoggies'
import { LemonModal } from 'lib/lemon-ui/LemonModal'
import { preflightLogic } from 'lib/logic/preflightLogic'
-import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'
import { organizationLogic } from 'scenes/organizationLogic'
+import { aiConsentLogic } from 'scenes/settings/organization/aiConsentLogic'
import { teamLogic } from 'scenes/teamLogic'
import { userLogic } from 'scenes/userLogic'
@@ -251,7 +251,7 @@ function SuperpowersContent(): JSX.Element {
const { fakeStatusOverride, fakeBillingAlert, mcpHintsDismissed } = useValues(superpowersLogic)
const { closeSuperpowers, setFakeStatusOverride, setFakeBillingAlert, reenableMCPHints } =
useActions(superpowersLogic)
- const { dataProcessingAccepted } = useValues(maxGlobalLogic)
+ const { dataProcessingAccepted } = useValues(aiConsentLogic)
const { updateOrganization } = useActions(organizationLogic)
const { isDev } = useValues(preflightLogic)