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.

chore(frontend): load the impersonation notice only for impersonating staff (#126942)

Paul D'Ambra0fe89f7be74f
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjs
index dff9cbe44f68..1387e203b60b 100644
--- a/frontend/bin/check-eager-graph.mjs
+++ b/frontend/bin/check-eager-graph.mjs
@@ -104,8 +104,8 @@ const ROOTS = [
{
root: AUTHENTICATED_SHELL,
label: 'authenticated shell (every logged-in page)',
- // 2026-11-01: 4.14 MiB eager output, stable CSS included. ~0.3% headroom.
- budgetBytes: 4_360_000,
+ // 2026-11-01: 4.11 MiB eager output, stable CSS included. ~0.3% headroom.
+ budgetBytes: 4_320_000,
forbidden: [
'node_modules/monaco-editor/',
'products/product_analytics/frontend/insights/activityDescriptions',
@@ -125,6 +125,8 @@ const ROOTS = [
'src/taxonomy/core-filter-definitions-by-group.json',
// The project notice logic pulls in dompurify and the sample data logic.
'src/layout/navigation/projectNoticeLogic.tsx',
+ // Only impersonating staff see this notice, and it pulls in react-draggable.
+ 'src/layout/navigation/ImpersonationNotice/ImpersonationNotice.tsx',
// 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.
@@ -188,8 +190,8 @@ const ROOTS = [
'src/scenes/project-homepage/today/TodayHome.tsx',
],
label: 'today home path',
- // 2026-11-01: 5.05 MiB, stable CSS included. ~0.3% headroom.
- budgetBytes: 5_310_000,
+ // 2026-11-01: 5.01 MiB, stable CSS included. ~0.3% headroom.
+ budgetBytes: 5_270_000,
forbidden: [
'src/scenes/project-homepage/ai-first/AiFirstHomepage.tsx',
'src/scenes/project-homepage/today/TodayReportPage.tsx',
@@ -206,8 +208,8 @@ const ROOTS = [
'src/scenes/project-homepage/ai-first/AiFirstHomepage.tsx',
],
label: 'AI-first home path',
- // 2026-11-01: 6.44 MiB, stable CSS included. ~1% headroom.
- budgetBytes: 6_820_000,
+ // 2026-11-01: 6.39 MiB, stable CSS included. ~1% headroom.
+ budgetBytes: 6_770_000,
forbidden: [
'products/posthog_ai/frontend/components/tool/widgets/VisualizationWidget.tsx',
'products/posthog_ai/frontend/components/tool/widgets/RecordingsWidget.tsx',
diff --git a/frontend/src/layout/navigation/ImpersonationNotice/ImpersonationNoticeSlot.test.tsx b/frontend/src/layout/navigation/ImpersonationNotice/ImpersonationNoticeSlot.test.tsx
new file mode 100644
index 000000000000..3007cea00cc0
--- /dev/null
+++ b/frontend/src/layout/navigation/ImpersonationNotice/ImpersonationNoticeSlot.test.tsx
@@ -0,0 +1,34 @@
+import '@testing-library/jest-dom'
+
+import { act, cleanup, render, screen } from '@testing-library/react'
+
+import { userLogic } from 'scenes/userLogic'
+
+import { initKeaTests } from '~/test/init'
+
+import { ImpersonationNoticeSlot } from './ImpersonationNoticeSlot'
+
+jest.mock('./ImpersonationNotice', () => ({
+ ImpersonationNotice: () => <div>impersonation notice</div>,
+}))
+
+describe('ImpersonationNoticeSlot', () => {
+ beforeEach(() => {
+ initKeaTests()
+ userLogic.mount()
+ })
+
+ afterEach(cleanup)
+
+ it('keeps the notice mounted after impersonation ends', async () => {
+ act(() => userLogic.actions.loadUserSuccess({ is_impersonated: false } as any))
+ render(<ImpersonationNoticeSlot />)
+ expect(screen.queryByText('impersonation notice')).not.toBeInTheDocument()
+
+ act(() => userLogic.actions.loadUserSuccess({ is_impersonated: true } as any))
+ expect(await screen.findByText('impersonation notice')).toBeInTheDocument()
+
+ act(() => userLogic.actions.loadUserSuccess({ is_impersonated: false } as any))
+ expect(screen.getByText('impersonation notice')).toBeInTheDocument()
+ })
+})
diff --git a/frontend/src/layout/navigation/ImpersonationNotice/ImpersonationNoticeSlot.tsx b/frontend/src/layout/navigation/ImpersonationNotice/ImpersonationNoticeSlot.tsx
new file mode 100644
index 000000000000..0507a5480f99
--- /dev/null
+++ b/frontend/src/layout/navigation/ImpersonationNotice/ImpersonationNoticeSlot.tsx
@@ -0,0 +1,40 @@
+import { useValues } from 'kea'
+import { Suspense, useEffect, useState } from 'react'
+
+import { lazyWithRetry } from 'lib/utils/retryImport'
+import { ChunkLoadErrorBoundary } from 'scenes/ChunkLoadErrorBoundary'
+import { userLogic } from 'scenes/userLogic'
+
+import { ErrorBoundary } from '~/layout/ErrorBoundary'
+
+// Only staff who impersonate a user see the notice, so everyone else skips the chunk and react-draggable.
+const ImpersonationNotice = lazyWithRetry(() =>
+ import('./ImpersonationNotice').then(({ ImpersonationNotice }) => ({ default: ImpersonationNotice }))
+)
+
+export function ImpersonationNoticeSlot(): JSX.Element | null {
+ const { user } = useValues(userLogic)
+ const isImpersonated = !!user?.is_impersonated
+ // Stays true after the session ends, so the notice can still show its expired-session overlay.
+ const [wasImpersonated, setWasImpersonated] = useState(isImpersonated)
+
+ useEffect(() => {
+ if (isImpersonated) {
+ setWasImpersonated(true)
+ }
+ }, [isImpersonated])
+
+ if (!isImpersonated && !wasImpersonated) {
+ return null
+ }
+
+ return (
+ <ErrorBoundary>
+ <ChunkLoadErrorBoundary>
+ <Suspense fallback={null}>
+ <ImpersonationNotice />
+ </Suspense>
+ </ChunkLoadErrorBoundary>
+ </ErrorBoundary>
+ )
+}
diff --git a/frontend/src/layout/navigation/ImpersonationNotice/index.ts b/frontend/src/layout/navigation/ImpersonationNotice/index.ts
deleted file mode 100644
index 4ba73ef007dd..000000000000
--- a/frontend/src/layout/navigation/ImpersonationNotice/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { ImpersonationNotice } from './ImpersonationNotice'
diff --git a/frontend/src/scenes/AuthenticatedShell.tsx b/frontend/src/scenes/AuthenticatedShell.tsx
index 5cb8d65aa6cb..c06f73798746 100644
--- a/frontend/src/scenes/AuthenticatedShell.tsx
+++ b/frontend/src/scenes/AuthenticatedShell.tsx
@@ -25,7 +25,7 @@ import { GlobalShortcuts } from '~/layout/GlobalShortcuts'
import { Navigation } from '~/layout/navigation-3000/Navigation'
import { themeLogic } from '~/layout/navigation-3000/themeLogic'
import { breadcrumbsLogic } from '~/layout/navigation/Breadcrumbs/breadcrumbsLogic'
-import { ImpersonationNotice } from '~/layout/navigation/ImpersonationNotice'
+import { ImpersonationNoticeSlot } from '~/layout/navigation/ImpersonationNotice/ImpersonationNoticeSlot'
import { webmcpLogic } from 'products/webmcp/frontend/logics/webmcpLogic'
@@ -132,7 +132,7 @@ export default function AuthenticatedShell({ children }: { children: React.React
</ChunkLoadErrorBoundary>
</ErrorBoundary>
)}
- <ImpersonationNotice />
+ <ImpersonationNoticeSlot />
<ErrorBoundary>
<ChunkLoadErrorBoundary>
<Suspense fallback={null}>{runSyncEnabled ? <WizardRunSyncFab /> : <WizardSyncFab />}</Suspense>
diff --git a/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.test.ts b/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.test.ts
index 360f7844f140..99b45708bc41 100644
--- a/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.test.ts
+++ b/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.test.ts
@@ -11,6 +11,7 @@ import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { userLogic } from 'scenes/userLogic'
+import { impersonationNoticeLogic } from '~/layout/navigation/ImpersonationNotice/impersonationNoticeLogic'
import { tagsModel } from '~/models/tagsModel'
import { initKeaTests } from '~/test/init'
import type { CommentType } from '~/types'
@@ -914,6 +915,30 @@ describe('supportTicketSceneLogic send outcome handling', () => {
})
})
+describe('supportTicketSceneLogic staff actions context', () => {
+ let logic: ReturnType<typeof supportTicketSceneLogic.build>
+
+ const ticketGetMock = api.conversationsTickets.get as jest.Mock
+
+ beforeEach(() => {
+ initKeaTests()
+ ticketGetMock.mockReset().mockResolvedValue(makeTicket())
+ })
+
+ afterEach(() => {
+ stopPolling(logic)
+ })
+
+ // The staff actions panel renders only after the ticket loads, so the scene must hold the shared logic open.
+ it('keeps the ticket context for staff actions when nothing else mounts the impersonation logic', async () => {
+ logic = supportTicketSceneLogic({ id: 42 })
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['setTicket', 'setTicketContext'])
+
+ expect(impersonationNoticeLogic.values.ticketContext).toMatchObject({ ticketId: 'ticket-1' })
+ })
+})
+
describe('supportTicketSceneLogic tag pool refresh', () => {
let logic: ReturnType<typeof supportTicketSceneLogic.build>
diff --git a/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.ts b/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.ts
index 149a4106f1ff..86bb828a041f 100644
--- a/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.ts
+++ b/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.ts
@@ -349,6 +349,9 @@ export interface supportTicketSceneLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface supportTicketSceneLogicActions {
+ setTicketContext: (context: ImpersonationTicketContext | null) => {
+ context: ImpersonationTicketContext | null
+ } // impersonationNoticeLogic
loadTickets: () => {
value: true
} // supportTicketsSceneLogic
@@ -632,7 +635,14 @@ export const supportTicketSceneLogic = kea<supportTicketSceneLogicType>([
props({ id: 'new' as string | number }),
key((props) => props.id),
connect(() => ({
- actions: [supportTicketsSceneLogic, ['loadTickets'], tagsModel, ['loadTags']],
+ actions: [
+ supportTicketsSceneLogic,
+ ['loadTickets'],
+ tagsModel,
+ ['loadTags'],
+ impersonationNoticeLogic,
+ ['setTicketContext'],
+ ],
values: [
teamLogic,
['currentTeam'],
@@ -1351,7 +1361,7 @@ export const supportTicketSceneLogic = kea<supportTicketSceneLogicType>([
actions.setTicket(ticket)
actions.loadMessages()
- impersonationNoticeLogic.findMounted()?.actions.setTicketContext(getImpersonationTicketContext(ticket))
+ actions.setTicketContext(getImpersonationTicketContext(ticket))
// Load session context data
actions.loadPerson()
@@ -1813,9 +1823,9 @@ export const supportTicketSceneLogic = kea<supportTicketSceneLogicType>([
actions.loadTicket()
}
}),
- beforeUnmount(() => {
+ beforeUnmount(({ actions }) => {
// The message poller is registered through cache.disposables, which the plugin tears down.
- impersonationNoticeLogic.findMounted()?.actions.setTicketContext(null)
+ actions.setTicketContext(null)
}),
beforeUnload(({ values, actions, cache }) => ({
enabled: (newLocation) => {