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(taxonomic-filter): capture first-load fetch failures and clear cache (#99715)

Paul D'Ambra1f3bffdebaa0
diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
index 1fbc7c37be16..7d550fbe4095 100644
--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
@@ -529,6 +529,49 @@ describe('infiniteListLogic', () => {
})
})
+ describe('unmounting clears the shared api cache', () => {
+ it('does not keep serving a cached response after the list unmounts', async () => {
+ let requestCount = 0
+ useMocks({
+ get: {
+ '/api/projects/:team/event_definitions': ({ request }) => {
+ const url = new URL(request.url)
+ if (url.searchParams.get('search') === 'cached_event') {
+ requestCount += 1
+ }
+ return [200, { results: [{ ...mockEventDefinitions[0], name: 'cached_event' }], count: 1 }]
+ },
+ },
+ })
+ initKeaTests()
+ const firstLogic = infiniteListLogic({
+ taxonomicFilterLogicKey: 'cacheList',
+ listGroupType: TaxonomicFilterGroupType.Events,
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events],
+ showNumericalPropsOnly: false,
+ })
+ firstLogic.mount()
+ await expectLogic(firstLogic, () => {
+ firstLogic.actions.setSearchQuery('cached_event')
+ }).toDispatchActions(['loadRemoteItemsSuccess'])
+ expect(requestCount).toBe(1)
+
+ firstLogic.unmount()
+
+ const secondLogic = infiniteListLogic({
+ taxonomicFilterLogicKey: 'cacheList2',
+ listGroupType: TaxonomicFilterGroupType.Events,
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events],
+ showNumericalPropsOnly: false,
+ })
+ secondLogic.mount()
+ await expectLogic(secondLogic, () => {
+ secondLogic.actions.setSearchQuery('cached_event')
+ }).toDispatchActions(['loadRemoteItemsSuccess'])
+ expect(requestCount).toBe(2)
+ })
+ })
+
describe('switching tabs reconciles a stale remote list', () => {
let staleLogic: ReturnType<typeof infiniteListLogic.build>
let surveyRequestCount: number
@@ -655,6 +698,82 @@ describe('infiniteListLogic', () => {
})
})
+ it('captures a fetch failure on the initial empty-query load too', async () => {
+ useMocks({
+ get: {
+ '/api/projects/:team/event_definitions': () => [500, { detail: 'server error' }],
+ },
+ })
+ initKeaTests()
+ const captureSpy = jest.spyOn(posthog, 'capture')
+ const failingLogic = infiniteListLogic({
+ taxonomicFilterLogicKey: 'failingEmptyList',
+ listGroupType: TaxonomicFilterGroupType.Events,
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events],
+ showNumericalPropsOnly: false,
+ })
+ failingLogic.mount()
+ // `showErrorState` is not asserted: with an empty query the picker can fall back to a
+ // recent or pinned row, so a failed fetch does not always show as an error in the UI.
+ await expectLogic(failingLogic)
+ .toDispatchActions(['loadRemoteItems', 'loadRemoteItemsFailure'])
+ .toFinishAllListeners()
+
+ const failedCalls = captureSpy.mock.calls.filter((c) => c[0] === 'taxonomic filter fetch failed')
+ expect(failedCalls).toHaveLength(1)
+ expect(failedCalls[0][1]).toMatchObject({
+ groupType: TaxonomicFilterGroupType.Events,
+ searchQuery: '',
+ })
+ })
+
+ it('captures a fetch failure from a list that feeds the open "All" tab', async () => {
+ useMocks({
+ get: {
+ '/api/projects/:team/event_definitions': () => [500, { detail: 'server error' }],
+ },
+ })
+ initKeaTests()
+ const captureSpy = jest.spyOn(posthog, 'capture')
+ // The shape of every property filter picker: an aggregate "All" tab in front of the
+ // groups it aggregates. No list is the active tab when the picker opens.
+ const groupTypes = [
+ TaxonomicFilterGroupType.Events,
+ TaxonomicFilterGroupType.EventProperties,
+ TaxonomicFilterGroupType.SuggestedFilters,
+ ]
+ const filterLogic = taxonomicFilterLogic({
+ taxonomicFilterLogicKey: 'allTabFailure',
+ taxonomicGroupTypes: groupTypes,
+ })
+ filterLogic.mount()
+ let eventsList!: ReturnType<typeof infiniteListLogic.build>
+ for (const groupType of groupTypes) {
+ const listLogic = infiniteListLogic({
+ taxonomicFilterLogicKey: 'allTabFailure',
+ listGroupType: groupType,
+ taxonomicGroupTypes: groupTypes,
+ showNumericalPropsOnly: false,
+ })
+ listLogic.mount()
+ if (groupType === TaxonomicFilterGroupType.Events) {
+ eventsList = listLogic
+ }
+ }
+ expect(filterLogic.values.activeTab).toBe(TaxonomicFilterGroupType.SuggestedFilters)
+
+ await expectLogic(eventsList)
+ .toDispatchActions(['loadRemoteItems', 'loadRemoteItemsFailure'])
+ .toFinishAllListeners()
+
+ const failedCalls = captureSpy.mock.calls.filter((c) => c[0] === 'taxonomic filter fetch failed')
+ expect(failedCalls).toHaveLength(1)
+ expect(failedCalls[0][1]).toMatchObject({
+ groupType: TaxonomicFilterGroupType.Events,
+ searchQuery: '',
+ })
+ })
+
// Group names go out over the query endpoint instead of the list endpoint, so they need
// the abort signal wired separately - without it the watchdog fires against a controller
// nobody is listening to and the list keeps spinning.
diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
index ddbe69e3081c..4e0494366b65 100644
--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
@@ -285,6 +285,7 @@ export interface infiniteListLogicValues {
searchQuery: string
} | null
expandedCountResultLoading: boolean
+ feedsActiveTab: boolean
fuse: ListFuse
group: TaxonomicFilterGroup | undefined
hasAppliedInitialPin: boolean
@@ -549,6 +550,11 @@ export interface infiniteListLogicMeta {
isSuggestedFilters: (listGroupType: TaxonomicFilterGroupType) => boolean
trimmedSearchQuery: (searchQuery: string) => string
isActiveTab: (listGroupType: TaxonomicFilterGroupType, activeTab: TaxonomicFilterGroupType) => boolean
+ feedsActiveTab: (
+ isActiveTab: boolean,
+ activeTab: TaxonomicFilterGroupType,
+ listGroupType: TaxonomicFilterGroupType
+ ) => boolean
excludedPropertiesWithHiddenEvents: (
arg: import('lib/components/TaxonomicFilter/types').TaxonomicFilterGroupValueMap | undefined,
featureFlags: FeatureFlagsSet,
@@ -1135,6 +1141,20 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
(listGroupType: TaxonomicFilterGroupType, activeTab: TaxonomicFilterGroupType): boolean =>
listGroupType === activeTab,
],
+ // This list reaches the surface the user is looking at. Being the active tab is one way;
+ // the other is the aggregated "All" tab, which runs no fetch of its own and shows the
+ // substantive groups' results instead. Every property filter picker opens on "All", so a
+ // check for the active tab alone never sees a list there.
+ feedsActiveTab: [
+ (s) => [s.isActiveTab, s.activeTab, s.listGroupType],
+ (
+ isActiveTab: boolean,
+ activeTab: TaxonomicFilterGroupType,
+ listGroupType: TaxonomicFilterGroupType
+ ): boolean =>
+ isActiveTab ||
+ (activeTab === TaxonomicFilterGroupType.SuggestedFilters && !META_GROUP_TYPES.has(listGroupType)),
+ ],
// The Recent and Pinned tabs filter against the caller's record, so the names the Events
// group hides from its own option list have to be folded in for them to drop too.
excludedPropertiesWithHiddenEvents: [
@@ -2278,13 +2298,15 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
remoteItemsFetchFailedForQuery: ({ searchQuery }) => {
// Failures land on the same empty state as genuine no-matches, so without this
// capture the "event exists but the backend blipped" case is invisible in prod.
- // Only count failures the user can actually see: the current query (a stale
- // out-of-order failure is rejected by `remoteResultsAreFresh` and never renders),
- // a real typed search (mount loads with an empty query are a different signal),
- // and the active tab — every list runs the search in parallel, and background-tab
- // failures the user never sees would inflate the metric.
+ // The empty-query load that runs when the picker opens counts too: it hits the same
+ // endpoint and fails just as often on a large project. Only count failures that reach
+ // the user: the current query (a stale out-of-order failure is rejected by
+ // `remoteResultsAreFresh` and never renders) and a list the open tab shows, because
+ // every list runs the search in parallel and background failures would inflate the
+ // metric. `feedsActiveTab` covers the aggregated "All" tab as well as this list's own,
+ // so a picker that opens on "All" still reports its first-load failures.
const trimmedQuery = searchQuery.trim()
- if (!values.isActiveTab || searchQuery !== values.searchQuery || trimmedQuery.length === 0) {
+ if (!values.feedsActiveTab || searchQuery !== values.searchQuery) {
return
}
const dedupeKey = `${props.listGroupType}::${trimmedQuery}`
@@ -2363,14 +2385,9 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
actions.reconcilePinnedRowState()
- // Clean up all cache timers to prevent memory leaks
- cache.disposables.add(() => {
- return () => {
- Object.values(apiCacheTimers).forEach((timerId) => {
- window.clearTimeout(timerId)
- })
- }
- }, 'apiCacheTimersCleanup')
+ // Clean up all cache timers to prevent memory leaks. Clearing only the timers would
+ // leave each `apiCache` entry with no expiry, so it would be served stale until reload.
+ cache.disposables.add(() => clearApiCache, 'apiCacheTimersCleanup')
},
})),