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.

fix(dashboards): prevent cross-tab url overwrite (#59039)

Adam Leithba53af3a2298
diff --git a/frontend/src/layout/navigation-3000/sidepanel/sidePanelStateLogic.tsx b/frontend/src/layout/navigation-3000/sidepanel/sidePanelStateLogic.tsx
index 50760976d17d..267c6681eca8 100644
--- a/frontend/src/layout/navigation-3000/sidepanel/sidePanelStateLogic.tsx
+++ b/frontend/src/layout/navigation-3000/sidepanel/sidePanelStateLogic.tsx
@@ -18,6 +18,18 @@ export const sidePanelStateLogic = kea<sidePanelStateLogicType>([
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(() => ({
@@ -32,6 +44,7 @@ export const sidePanelStateLogic = kea<sidePanelStateLogicType>([
{ persist: true },
{
openSidePanel: (_, { tab }) => tab,
+ restoreSidePanelStateForTab: (state, { open, selectedTab }) => (open ? selectedTab : state),
},
],
@@ -41,6 +54,7 @@ export const sidePanelStateLogic = kea<sidePanelStateLogicType>([
openSidePanel: (_, { options }) => options ?? null,
setSidePanelOptions: (_, { options }) => options ?? null,
closeSidePanel: () => null,
+ restoreSidePanelStateForTab: (_, { open, selectedTabOptions }) => (open ? selectedTabOptions : null),
},
],
sidePanelOpen: [
@@ -48,6 +62,7 @@ export const sidePanelStateLogic = kea<sidePanelStateLogicType>([
{ persist: true },
{
setSidePanelOpen: (_, { open }) => open,
+ restoreSidePanelStateForTab: (_, { open }) => open,
},
],
})),
@@ -93,14 +108,17 @@ export const sidePanelStateLogic = kea<sidePanelStateLogicType>([
}
// Restore state for the new tab (preserve current state for never-visited tabs
- // so the URL hash handler can set it if needed)
+ // 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) {
- if (savedState.open && savedState.selectedTab) {
- actions.openSidePanel(savedState.selectedTab, savedState.selectedTabOptions ?? undefined)
- } else {
- actions.closeSidePanel()
- }
+ actions.restoreSidePanelStateForTab(
+ !!(savedState.open && savedState.selectedTab),
+ savedState.selectedTab,
+ savedState.selectedTabOptions
+ )
}
},
})),