: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(navigation): stop AI side panel auto-opening on app return (#61883)
Adam Leith7b03575fe1f9
diff --git a/frontend/src/layout/navigation-3000/sidepanel/sidePanelStateLogic.test.ts b/frontend/src/layout/navigation-3000/sidepanel/sidePanelStateLogic.test.tsindex 44e24327d7d7..5d15d0ddbe8b 100644--- a/frontend/src/layout/navigation-3000/sidepanel/sidePanelStateLogic.test.ts+++ b/frontend/src/layout/navigation-3000/sidepanel/sidePanelStateLogic.test.ts@@ -7,7 +7,7 @@ import { SidePanelTab } from '~/types'import { sidePanelStateLogic } from './sidePanelStateLogic'-describe('sidePanelStateLogic - onSceneTabChanged', () => {+describe('sidePanelStateLogic', () => {let logic: ReturnType<typeof sidePanelStateLogic.build>beforeEach(() => {@@ -17,97 +17,39 @@ describe('sidePanelStateLogic - onSceneTabChanged', () => {logic.mount()})- it('does not crash when featureFlagLogic is not mounted', async () => {- featureFlagLogic.unmount()-- logic.actions.openSidePanel(SidePanelTab.Max)- logic.actions.onSceneTabChanged('tab-a', 'tab-b')-- await expectLogic(logic).toMatchValues({ sidePanelOpen: true, selectedTab: SidePanelTab.Max })+ it('starts closed', async () => {+ await expectLogic(logic).toMatchValues({ sidePanelOpen: false, selectedTab: null })})- it('saves and restores side panel state when switching between tabs', async () => {- // Open panel on tab-a+ it('opens only on an explicit openSidePanel trigger', async () => {logic.actions.openSidePanel(SidePanelTab.Max)await expectLogic(logic).toMatchValues({ sidePanelOpen: true, selectedTab: SidePanelTab.Max })-- // Switch to tab-b: saves tab-a state, tab-b has no saved state so panel stays as-is- logic.actions.onSceneTabChanged('tab-a', 'tab-b')- await expectLogic(logic).toMatchValues({ sidePanelOpen: true })-- // Close panel on tab-b- logic.actions.closeSidePanel()- await expectLogic(logic).toMatchValues({ sidePanelOpen: false })-- // Switch back to tab-a: restores open state- logic.actions.onSceneTabChanged('tab-b', 'tab-a')- await expectLogic(logic).toMatchValues({ sidePanelOpen: true, selectedTab: SidePanelTab.Max })- })-- it('restores closed state for tabs that were explicitly closed', async () => {- // Open panel on tab-a- logic.actions.openSidePanel(SidePanelTab.Max)-- // Switch to tab-b- logic.actions.onSceneTabChanged('tab-a', 'tab-b')-- // Close panel on tab-b, then switch to tab-c- logic.actions.closeSidePanel()- logic.actions.onSceneTabChanged('tab-b', 'tab-c')-- // Switch back to tab-b: should restore the closed state- logic.actions.onSceneTabChanged('tab-c', 'tab-b')- await expectLogic(logic).toMatchValues({ sidePanelOpen: false })})- it('preserves current state for never-visited tabs', async () => {- // Open panel- logic.actions.openSidePanel(SidePanelTab.Max)- await expectLogic(logic).toMatchValues({ sidePanelOpen: true })-- // Switch to a brand-new tab: no saved state, should preserve current panel state- logic.actions.onSceneTabChanged('tab-a', 'tab-new')- await expectLogic(logic).toMatchValues({ sidePanelOpen: true, selectedTab: SidePanelTab.Max })- })-- it('restores selectedTabOptions along with the tab', async () => {+ it('carries selectedTabOptions when opening', async () => {logic.actions.openSidePanel(SidePanelTab.Activity, 'bug:analytics')await expectLogic(logic).toMatchValues({sidePanelOpen: true,selectedTab: SidePanelTab.Activity,selectedTabOptions: 'bug:analytics',})+ })- // Switch away and back- logic.actions.onSceneTabChanged('tab-a', 'tab-b')+ it('closes when closeSidePanel is called with no tab', async () => {+ logic.actions.openSidePanel(SidePanelTab.Max)logic.actions.closeSidePanel()- logic.actions.onSceneTabChanged('tab-b', 'tab-a')-- await expectLogic(logic).toMatchValues({- sidePanelOpen: true,- selectedTab: SidePanelTab.Activity,- selectedTabOptions: 'bug:analytics',- })+ await expectLogic(logic).toMatchValues({ sidePanelOpen: false })})- it('deduplicates identical transitions from activateTab and setScene', async () => {+ it('only closes for the currently selected tab when a tab is passed', async () => {logic.actions.openSidePanel(SidePanelTab.Max)- // First dispatch (from activateTab): saves tab-a state, tab-b has no saved state- logic.actions.onSceneTabChanged('tab-a', 'tab-b')+ // Closing a different tab leaves the panel open+ logic.actions.closeSidePanel(SidePanelTab.Activity)await expectLogic(logic).toMatchValues({ sidePanelOpen: true })- // Close the panel on tab-b- logic.actions.closeSidePanel()+ // Closing the selected tab closes the panel+ logic.actions.closeSidePanel(SidePanelTab.Max)await expectLogic(logic).toMatchValues({ sidePanelOpen: false })-- // Second dispatch (from setScene) with same transition: should be skipped- // If it weren't skipped, it would overwrite tab-a's saved state with {open: false}- logic.actions.onSceneTabChanged('tab-a', 'tab-b')- await expectLogic(logic).toMatchValues({ sidePanelOpen: false })-- // Switch back to tab-a: should still have the original open state- logic.actions.onSceneTabChanged('tab-b', 'tab-a')- await expectLogic(logic).toMatchValues({ sidePanelOpen: true, selectedTab: SidePanelTab.Max })})})diff --git a/frontend/src/layout/navigation-3000/sidepanel/sidePanelStateLogic.tsx b/frontend/src/layout/navigation-3000/sidepanel/sidePanelStateLogic.tsxindex 267c6681eca8..20df423b775a 100644--- a/frontend/src/layout/navigation-3000/sidepanel/sidePanelStateLogic.tsx+++ b/frontend/src/layout/navigation-3000/sidepanel/sidePanelStateLogic.tsx@@ -17,19 +17,6 @@ export const sidePanelStateLogic = kea<sidePanelStateLogicType>([setSidePanelOpen: (open: boolean) => ({ open }),setSidePanelOptions: (options: string | null) => ({ options }),setSidePanelAvailable: (available: boolean) => ({ available }),- onSceneTabChanged: (previousTabId: string | null, newTabId: string) => ({ previousTabId, newTabId }),- // Restores side panel state for a scene tab without touching the URL. Unlike openSidePanel/- // closeSidePanel this has no actionToUrl, so it can't navigate the active tab to a stale- // location mid-tab-switch. The tab's own stored URL hash already carries `#panel=…`.- restoreSidePanelStateForTab: (- open: boolean,- selectedTab: SidePanelTab | null,- selectedTabOptions: string | null- ) => ({- open,- selectedTab,- selectedTabOptions,- }),}),reducers(() => ({@@ -44,7 +31,6 @@ export const sidePanelStateLogic = kea<sidePanelStateLogicType>([{ persist: true },{openSidePanel: (_, { tab }) => tab,- restoreSidePanelStateForTab: (state, { open, selectedTab }) => (open ? selectedTab : state),},],@@ -54,22 +40,21 @@ export const sidePanelStateLogic = kea<sidePanelStateLogicType>([openSidePanel: (_, { options }) => options ?? null,setSidePanelOptions: (_, { options }) => options ?? null,closeSidePanel: () => null,- restoreSidePanelStateForTab: (_, { open, selectedTabOptions }) => (open ? selectedTabOptions : null),},],+ // Not persisted: the panel must only open from an explicit trigger (click or URL #panel hash),+ // never auto-reopen on returning to the app.sidePanelOpen: [false,- { persist: true },{setSidePanelOpen: (_, { open }) => open,- restoreSidePanelStateForTab: (_, { open }) => open,},],})),windowValues(() => ({modalMode: (window: Window) => window?.innerWidth < 992, // Sync width threshold with Sass variable $lg!})),- listeners(({ actions, values, cache }) => ({+ listeners(({ actions, values }) => ({// NOTE: We explicitly reference the actions instead of connecting so that people don't accidentally// use this logic instead of sidePanelStateLogicopenSidePanel: ({ tab }) => {@@ -86,41 +71,6 @@ export const sidePanelStateLogic = kea<sidePanelStateLogicType>([actions.setSidePanelOpen(false)}},- onSceneTabChanged: ({ previousTabId, newTabId }) => {- // Skip if we already processed this exact transition (activateTab fires early, setScene fires later)- const transitionKey = `${previousTabId}->${newTabId}`- if (cache.lastProcessedTransition === transitionKey) {- return- }- cache.lastProcessedTransition = transitionKey-- if (!cache.sidePanelStateByTab) {- cache.sidePanelStateByTab = {}- }-- // Save current side panel state for the previous tab- if (previousTabId) {- cache.sidePanelStateByTab[previousTabId] = {- open: values.sidePanelOpen,- selectedTab: values.selectedTab,- selectedTabOptions: values.selectedTabOptions,- }- }-- // Restore state for the new tab (preserve current state for never-visited tabs- // so the URL hash handler can set it if needed). Use restoreSidePanelStateForTab- // rather than openSidePanel/closeSidePanel: those carry an actionToUrl that would- // replace() the active tab's URL using the stale (pre-switch) router location,- // overwriting the just-activated tab with the previous tab's pathname.- const savedState = cache.sidePanelStateByTab[newTabId]- if (savedState) {- actions.restoreSidePanelStateForTab(- !!(savedState.open && savedState.selectedTab),- savedState.selectedTab,- savedState.selectedTabOptions- )- }- },})),urlToAction(({ actions, values }) => ({diff --git a/frontend/src/scenes/sceneLogic.tsx b/frontend/src/scenes/sceneLogic.tsxindex adfdb762164b..d1f99abb45a7 100644--- a/frontend/src/scenes/sceneLogic.tsx+++ b/frontend/src/scenes/sceneLogic.tsx@@ -38,7 +38,6 @@ import {import { urls } from 'scenes/urls'import { isSharedView } from '~/exporter/exporterViewLogic'-import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'import { FileSystemIconType, ProductKey } from '~/queries/schema/schema-general'import { AccessControlLevel } from '~/types'@@ -840,11 +839,7 @@ export const sceneLogic = kea<sceneLogicType>([}},setTabs: () => persistTabs(values.tabs, values.homepage),- activateTab: ({ tab }, _, __, previousState) => {- const previousActiveTabId = selectors.activeTabId(previousState)- if (previousActiveTabId && previousActiveTabId !== tab.id) {- sidePanelStateLogic.findMounted()?.actions.onSceneTabChanged(previousActiveTabId, tab.id)- }+ activateTab: () => {persistTabs(values.tabs, values.homepage)},duplicateTab: () => persistTabs(values.tabs, values.homepage),@@ -1017,10 +1012,6 @@ export const sceneLogic = kea<sceneLogicType>([}if (tabId !== lastTabId) {- if (lastTabId) {- sidePanelStateLogic.findMounted()?.actions.onSceneTabChanged(lastTabId, tabId)- }-const scrollTop = values.tabScrollDepths[tabId] ?? 0window.setTimeout(() => restoreMainContentScrollTop(scrollTop, tabId), 1)window.setTimeout(() => restoreMainContentScrollTop(scrollTop, tabId), 10)