: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
fix(support): open support form in side panel without modal flash (#63560)
Christiaan Hendriksen77fae5b1e67e
diff --git a/frontend/src/lib/components/Support/supportLogic.test.ts b/frontend/src/lib/components/Support/supportLogic.test.tsindex f427b73d6a27..7197bccba0f7 100644--- a/frontend/src/lib/components/Support/supportLogic.test.ts+++ b/frontend/src/lib/components/Support/supportLogic.test.ts@@ -1,34 +1,93 @@+import { expectLogic } from 'kea-test-utils'import posthog from 'posthog-js'-import { OrganizationBasicType, Region, TeamPublicType } from '~/types'+import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'+import { initKeaTests } from '~/test/init'+import { OrganizationBasicType, Region, SidePanelTab, TeamPublicType } from '~/types'-import { getPublicSupportSnippet } from './supportLogic'+import { getPublicSupportSnippet, supportLogic } from './supportLogic'+import * as SupportModal from './SupportModal'-describe('supportLogic snippet helpers', () => {- const mockedGetReplayUrl = posthog.get_session_replay_url as jest.Mock- const organization = { id: 'org-1', name: 'Test org' } as OrganizationBasicType- const team = { id: 42 } as TeamPublicType+// supportLogic and SupportModal import each other, so jest.mock('./SupportModal') leaves supportLogic+// bound to the real openSupportModal — spy on the live module export instead so the call is intercepted.+const openSupportModal = jest.spyOn(SupportModal, 'openSupportModal').mockImplementation(() => {})- beforeEach(() => {- mockedGetReplayUrl.mockReset()- })+describe('supportLogic', () => {+ describe('snippet helpers', () => {+ const mockedGetReplayUrl = posthog.get_session_replay_url as jest.Mock+ const organization = { id: 'org-1', name: 'Test org' } as OrganizationBasicType+ const team = { id: 42 } as TeamPublicType- it('rewrites the session line to the internal golink for staff triage', () => {- mockedGetReplayUrl.mockReturnValue(`${window.location.origin}/replay/abc?t=30`)- const snippet = getPublicSupportSnippet(Region.US, organization, team, false)- expect(snippet).toContain('Session: http://go/session/abc?t=30')- expect(snippet).not.toContain(`${window.location.origin}/replay/`)- })+ beforeEach(() => {+ mockedGetReplayUrl.mockReset()+ })++ it('rewrites the session line to the internal golink for staff triage', () => {+ mockedGetReplayUrl.mockReturnValue(`${window.location.origin}/replay/abc?t=30`)+ const snippet = getPublicSupportSnippet(Region.US, organization, team, false)+ expect(snippet).toContain('Session: http://go/session/abc?t=30')+ expect(snippet).not.toContain(`${window.location.origin}/replay/`)+ })- it('omits the session line when there is no recording', () => {- mockedGetReplayUrl.mockReturnValue(undefined)- const snippet = getPublicSupportSnippet(Region.US, organization, team, false)- expect(snippet).not.toContain('Session:')+ it('omits the session line when there is no recording', () => {+ mockedGetReplayUrl.mockReturnValue(undefined)+ const snippet = getPublicSupportSnippet(Region.US, organization, team, false)+ expect(snippet).not.toContain('Session:')+ })++ it('marks the admin line as internal', () => {+ mockedGetReplayUrl.mockReturnValue(undefined)+ const snippet = getPublicSupportSnippet(Region.US, organization, team, false)+ expect(snippet).toContain('Admin (internal): http://go/adminOrg')+ })})- it('marks the admin line as internal', () => {- mockedGetReplayUrl.mockReturnValue(undefined)- const snippet = getPublicSupportSnippet(Region.US, organization, team, false)- expect(snippet).toContain('Admin (internal): http://go/adminOrg')+ describe('openSupportForm modal vs side panel target', () => {+ let logic: ReturnType<typeof supportLogic.build>++ beforeEach(() => {+ // sidePanelStateLogic persists its selected tab and reflects open state in the URL hash;+ // initKeaTests resets neither, so clear them to keep the gating decision deterministic.+ localStorage.clear()+ window.history.replaceState(null, '', '/')+ initKeaTests()+ sidePanelStateLogic.mount()+ logic = supportLogic.build()+ logic.mount()+ openSupportModal.mockClear()+ })++ afterEach(() => {+ logic?.unmount()+ })++ it('opens the side panel when target is sidePanel', async () => {+ await expectLogic(logic, () => {+ logic.actions.openSupportForm({ kind: 'support', target_area: 'login', target: 'sidePanel' })+ }).toFinishAllListeners()++ expect(sidePanelStateLogic.values.sidePanelOpen).toBe(true)+ expect(sidePanelStateLogic.values.selectedTab).toBe(SidePanelTab.Support)+ expect(openSupportModal).not.toHaveBeenCalled()+ })++ it('opens the modal when target is modal', async () => {+ await expectLogic(logic, () => {+ logic.actions.openSupportForm({ kind: 'support', target_area: 'login', target: 'modal' })+ }).toFinishAllListeners()++ expect(sidePanelStateLogic.values.sidePanelOpen).toBe(false)+ expect(openSupportModal).toHaveBeenCalledTimes(1)+ })++ it('falls back to sidePanelAvailable when no target is given', async () => {+ sidePanelStateLogic.actions.setSidePanelAvailable(false)+ await expectLogic(logic, () => {+ logic.actions.openSupportForm({ kind: 'support', target_area: 'login' })+ }).toFinishAllListeners()++ expect(sidePanelStateLogic.values.sidePanelOpen).toBe(false)+ expect(openSupportModal).toHaveBeenCalledTimes(1)+ })})})diff --git a/frontend/src/lib/components/Support/supportLogic.ts b/frontend/src/lib/components/Support/supportLogic.tsindex ecdbd47906a6..61fbb012b102 100644--- a/frontend/src/lib/components/Support/supportLogic.ts+++ b/frontend/src/lib/components/Support/supportLogic.ts@@ -1,6 +1,5 @@import { actions, connect, kea, listeners, path, props, reducers, selectors } from 'kea'import { forms } from 'kea-forms'-import { urlToAction } from 'kea-router'import posthog from 'posthog-js'import { LemonSelectOptions } from '@posthog/lemon-ui'@@ -463,7 +462,7 @@ export const supportLogic = kea<supportLogicType>([})),actions(() => ({closeSupportForm: true,- openSupportForm: (values: Partial<SupportFormFields>) => values,+ openSupportForm: (values: Partial<SupportFormFields> & { target?: 'modal' | 'sidePanel' }) => values,submitZendeskTicket: (form: SupportFormFields) => form,ensureZendeskOrganization: true,updateUrlParams: true,@@ -559,7 +558,8 @@ export const supportLogic = kea<supportLogicType>([severity_level,message,exception_event,- }: Partial<SupportFormFields>) => {+ target,+ }: Partial<SupportFormFields> & { target?: 'modal' | 'sidePanel' }) => {let area = target_area ?? getURLPathToTargetArea(window.location.pathname)if (!userLogic.values.user) {area = 'login'@@ -581,7 +581,8 @@ export const supportLogic = kea<supportLogicType>([actions.closeEmailForm()}- if (values.sidePanelAvailable) {+ const useSidePanel = target ? target === 'sidePanel' : values.sidePanelAvailable+ if (useSidePanel) {const panelOptions = [kind ?? '', area ?? ''].join(':')actions.openSidePanel(SidePanelTab.Support, panelOptions === ':' ? undefined : panelOptions)} else {@@ -875,37 +876,4 @@ export const supportLogic = kea<supportLogicType>([}},})),-- urlToAction(({ actions, values }) => ({- '*': (_, _search, hashParams) => {- if (values.isSupportFormOpen) {- return- }-- const [panel, ...panelOptions] = (hashParams['panel'] ?? '').split(':')-- if (panel === SidePanelTab.Support) {- const [kind, area, severity, isEmailFormOpen] = panelOptions-- actions.openSupportForm({- kind: Object.keys(SUPPORT_KIND_TO_SUBJECT).includes(kind) ? kind : null,- target_area: getLabelBasedOnTargetArea(area) ? area : null,- severity_level: Object.keys(SEVERITY_LEVEL_TO_NAME).includes(severity) ? severity : null,- isEmailFormOpen: isEmailFormOpen ?? 'false',- })- return- }-- // Legacy supportModal param- if ('supportModal' in hashParams) {- const [kind, area, severity] = (hashParams['supportModal'] || '').split(':')-- actions.openSupportForm({- kind: Object.keys(SUPPORT_KIND_TO_SUBJECT).includes(kind) ? kind : null,- target_area: Object.keys(TARGET_AREA_TO_NAME).includes(area) ? area : null,- severity_level: Object.keys(SEVERITY_LEVEL_TO_NAME).includes(severity) ? severity : null,- })- }- },- })),])diff --git a/frontend/src/lib/components/Support/supportRouterLogic.ts b/frontend/src/lib/components/Support/supportRouterLogic.tsnew file mode 100644index 000000000000..183dcf18058e--- /dev/null+++ b/frontend/src/lib/components/Support/supportRouterLogic.ts@@ -0,0 +1,69 @@+import { kea, path } from 'kea'+import { urlToAction } from 'kea-router'++import { organizationLogic } from 'scenes/organizationLogic'+import { sceneLogic } from 'scenes/sceneLogic'++import { SidePanelTab } from '~/types'++import {+ getLabelBasedOnTargetArea,+ SEVERITY_LEVEL_TO_NAME,+ SUPPORT_KIND_TO_SUBJECT,+ supportLogic,+ TARGET_AREA_TO_NAME,+} from './supportLogic'+import type { supportRouterLogicType } from './supportRouterLogicType'++// Mirrors navigationLogic's `mode === 'full'` (the condition that mounts <SidePanel />), derived from+// sources supportLogic can't import without a billingLogic init cycle. Keep here, not in supportLogic.+function shouldUseSidePanel(searchParams: Record<string, any>): boolean {+ const zenFromUrl = searchParams?.zen !== undefined && searchParams.zen !== 'false' && searchParams.zen !== '0'+ if (zenFromUrl) {+ return false+ }+ if (organizationLogic.findMounted()?.values.isCurrentOrganizationUnavailable) {+ return false+ }+ return sceneLogic.findMounted()?.values.sceneConfig?.layout !== 'plain'+}++export const supportRouterLogic = kea<supportRouterLogicType>([+ path(['lib', 'components', 'support', 'supportRouterLogic']),+ urlToAction(() => ({+ '*': (_, searchParams, hashParams) => {+ if (supportLogic.findMounted()?.values.isSupportFormOpen) {+ return+ }++ const target = shouldUseSidePanel(searchParams) ? 'sidePanel' : 'modal'++ const [panel, ...panelOptions] = (hashParams['panel'] ?? '').split(':')++ if (panel === SidePanelTab.Support) {+ const [kind, area, severity, isEmailFormOpen] = panelOptions++ supportLogic.actions.openSupportForm({+ kind: Object.keys(SUPPORT_KIND_TO_SUBJECT).includes(kind) ? kind : null,+ target_area: getLabelBasedOnTargetArea(area) ? area : null,+ severity_level: Object.keys(SEVERITY_LEVEL_TO_NAME).includes(severity) ? severity : null,+ isEmailFormOpen: isEmailFormOpen ?? 'false',+ target,+ })+ return+ }++ // Legacy supportModal param+ if ('supportModal' in hashParams) {+ const [kind, area, severity] = (hashParams['supportModal'] || '').split(':')++ supportLogic.actions.openSupportForm({+ kind: Object.keys(SUPPORT_KIND_TO_SUBJECT).includes(kind) ? kind : null,+ target_area: Object.keys(TARGET_AREA_TO_NAME).includes(area) ? area : null,+ severity_level: Object.keys(SEVERITY_LEVEL_TO_NAME).includes(severity) ? severity : null,+ target,+ })+ }+ },+ })),+])diff --git a/frontend/src/scenes/App.tsx b/frontend/src/scenes/App.tsxindex 5d95e320e244..b66dad678ea8 100644--- a/frontend/src/scenes/App.tsx+++ b/frontend/src/scenes/App.tsx@@ -57,6 +57,17 @@ export function App(): JSX.Element | null {// (OAuth UI gated on preflight.is_debug); no timers/listeners, so cheap to always mount.useMountedLogic(oauthLogic)+ // Mount the support-hash router (handles #panel=support) on every page, lazily so it stays out+ // of App's import graph — a static import drags supportLogic/sceneLogic/organizationLogic into+ // root init and triggers a circular-import TDZ. Its urlToAction fires on the current URL on mount.+ useEffect(() => {+ let unmount: (() => void) | undefined+ void import('lib/components/Support/supportRouterLogic').then(({ supportRouterLogic }) => {+ unmount = supportRouterLogic.mount()+ })+ return () => unmount?.()+ }, [])+useThemedHtml()// A cloud OAuth redirect lands at /oauth/callback on the local origin. Render the exchange