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): stop infinite update loop from unstable recents (#68608)

Thomas Obermüller5126c9aa09ba
diff --git a/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicLocalOverrides.ts b/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicLocalOverrides.ts
index 91ba941124bc..c2b172945589 100644
--- a/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicLocalOverrides.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicLocalOverrides.ts
@@ -10,7 +10,7 @@
* + `optionsFromProp` and report `0` for every logic-backed tab.
*/
import { useValues } from 'kea'
-import { useCallback } from 'react'
+import { useCallback, useMemo } from 'react'
import { recentTaxonomicFiltersLogic } from 'lib/components/TaxonomicFilter/recentTaxonomicFiltersLogic'
import { taxonomicFilterPinnedPropertiesLogic } from 'lib/components/TaxonomicFilter/taxonomicFilterPinnedPropertiesLogic'
@@ -45,18 +45,21 @@ export function useTaxonomicLocalOverrides(context: {
const { dataWarehouseTablesAndViews } = useValues(dataWarehouseSettingsSceneLogic)
const { columnsJoinedToPersons } = useValues(joinsLogic)
+ // Memoized so repeated calls return the same array reference — the result feeds
+ // `useGroupList` memo deps and `useEffect` deps (e.g. the sole-substantive-group
+ // recents promotion), where a fresh array per render means an infinite update loop.
+ const contextFilteredRecentItems = useMemo(
+ () => filterRecentsForContext(recentFilterItems, taxonomicGroupTypes, excludedOperators, selectingKeyOnly),
+ [recentFilterItems, taxonomicGroupTypes, excludedOperators, selectingKeyOnly]
+ )
+
return useCallback(
(groupType: TaxonomicFilterGroupType): TaxonomicDefinitionTypes[] | undefined => {
switch (groupType) {
case TaxonomicFilterGroupType.Actions:
return actionsSorted as unknown as TaxonomicDefinitionTypes[]
case TaxonomicFilterGroupType.RecentFilters:
- return filterRecentsForContext(
- recentFilterItems,
- taxonomicGroupTypes,
- excludedOperators,
- selectingKeyOnly
- )
+ return contextFilteredRecentItems
case TaxonomicFilterGroupType.PinnedFilters:
return pinnedFilterItems
case TaxonomicFilterGroupType.Dashboards:
@@ -73,15 +76,12 @@ export function useTaxonomicLocalOverrides(context: {
},
[
actionsSorted,
- recentFilterItems,
+ contextFilteredRecentItems,
pinnedFilterItems,
nameSortedDashboards,
experiments,
dataWarehouseTablesAndViews,
columnsJoinedToPersons,
- taxonomicGroupTypes,
- excludedOperators,
- selectingKeyOnly,
]
)
}
diff --git a/frontend/src/lib/lemon-ui/LemonTree/LemonTree.test.tsx b/frontend/src/lib/lemon-ui/LemonTree/LemonTree.test.tsx
index b15a028e6d5d..880abc1e96a8 100644
--- a/frontend/src/lib/lemon-ui/LemonTree/LemonTree.test.tsx
+++ b/frontend/src/lib/lemon-ui/LemonTree/LemonTree.test.tsx
@@ -1,6 +1,6 @@
import '@testing-library/jest-dom'
-import { act, render, screen, waitFor, within } from '@testing-library/react'
+import { act, cleanup, render, screen, waitFor, within } from '@testing-library/react'
import { createRef } from 'react'
import { LemonTree, LemonTreeRef, TreeDataItem } from './LemonTree'
@@ -41,6 +41,13 @@ describe('LemonTree virtualization', () => {
})
afterEach(() => {
+ // RTL's auto-cleanup is inert in this repo (jest.setup.ts imports @testing-library/react
+ // during the setupFiles phase, before afterEach exists, so its hook never registers).
+ // Without unmounting, each test leaves ~50 heavy rows mounted; every later waitFor's
+ // act() then re-flushes all accumulated trees, ballooning 500ms tests to 3s+ and past
+ // the per-test timeout on contended CI runners. Unmount while the synchronous rAF spy
+ // is still installed so unmount work can't schedule timers into the next test.
+ cleanup()
requestAnimationFrameSpy.mockRestore()
cancelAnimationFrameSpy.mockRestore()
})
@@ -199,7 +206,7 @@ describe('LemonTree virtualization', () => {
await waitFor(() => {
expect(within(container).getByLabelText('tree item: child-40')).toBeInTheDocument()
})
- }, 10000)
+ })
it('supports an overridden virtualized row height', async () => {
const data: TreeDataItem[] = [
@@ -224,7 +231,7 @@ describe('LemonTree virtualization', () => {
expect(within(container).getByLabelText('tree item: child-30')).toBeInTheDocument()
})
expect(within(container).queryByLabelText('tree item: child-0')).not.toBeInTheDocument()
- }, 10000)
+ })
it('supports an overridden virtualization overscan', async () => {
const data: TreeDataItem[] = [
@@ -255,5 +262,5 @@ describe('LemonTree virtualization', () => {
expect(within(container).getByLabelText('tree item: child-0')).toBeInTheDocument()
})
expect(within(container).queryByLabelText('tree item: child-1')).not.toBeInTheDocument()
- }, 10000)
+ })
})