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 taxonomicGroups reference churn (react #185) (#68794)

posthog[bot]f43dbc2f6d07
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts
index 4614bda7756b..8e1df9cc0aad 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts
@@ -1,5 +1,6 @@
import { MOCK_TEAM_ID } from 'lib/api.mock'
+import { getContext } from 'kea'
import { expectLogic } from 'kea-test-utils'
import posthog from 'posthog-js'
@@ -17,6 +18,7 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { useMocks } from '~/mocks/jest'
import { actionsModel } from '~/models/actionsModel'
import { groupsModel } from '~/models/groupsModel'
+import { NodeKind } from '~/queries/schema/schema-general'
import { CORE_FILTER_DEFINITIONS_BY_GROUP } from '~/taxonomy/taxonomy'
import { initKeaTests } from '~/test/init'
import { mockEventDefinitions, mockSessionPropertyDefinitions } from '~/test/mocks'
@@ -212,6 +214,25 @@ describe('taxonomicFilterLogic', () => {
captureSpy.mockRestore()
})
+ it('taxonomicGroups keeps a stable reference across equal-but-freshly-allocated object props', () => {
+ // A parent re-render that passes an inline object literal (e.g. metadataSource={{ ... }}) hands
+ // the logic a new-but-deep-equal prop on every tick. Without resultEqualityCheck on the
+ // prop-derived selectors, taxonomicGroups recomputes and mints fresh group objects each time,
+ // cascading through the infinite list (group -> rawLocalItems -> ... -> selectedItem) and handing
+ // react-window new rowProps every render, which drives its layout-effect setState past React's
+ // update limit (error #185). This locks the reference in so that cascade cannot start.
+ const state = getContext().store.getState()
+ const propsA = { ...logic.props, metadataSource: { kind: NodeKind.HogQLQuery, query: 'select 1' } }
+ const propsB = { ...logic.props, metadataSource: { kind: NodeKind.HogQLQuery, query: 'select 1' } }
+
+ expect(propsA.metadataSource).not.toBe(propsB.metadataSource)
+
+ const groupsA = logic.selectors.taxonomicGroups(state, propsA)
+ const groupsB = logic.selectors.taxonomicGroups(state, propsB)
+
+ expect(groupsB).toBe(groupsA)
+ })
+
it('tabs skip groups with no results', async () => {
await expectLogic(logic).toDispatchActions(['infiniteListResultsReceived']).delay(1).clearHistory()
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
index 7f4e2dd6bd9d..1455908f3d7e 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
@@ -477,7 +477,18 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
(_, p) => [p.taxonomicFilterLogicKey],
(taxonomicFilterLogicKey) => taxonomicFilterLogicKey,
],
- eventNames: [() => [(_, props) => props.eventNames], (eventNames) => eventNames ?? []],
+ // Prop-derived reference selectors below carry `resultEqualityCheck: objectsEqual` so that a
+ // consumer passing an equal-but-freshly-allocated object/array prop on every render does not
+ // churn the selector's output reference. Without this, taxonomicGroups (which depends on them)
+ // recomputes on every render, minting new group objects and inline option arrays that cascade
+ // through group → rawLocalItems → fuse → localItems → items → selectedItem, and hand react-window
+ // new rowProps on every tick — driving its layout-effect setState past React's update limit
+ // (error #185). Deep-equal costs less than a full taxonomicGroups rebuild plus that cascade.
+ eventNames: [
+ () => [(_, props) => props.eventNames],
+ (eventNames) => eventNames ?? [],
+ { resultEqualityCheck: objectsEqual },
+ ],
// Combined selector that returns both event names and the distinct primary properties
// for those events. Combined into a single selector so taxonomicGroups stays under
// kea's 16-dep tuple type limit; consumers destructure both fields.
@@ -502,15 +513,22 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
primaryPropertiesForContextEvents: Array.from(distinct),
}
},
+ { resultEqualityCheck: objectsEqual },
+ ],
+ schemaColumns: [
+ () => [(_, props) => props.schemaColumns],
+ (schemaColumns) => schemaColumns ?? [],
+ { resultEqualityCheck: objectsEqual },
],
- schemaColumns: [() => [(_, props) => props.schemaColumns], (schemaColumns) => schemaColumns ?? []],
maxContextOptions: [
() => [(_, props) => props.maxContextOptions],
(maxContextOptions) => maxContextOptions ?? [],
+ { resultEqualityCheck: objectsEqual },
],
dataWarehousePopoverFields: [
() => [(_, props) => props.dataWarehousePopoverFields],
(dataWarehousePopoverFields) => dataWarehousePopoverFields ?? [],
+ { resultEqualityCheck: objectsEqual },
],
suggestedFiltersLabel: [
() => [(_, props) => props.suggestedFiltersLabel],
@@ -520,22 +538,27 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
() => [(_, props) => props.metadataSource],
(metadataSource): AnyDataNode =>
metadataSource ?? { kind: NodeKind.HogQLQuery, query: 'select event from events' },
+ { resultEqualityCheck: objectsEqual },
],
excludedProperties: [
() => [(_, props) => props.excludedProperties],
(excludedProperties) => (excludedProperties ?? {}) as ExcludedProperties,
+ { resultEqualityCheck: objectsEqual },
],
selectedProperties: [
() => [(_, props) => props.selectedProperties],
(selectedProperties) => (selectedProperties ?? {}) as SelectedProperties,
+ { resultEqualityCheck: objectsEqual },
],
propertyAllowList: [
() => [(_, props) => props.propertyAllowList],
(propertyAllowList) => propertyAllowList as TaxonomicFilterLogicProps['propertyAllowList'],
+ { resultEqualityCheck: objectsEqual },
],
propertyFilters: [
(s) => [s.excludedProperties, s.propertyAllowList],
(excludedProperties, propertyAllowList) => ({ excludedProperties, propertyAllowList }),
+ { resultEqualityCheck: objectsEqual },
],
allowNonCapturedEvents: [
() => [(_, props) => props.allowNonCapturedEvents],
@@ -554,10 +577,12 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
globals: hogQLGlobals,
showBreakdownLabelHint: showBreakdownLabelHint ?? false,
}),
+ { resultEqualityCheck: objectsEqual },
],
endpointFilters: [
() => [(_, props) => props.endpointFilters],
(endpointFilters: Record<string, any>) => endpointFilters,
+ { resultEqualityCheck: objectsEqual },
],
// Combined selector so taxonomicGroups stays under kea's 16-dep tuple type limit.
metadataPropertyDefinitionsByType: [
@@ -566,6 +591,7 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
event: PropertyDefinition[],
person: PropertyDefinition[]
): { event: PropertyDefinition[]; person: PropertyDefinition[] } => ({ event, person }),
+ { resultEqualityCheck: objectsEqual },
],
taxonomicGroups: [
(s) => [
@@ -1649,6 +1675,7 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
return filtered
},
+ { resultEqualityCheck: objectsEqual },
],
groupAnalyticsTaxonomicGroupNames: [
(s) => [s.groupTypes, s.currentTeamId, s.aggregationLabel],