: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(aio): stop the shared logic rewriting other scenes' URLs on mount (#98990)
Thomas Obermüller26814e225477
diff --git a/products/ai_observability/frontend/aiObservabilitySharedLogic.test.ts b/products/ai_observability/frontend/aiObservabilitySharedLogic.test.tsindex ce7ad9654d1c..9f4324037002 100644--- a/products/ai_observability/frontend/aiObservabilitySharedLogic.test.ts+++ b/products/ai_observability/frontend/aiObservabilitySharedLogic.test.ts@@ -1,7 +1,11 @@+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'++import { router } from 'kea-router'import { expectLogic } from 'kea-test-utils'import { runInThisContext } from 'node:vm'import { productSetupStatusLogic } from 'lib/components/ProductEmptyState/productSetupStatusLogic'+import { urls } from 'scenes/urls'import { ProductKey } from '~/queries/schema/schema-general'import { initKeaTests } from '~/test/init'@@ -106,6 +110,40 @@ describe('aiObservabilitySharedLogic', () => {})})+ // A DataTable `person` cell mounts this logic on any scene, so a URL write on mount lands there.+ describe('test-account default and the URL', () => {+ beforeEach(() => {+ jest.clearAllMocks()+ mockHasRecentAIEvents.mockResolvedValue(false)+ initKeaTests(true, { ...MOCK_DEFAULT_TEAM, test_account_filters_default_checked: true })+ })++ it("leaves another scene's URL alone when mounted there", async () => {+ const drillDown = { kind: 'DataTableNode', source: { kind: 'ActorsQuery', select: ['person'] } }+ router.actions.push(urls.insightNew({ query: drillDown as any }))+ const { pathname, search, hash } = router.values.location++ const logic = aiObservabilitySharedLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.shouldFilterTestAccounts).toBe(false)+ expect(router.values.location).toMatchObject({ pathname, search, hash })+ })++ it('applies the default on its own route without dropping the hash', async () => {+ router.actions.push(urls.aiObservabilityTraces(), {}, { panel: 'max' })++ const logic = aiObservabilitySharedLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.shouldFilterTestAccounts).toBe(true)+ expect(router.values.searchParams.filter_test_accounts).toBe(true)+ expect(router.values.hashParams.panel).toBe('max')+ })+ })+// Guards the connect + mapping into the app-wide setup-status layer: if either// breaks, the scene empty-state gate strands users on its spinner, or shows the// setup screen to teams that already have AI events.diff --git a/products/ai_observability/frontend/aiObservabilitySharedLogic.ts b/products/ai_observability/frontend/aiObservabilitySharedLogic.tsindex 33c218751b3f..4536f5e1827e 100644--- a/products/ai_observability/frontend/aiObservabilitySharedLogic.ts+++ b/products/ai_observability/frontend/aiObservabilitySharedLogic.ts@@ -597,9 +597,14 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([? date_to: INITIAL_DATE_TO: values.dateFilter.dateTo- const filterTestAccountsValue = [true, 'true', 1, '1'].includes(- filter_test_accounts as string | number | boolean- )+ // A DataTable `person` cell mounts this logic on whatever scene renders it, so the team+ // default is applied only once a route of this product matches. Applying it on mount would+ // write this product's params over that scene's URL and drop its `#q=` state.+ const filterTestAccountsValue =+ filter_test_accounts === undefined && !cache.enteredAIObservabilityRoute+ ? values.filterTestAccountsDefault+ : [true, 'true', 1, '1'].includes(filter_test_accounts as string | number | boolean)+ markAIObservabilityRouteEntered()const newSearchQuery = typeof trace_search === 'string' ? trace_search : ''const filtersChanged = !objectsEqual(parsedFilters, values.propertyFilters)@@ -631,11 +636,19 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([cleanParams[key] = value}}- router.actions.replace(router.values.location.pathname, cleanParams)+ router.actions.replace(router.values.location.pathname, cleanParams, router.values.hashParams)}}}+ function markAIObservabilityRouteEntered(): void {+ if (cache.enteredAIObservabilityRoute) {+ return+ }+ cache.enteredAIObservabilityRoute = true+ globalSetupLogic.findMounted()?.actions.markTaskAsCompleted(SetupTaskId.TrackCosts)+ }+function clearDashboardTimer(): void {clearTimeout(cache.dashboardDwellTimer)cache.dashboardDwellTimer = undefined@@ -750,6 +763,7 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([trace_search:(searchQuery ?? (router.values.searchParams.trace_search as string | undefined)) || undefined,},+ router.values.hashParams,],setPropertyFilters: ({ propertyFilters }) => [router.values.location.pathname,@@ -757,6 +771,7 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([...sharedSearchParams(),filters: propertyFilters.length > 0 ? propertyFilters : undefined,},+ router.values.hashParams,],setDates: ({ dateFrom, dateTo }) => [router.values.location.pathname,@@ -765,6 +780,7 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([date_from: dateFrom === INITIAL_EVENTS_DATE_FROM ? undefined : dateFrom || undefined,date_to: dateTo || undefined,},+ router.values.hashParams,],setDashboardDates: ({ dateFrom, dateTo }) => [router.values.location.pathname,@@ -773,6 +789,7 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([date_from: dateFrom ?? 'all',date_to: dateTo || undefined,},+ router.values.hashParams,],setShouldFilterTestAccounts: ({ shouldFilterTestAccounts }) => [router.values.location.pathname,@@ -780,6 +797,7 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([...sharedSearchParams(),filter_test_accounts: shouldFilterTestAccounts ? 'true' : undefined,},+ router.values.hashParams,],setSearchQuery: ({ searchQuery }) => [router.values.location.pathname,@@ -787,6 +805,7 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([...sharedSearchParams(),trace_search: searchQuery || undefined,},+ router.values.hashParams,],}}),@@ -822,12 +841,6 @@ export const aiObservabilitySharedLogic = kea<aiObservabilitySharedLogicType>([detectAIEventsIfProjectKnown()registerSetupPoll()- globalSetupLogic.findMounted()?.actions.markTaskAsCompleted(SetupTaskId.TrackCosts)-- const urlHasTestAccountsParam = 'filter_test_accounts' in router.values.searchParams- if (!urlHasTestAccountsParam && values.filterTestAccountsDefault !== values.shouldFilterTestAccounts) {- actions.setShouldFilterTestAccounts(values.filterTestAccountsDefault)- }}),beforeUnmount(({ cache }) => {