: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(insights): preserve #q= query hash on /insights/new url sync (#62263)
posthog[bot]eb3d818e9587
diff --git a/frontend/src/scenes/insights/insightSceneLogic.test.ts b/frontend/src/scenes/insights/insightSceneLogic.test.tsindex 39ce435c9c72..e02cca0abce6 100644--- a/frontend/src/scenes/insights/insightSceneLogic.test.ts+++ b/frontend/src/scenes/insights/insightSceneLogic.test.ts@@ -118,6 +118,29 @@ describe('insightSceneLogic', () => {await expectLogic(logic).toDispatchActions(['upgradeQuery']).toFinishAllListeners()})+ it('retains the #q= query hash after navigating to /insights/new (persons modal drill-down)', async () => {+ // Mirrors PersonsModal's "View events" / "Open as new insight" navigation: a DataTableNode+ // query encoded in the #q= hash must survive the post-load URL sync, otherwise both buttons+ // collapse onto the same default insight page.+ const dataTableQuery = {+ kind: NodeKind.DataTableNode,+ source: {+ kind: NodeKind.EventsQuery,+ select: ['*'],+ },+ }+ router.actions.push(urls.insightNew({ query: dataTableQuery as any }))+ logic = insightSceneLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ await expectLogic(router)+ .delay(1)+ .toMatchValues({+ hashParams: partial({ q: JSON.stringify(dataTableQuery) }),+ })+ })+it('persists edit mode in the url', async () => {logic = insightSceneLogic()logic.mount()diff --git a/frontend/src/scenes/insights/insightSceneLogic.tsx b/frontend/src/scenes/insights/insightSceneLogic.tsxindex 6fc14c230e19..c054b502f310 100644--- a/frontend/src/scenes/insights/insightSceneLogic.tsx+++ b/frontend/src/scenes/insights/insightSceneLogic.tsx@@ -610,7 +610,8 @@ export const insightSceneLogic = kea<insightSceneLogicType>([| [string, Record<string, any> | string | undefined, Record<string, any> | string | undefined]| undefined => {if (!insightId || insightId === 'new' || insightId.startsWith('new-')) {- return [urls.insightNew(), undefined, undefined]+ // Preserve search + hash (e.g. the `#q=` query) so post-load URL sync doesn't strip the drill-down query+ return [urls.insightNew(), window.location.search, window.location.hash]}const baseUrl = insightMode === ItemMode.View ? urls.insightView(insightId) : urls.insightEdit(insightId)