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.

perf(cohorts): keep the cohort field components off the shell path (#126236)

Paul D'Ambradd54edb71aae
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjs
index 87cb3180dd97..5ee6869e602e 100644
--- a/frontend/bin/check-eager-graph.mjs
+++ b/frontend/bin/check-eager-graph.mjs
@@ -102,8 +102,8 @@ const ROOTS = [
{
root: AUTHENTICATED_SHELL,
label: 'authenticated shell (every logged-in page)',
- // 2026-10-29: 7.08 MiB eager output, stable CSS included. ~0.3% headroom.
- budgetBytes: 7_450_000,
+ // 2026-10-30: 6.75 MiB eager output, stable CSS included. ~0.3% headroom.
+ budgetBytes: 7_100_000,
forbidden: [
'node_modules/monaco-editor/',
'src/lib/components/ActivityLog/describers',
@@ -166,7 +166,8 @@ const ROOTS = [
'src/scenes/project-homepage/today/TodayHome.tsx',
],
label: 'today home path',
- budgetBytes: 7_700_000,
+ // 2026-10-30: 6.94 MiB, stable CSS included. ~0.3% headroom.
+ budgetBytes: 7_300_000,
forbidden: [
'src/scenes/project-homepage/ai-first/AiFirstHomepage.tsx',
'src/scenes/project-homepage/today/TodayReportPage.tsx',
@@ -183,8 +184,8 @@ const ROOTS = [
'src/scenes/project-homepage/ai-first/AiFirstHomepage.tsx',
],
label: 'AI-first home path',
- // 2026-10-29: 7.51 MiB, stable CSS included. ~1% headroom.
- budgetBytes: 7_950_000,
+ // 2026-10-30: 7.46 MiB, stable CSS included. ~1% headroom.
+ budgetBytes: 7_900_000,
forbidden: [
'products/posthog_ai/frontend/components/tool/widgets/VisualizationWidget.tsx',
'products/posthog_ai/frontend/components/tool/widgets/RecordingsWidget.tsx',
diff --git a/frontend/src/lib/components/PropertyFilters/components/PropertyFiltersDisplay.tsx b/frontend/src/lib/components/PropertyFilters/components/PropertyFiltersDisplay.tsx
index 37962b23d7ea..04ce26fff140 100644
--- a/frontend/src/lib/components/PropertyFilters/components/PropertyFiltersDisplay.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/PropertyFiltersDisplay.tsx
@@ -10,7 +10,7 @@ const PropertyFiltersDisplay = ({
compact?: boolean
}): JSX.Element => {
return (
- <div className="PropertyFilters flex-wrap">
+ <div className="PropertyFilters flex flex-wrap gap-2">
{filters &&
filters.map((item) => {
return <PropertyFilterButton key={item.key} item={item} compact={compact} />
diff --git a/frontend/src/scenes/cohorts/CohortFilters/CohortCriteriaRowBuilder.tsx b/frontend/src/scenes/cohorts/CohortFilters/CohortCriteriaRowBuilder.tsx
index 9c05411e27bc..b01291fec98c 100644
--- a/frontend/src/scenes/cohorts/CohortFilters/CohortCriteriaRowBuilder.tsx
+++ b/frontend/src/scenes/cohorts/CohortFilters/CohortCriteriaRowBuilder.tsx
@@ -15,7 +15,8 @@ import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { getFeatureFlagPayload } from 'lib/logic/featureFlagLogic'
import { CohortLogicProps, cohortEditLogic } from 'scenes/cohorts/cohortEditLogic'
-import { getRowShape, renderField } from 'scenes/cohorts/CohortFilters/constants'
+import { getRowShape } from 'scenes/cohorts/CohortFilters/constants'
+import { renderField } from 'scenes/cohorts/CohortFilters/renderField'
import { BehavioralFilterType, CohortFieldProps, Field, FilterType } from 'scenes/cohorts/CohortFilters/types'
import { cleanCriteria } from 'scenes/cohorts/cohortUtils'
import { teamLogic } from 'scenes/teamLogic'
diff --git a/frontend/src/scenes/cohorts/CohortFilters/CohortNumberField.stories.tsx b/frontend/src/scenes/cohorts/CohortFilters/CohortNumberField.stories.tsx
index 2cffbfaec17f..54cc9dfb7544 100644
--- a/frontend/src/scenes/cohorts/CohortFilters/CohortNumberField.stories.tsx
+++ b/frontend/src/scenes/cohorts/CohortFilters/CohortNumberField.stories.tsx
@@ -3,7 +3,7 @@ import { useMountedLogic } from 'kea'
import { useState } from 'react'
import { cohortEditLogic } from 'scenes/cohorts/cohortEditLogic'
-import { renderField } from 'scenes/cohorts/CohortFilters/constants'
+import { renderField } from 'scenes/cohorts/CohortFilters/renderField'
import { CohortNumberFieldProps, FilterType } from 'scenes/cohorts/CohortFilters/types'
import { CohortNumberField } from './CohortField'
diff --git a/frontend/src/scenes/cohorts/CohortFilters/CohortPersonPropertiesValuesField.stories.tsx b/frontend/src/scenes/cohorts/CohortFilters/CohortPersonPropertiesValuesField.stories.tsx
index e0ef4c893745..82615f9c548e 100644
--- a/frontend/src/scenes/cohorts/CohortFilters/CohortPersonPropertiesValuesField.stories.tsx
+++ b/frontend/src/scenes/cohorts/CohortFilters/CohortPersonPropertiesValuesField.stories.tsx
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react'
import { useState } from 'react'
-import { renderField } from 'scenes/cohorts/CohortFilters/constants'
+import { renderField } from 'scenes/cohorts/CohortFilters/renderField'
import { CohortPersonPropertiesValuesFieldProps, FilterType } from 'scenes/cohorts/CohortFilters/types'
import { PropertyOperator } from '~/types'
diff --git a/frontend/src/scenes/cohorts/CohortFilters/CohortTaxonomicField.stories.tsx b/frontend/src/scenes/cohorts/CohortFilters/CohortTaxonomicField.stories.tsx
index d8383d7d409d..c012f6634e93 100644
--- a/frontend/src/scenes/cohorts/CohortFilters/CohortTaxonomicField.stories.tsx
+++ b/frontend/src/scenes/cohorts/CohortFilters/CohortTaxonomicField.stories.tsx
@@ -4,7 +4,7 @@ import { useState } from 'react'
import { taxonomicFilterMocksDecorator } from 'lib/components/TaxonomicFilter/__mocks__/taxonomicFilterMocksDecorator'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
-import { renderField } from 'scenes/cohorts/CohortFilters/constants'
+import { renderField } from 'scenes/cohorts/CohortFilters/renderField'
import { CohortTaxonomicFieldProps, FilterType } from 'scenes/cohorts/CohortFilters/types'
import { actionsModel } from '~/models/actionsModel'
diff --git a/frontend/src/scenes/cohorts/CohortFilters/CohortTextField.stories.tsx b/frontend/src/scenes/cohorts/CohortFilters/CohortTextField.stories.tsx
index 2eb39de72bf6..7df9460230a4 100644
--- a/frontend/src/scenes/cohorts/CohortFilters/CohortTextField.stories.tsx
+++ b/frontend/src/scenes/cohorts/CohortFilters/CohortTextField.stories.tsx
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from '@storybook/react'
-import { renderField } from 'scenes/cohorts/CohortFilters/constants'
+import { renderField } from 'scenes/cohorts/CohortFilters/renderField'
import { CohortTextFieldProps, FilterType } from 'scenes/cohorts/CohortFilters/types'
import { CohortTextField } from './CohortField'
diff --git a/frontend/src/scenes/cohorts/CohortFilters/constants.tsx b/frontend/src/scenes/cohorts/CohortFilters/constants.tsx
index 797c6513dfb5..e763d5fef485 100644
--- a/frontend/src/scenes/cohorts/CohortFilters/constants.tsx
+++ b/frontend/src/scenes/cohorts/CohortFilters/constants.tsx
@@ -1,27 +1,10 @@
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { CohortTypeEnum, PROPERTY_MATCH_TYPE } from 'lib/constants'
import { LemonSelectOptions } from 'lib/lemon-ui/LemonSelect'
-import {
- CohortEventFiltersField,
- CohortMathOperatorField,
- CohortNumberField,
- CohortPersonPropertiesValuesField,
- CohortRelativeAndExactTimeField,
- CohortSelectorField,
- CohortTaxonomicField,
- CohortTextField,
-} from 'scenes/cohorts/CohortFilters/CohortField'
import {
BehavioralFilterKey,
BehavioralFilterType,
CohortClientErrors,
- CohortEventFiltersFieldProps,
- CohortFieldProps,
- CohortNumberFieldProps,
- CohortPersonPropertiesValuesFieldProps,
- CohortRelativeAndExactTimeFieldProps,
- CohortTaxonomicFieldProps,
- CohortTextFieldProps,
FieldOptionsType,
FieldValues,
FilterType,
@@ -963,114 +946,6 @@ export const COHORT_EVENT_TYPES_WITH_EXPLICIT_DATETIME = Object.entries(ROWS)
.filter(([_, row]) => row.fields.some((field) => field.type === FilterType.RelativeAndExactTime))
.map(([eventType, _]) => eventType)
-// Building blocks of a row
-export const renderField: Record<FilterType, (props: CohortFieldProps) => JSX.Element> = {
- [FilterType.Behavioral]: function _renderField(p) {
- return (
- <CohortSelectorField
- {...p}
- fieldOptionGroupTypes={[
- FieldOptionsType.EventBehavioral,
- FieldOptionsType.PersonPropertyBehavioral,
- FieldOptionsType.CohortBehavioral,
- FieldOptionsType.LifecycleBehavioral,
- ]}
- />
- )
- },
- [FilterType.Aggregation]: function _renderField(p) {
- return (
- <CohortSelectorField
- {...p}
- fieldOptionGroupTypes={[FieldOptionsType.EventAggregation, FieldOptionsType.PropertyAggregation]}
- />
- )
- },
- [FilterType.Actors]: function _renderField(p) {
- return <CohortSelectorField {...p} fieldOptionGroupTypes={[FieldOptionsType.Actors]} />
- },
- [FilterType.TimeUnit]: function _renderField(p) {
- return <CohortSelectorField {...p} fieldOptionGroupTypes={[FieldOptionsType.TimeUnits]} />
- },
- [FilterType.DateOperator]: function _renderField(p) {
- return <CohortSelectorField {...p} fieldOptionGroupTypes={[FieldOptionsType.DateOperators]} />
- },
- [FilterType.MathOperator]: function _renderField(p) {
- return <CohortMathOperatorField {...p} />
- },
- [FilterType.EventsAndActionsMathOperator]: function _renderField(p) {
- return <CohortSelectorField {...p} fieldOptionGroupTypes={[FieldOptionsType.EventsAndActionsMathOperators]} />
- },
- [FilterType.Value]: function _renderField(p) {
- return <CohortSelectorField {...p} fieldOptionGroupTypes={[FieldOptionsType.ValueOptions]} />
- },
- [FilterType.Text]: function _renderField(p) {
- const _p = p as CohortTextFieldProps
- return <CohortTextField {..._p} value={String(_p?.value ?? '')} />
- },
- [FilterType.EventsAndActions]: function _renderField(p) {
- return (
- <CohortTaxonomicField
- {...(p as CohortTaxonomicFieldProps)}
- taxonomicGroupTypes={[TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.Actions]}
- placeholder="Choose event or action"
- />
- )
- },
- [FilterType.PersonProperties]: function _renderField(p) {
- return (
- <CohortTaxonomicField
- {...(p as CohortTaxonomicFieldProps)}
- hideUnsupportedRecentOperators
- taxonomicGroupTypes={[
- TaxonomicFilterGroupType.PersonProperties,
- TaxonomicFilterGroupType.PersonMetadata,
- ]}
- placeholder="Choose person property"
- />
- )
- },
- [FilterType.EventFilters]: function _renderField(p) {
- return <CohortEventFiltersField {...(p as CohortEventFiltersFieldProps)} />
- },
- [FilterType.PersonPropertyValues]: function _renderField(p) {
- return p.criteria['operator'] &&
- [PropertyOperator.IsSet, PropertyOperator.IsNotSet].includes(p.criteria['operator']) ? (
- <></>
- ) : (
- <CohortPersonPropertiesValuesField
- {...(p as CohortPersonPropertiesValuesFieldProps)}
- propertyKey={p.criteria.key}
- operator={p.criteria['operator'] ?? undefined}
- />
- )
- },
- [FilterType.Number]: function _renderField(p) {
- return <CohortNumberField {...(p as CohortNumberFieldProps)} />
- },
- [FilterType.NumberTicker]: function _renderField(p) {
- return <CohortNumberField {...(p as CohortNumberFieldProps)} />
- },
- [FilterType.CohortValues]: function _renderField(p) {
- return (
- <CohortTaxonomicField
- {...(p as CohortTaxonomicFieldProps)}
- taxonomicGroupTypes={[TaxonomicFilterGroupType.Cohorts]}
- placeholder="Choose cohort"
- />
- )
- },
- [FilterType.RelativeAndExactTime]: function _renderField(p) {
- return <CohortRelativeAndExactTimeField {...(p as CohortRelativeAndExactTimeFieldProps)} />
- },
- [FilterType.EventType]: function _renderField() {
- return <></>
- },
- [FilterType.CohortId]: function _renderField() {
- return <></>
- },
-}
-
export const CRITERIA_VALIDATIONS: Record<
string,
(d: string | number | null | undefined) => CohortClientErrors | undefined
diff --git a/frontend/src/scenes/cohorts/CohortFilters/renderField.tsx b/frontend/src/scenes/cohorts/CohortFilters/renderField.tsx
new file mode 100644
index 000000000000..bb763b50099a
--- /dev/null
+++ b/frontend/src/scenes/cohorts/CohortFilters/renderField.tsx
@@ -0,0 +1,132 @@
+import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
+import {
+ CohortEventFiltersField,
+ CohortMathOperatorField,
+ CohortNumberField,
+ CohortPersonPropertiesValuesField,
+ CohortRelativeAndExactTimeField,
+ CohortSelectorField,
+ CohortTaxonomicField,
+ CohortTextField,
+} from 'scenes/cohorts/CohortFilters/CohortField'
+import {
+ CohortEventFiltersFieldProps,
+ CohortFieldProps,
+ CohortNumberFieldProps,
+ CohortPersonPropertiesValuesFieldProps,
+ CohortRelativeAndExactTimeFieldProps,
+ CohortTaxonomicFieldProps,
+ CohortTextFieldProps,
+ FieldOptionsType,
+ FilterType,
+} from 'scenes/cohorts/CohortFilters/types'
+
+import { PropertyOperator } from '~/types'
+
+// Building blocks of a row
+export const renderField: Record<FilterType, (props: CohortFieldProps) => JSX.Element> = {
+ [FilterType.Behavioral]: function _renderField(p) {
+ return (
+ <CohortSelectorField
+ {...p}
+ fieldOptionGroupTypes={[
+ FieldOptionsType.EventBehavioral,
+ FieldOptionsType.PersonPropertyBehavioral,
+ FieldOptionsType.CohortBehavioral,
+ FieldOptionsType.LifecycleBehavioral,
+ ]}
+ />
+ )
+ },
+ [FilterType.Aggregation]: function _renderField(p) {
+ return (
+ <CohortSelectorField
+ {...p}
+ fieldOptionGroupTypes={[FieldOptionsType.EventAggregation, FieldOptionsType.PropertyAggregation]}
+ />
+ )
+ },
+ [FilterType.Actors]: function _renderField(p) {
+ return <CohortSelectorField {...p} fieldOptionGroupTypes={[FieldOptionsType.Actors]} />
+ },
+ [FilterType.TimeUnit]: function _renderField(p) {
+ return <CohortSelectorField {...p} fieldOptionGroupTypes={[FieldOptionsType.TimeUnits]} />
+ },
+ [FilterType.DateOperator]: function _renderField(p) {
+ return <CohortSelectorField {...p} fieldOptionGroupTypes={[FieldOptionsType.DateOperators]} />
+ },
+ [FilterType.MathOperator]: function _renderField(p) {
+ return <CohortMathOperatorField {...p} />
+ },
+ [FilterType.EventsAndActionsMathOperator]: function _renderField(p) {
+ return <CohortSelectorField {...p} fieldOptionGroupTypes={[FieldOptionsType.EventsAndActionsMathOperators]} />
+ },
+ [FilterType.Value]: function _renderField(p) {
+ return <CohortSelectorField {...p} fieldOptionGroupTypes={[FieldOptionsType.ValueOptions]} />
+ },
+ [FilterType.Text]: function _renderField(p) {
+ const _p = p as CohortTextFieldProps
+ return <CohortTextField {..._p} value={String(_p?.value ?? '')} />
+ },
+ [FilterType.EventsAndActions]: function _renderField(p) {
+ return (
+ <CohortTaxonomicField
+ {...(p as CohortTaxonomicFieldProps)}
+ taxonomicGroupTypes={[TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.Actions]}
+ placeholder="Choose event or action"
+ />
+ )
+ },
+ [FilterType.PersonProperties]: function _renderField(p) {
+ return (
+ <CohortTaxonomicField
+ {...(p as CohortTaxonomicFieldProps)}
+ hideUnsupportedRecentOperators
+ taxonomicGroupTypes={[
+ TaxonomicFilterGroupType.PersonProperties,
+ TaxonomicFilterGroupType.PersonMetadata,
+ ]}
+ placeholder="Choose person property"
+ />
+ )
+ },
+ [FilterType.EventFilters]: function _renderField(p) {
+ return <CohortEventFiltersField {...(p as CohortEventFiltersFieldProps)} />
+ },
+ [FilterType.PersonPropertyValues]: function _renderField(p) {
+ return p.criteria['operator'] &&
+ [PropertyOperator.IsSet, PropertyOperator.IsNotSet].includes(p.criteria['operator']) ? (
+ <></>
+ ) : (
+ <CohortPersonPropertiesValuesField
+ {...(p as CohortPersonPropertiesValuesFieldProps)}
+ propertyKey={p.criteria.key}
+ operator={p.criteria['operator'] ?? undefined}
+ />
+ )
+ },
+ [FilterType.Number]: function _renderField(p) {
+ return <CohortNumberField {...(p as CohortNumberFieldProps)} />
+ },
+ [FilterType.NumberTicker]: function _renderField(p) {
+ return <CohortNumberField {...(p as CohortNumberFieldProps)} />
+ },
+ [FilterType.CohortValues]: function _renderField(p) {
+ return (
+ <CohortTaxonomicField
+ {...(p as CohortTaxonomicFieldProps)}
+ taxonomicGroupTypes={[TaxonomicFilterGroupType.Cohorts]}
+ placeholder="Choose cohort"
+ />
+ )
+ },
+ [FilterType.RelativeAndExactTime]: function _renderField(p) {
+ return <CohortRelativeAndExactTimeField {...(p as CohortRelativeAndExactTimeFieldProps)} />
+ },
+ [FilterType.EventType]: function _renderField() {
+ return <></>
+ },
+ [FilterType.CohortId]: function _renderField() {
+ return <></>
+ },
+}