: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(taxonomic-filter): reload stale tab on category switch (#68631)
posthog[bot]e9caaeddbbd7
diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.tsindex 84ceb5a84053..1b03284240e7 100644--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts@@ -448,6 +448,87 @@ describe('infiniteListLogic', () => {})})+ describe('switching tabs reconciles a stale remote list', () => {+ let staleLogic: ReturnType<typeof infiniteListLogic.build>+ let surveyRequestCount: number++ beforeEach(() => {+ surveyRequestCount = 0+ useMocks({+ get: {+ '/api/projects/:team/event_definitions': ({ request }) => {+ const url = new URL(request.url)+ const search = url.searchParams.get('search') ?? ''+ if (search === 'survey') {+ surveyRequestCount += 1+ // First fetch is cut short (a transient client-side failure stands in for+ // an in-flight debounced load a tab switch cancels). The event exists.+ if (surveyRequestCount === 1) {+ return [500, { detail: 'transient error' }]+ }+ const results = [{ ...mockEventDefinitions[0], name: 'Survey Responded' }]+ return [200, { results, count: results.length }]+ }+ const results = mockEventDefinitions.filter((e) => e.name.includes(search))+ return [200, { results, count: results.length }]+ },+ },+ })+ initKeaTests()+ clearApiCache()+ staleLogic = infiniteListLogic({+ taxonomicFilterLogicKey: 'staleTabList',+ listGroupType: TaxonomicFilterGroupType.Events,+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.Actions],+ showNumericalPropsOnly: false,+ })+ staleLogic.mount()+ })++ it('re-fetches the current query when the cached remote results are stale for it', async () => {+ await expectLogic(staleLogic).toDispatchActions(['loadRemoteItemsSuccess']) // initial empty-query load++ // The search is cut short, leaving the tab on its stale empty-query results even+ // though "Survey Responded" exists for this term.+ await expectLogic(staleLogic, () => {+ staleLogic.actions.setSearchQuery('survey')+ })+ .toDispatchActions(['setSearchQuery', 'loadRemoteItems', 'loadRemoteItemsFailure'])+ .toFinishAllListeners()+ expect(staleLogic.values.remoteItems.searchQuery).not.toBe('survey')++ // Switching category tabs must reconcile the stale tab against the active query rather+ // than leaving it on a false "No results".+ await expectLogic(staleLogic, () => {+ staleLogic.actions.setActiveTab(TaxonomicFilterGroupType.Actions)+ })+ .toDispatchActions(['loadRemoteItems', 'loadRemoteItemsSuccess'])+ .toMatchValues({+ remoteItems: partial({+ searchQuery: 'survey',+ results: partial([partial({ name: 'Survey Responded' })]),+ }),+ })+ })++ it('does not re-fetch when the tab is already fresh for the current query', async () => {+ await expectLogic(staleLogic, () => {+ staleLogic.actions.setSearchQuery('event')+ })+ .toDispatchActions(['setSearchQuery', 'loadRemoteItems', 'loadRemoteItemsSuccess'])+ .toFinishAllListeners()+ .toMatchValues({ remoteItems: partial({ searchQuery: 'event' }) })++ // The cached remote query already matches, so a tab switch must not trigger a+ // redundant reload.+ await expectLogic(staleLogic, () => {+ staleLogic.actions.setActiveTab(TaxonomicFilterGroupType.Actions)+ })+ .toDispatchActions(['setActiveTab'])+ .toNotHaveDispatchedActions(['loadRemoteItems'])+ })+ })+describe('remote fetch failure settles the list', () => {it('falls back to the empty state instead of spinning forever when the fetch fails', async () => {useMocks({diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.tsindex a2719034bd63..1d46b55b9186 100644--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts@@ -1223,6 +1223,21 @@ export const infiniteListLogic = kea<infiniteListLogicType>([cache.lastActiveTab = activeTabactions.resetPinnedRowState()actions.reconcilePinnedRowState()++ // A tab switch can cut short this list's in-flight (debounced) remote search before+ // it lands, leaving the cached results stale for the current query. Nothing else+ // re-fires the load, so the stale list surfaces as a false "No results" until a later+ // render or re-type. Reconcile here: if the cached remote query no longer matches the+ // active search, re-dispatch so switching to (or back to) a tab always reloads against+ // the current query. Skip when a load is already in flight — it reads the current+ // query at fetch time and settles correctly on its own.+ if (+ values.hasRemoteDataSource &&+ !values.remoteItemsLoading &&+ (values.remoteItems.searchQuery ?? '') !== values.searchQuery+ ) {+ actions.loadRemoteItems({ offset: 0, limit: values.limit })+ }},setSearchQuery: async () => {const searchQueryChanged = cache.lastSearchQuery !== values.searchQuery