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(insights): defer action loading in filter controls (#103114)

Matt Puaad4958bf9cc6
diff --git a/docs/internal/taxonomic-filter-search.md b/docs/internal/taxonomic-filter-search.md
index 0d61bc882521..2beaed590ae9 100644
--- a/docs/internal/taxonomic-filter-search.md
+++ b/docs/internal/taxonomic-filter-search.md
@@ -14,6 +14,13 @@ The expansion count must not delay the scoped results or keep the aggregate reve
The legacy implementation separates these requests in `infiniteListLogic.ts`; the rebuilt implementation uses independent resources in `hooks/useGroupList.ts`. Keep this behavior consistent across both implementations.
+## Action definitions
+
+Event-only insight editors and closed breakdown pickers do not load the action list.
+Action series load their definitions to resolve names and event-scoped properties.
+Opening an event picker that offers Actions loads the list; later opens reuse the shared cache.
+The classic popover unmounts after its close transition and starts with a fresh search when reopened.
+
## Typing and rendering
The legacy picker debounces API searches for 500 ms after the last keystroke, including while the initial response is loading.
diff --git a/frontend/src/lib/components/TaxonomicPopover/TaxonomicPopover.test.tsx b/frontend/src/lib/components/TaxonomicPopover/TaxonomicPopover.test.tsx
index 4be85cda6100..57bdb3603478 100644
--- a/frontend/src/lib/components/TaxonomicPopover/TaxonomicPopover.test.tsx
+++ b/frontend/src/lib/components/TaxonomicPopover/TaxonomicPopover.test.tsx
@@ -5,13 +5,15 @@ import userEvent from '@testing-library/user-event'
import { Provider } from 'kea'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { useMocks } from '~/mocks/jest'
-import { actionsModel } from '~/models/actionsModel'
import { groupsModel } from '~/models/groupsModel'
import { initKeaTests } from '~/test/init'
import { mockGetEventDefinitions } from '~/test/mocks'
+import { taxonomicMenuPreferenceLogic } from './taxonomicMenuPreferenceLogic'
import { TaxonomicPopover, TaxonomicStringPopover } from './TaxonomicPopover'
jest.mock('lib/components/AutoSizer', () => ({
@@ -20,21 +22,29 @@ jest.mock('lib/components/AutoSizer', () => ({
}))
describe('TaxonomicPopover', () => {
+ let actionRequestCount: number
+
beforeEach(() => {
+ actionRequestCount = 0
useMocks({
get: {
'/api/projects/:team/event_definitions': mockGetEventDefinitions,
+ '/api/projects/:team/actions/': () => {
+ actionRequestCount++
+ return [200, { results: [], count: 0 }]
+ },
},
post: {
'/api/environments/:team/query': { results: [] },
},
})
initKeaTests()
- actionsModel.mount()
groupsModel.mount()
})
afterEach(() => {
+ featureFlagLogic.actions.setFeatureFlags([], {})
+ taxonomicMenuPreferenceLogic.actions.setUseNewMenu(true)
cleanup()
})
@@ -55,6 +65,54 @@ describe('TaxonomicPopover', () => {
expect(screen.getByText('pageview')).toBeInTheDocument()
})
+ it('loads actions only after an actions picker opens', async () => {
+ renderPopover({
+ groupType: TaxonomicFilterGroupType.Actions,
+ groupTypes: [TaxonomicFilterGroupType.Actions],
+ })
+
+ expect(actionRequestCount).toBe(0)
+
+ await userEvent.click(screen.getByText('Please select'))
+
+ await waitFor(() => {
+ expect(actionRequestCount).toBe(1)
+ })
+ })
+
+ it('resets the legacy picker search after closing completely', async () => {
+ renderPopover()
+
+ await userEvent.click(screen.getByText('Please select'))
+ await userEvent.type(screen.getByTestId('taxonomic-filter-searchfield'), 'event1')
+ await userEvent.click(document.body)
+ await waitFor(() => {
+ expect(screen.queryByTestId('taxonomic-filter-searchfield')).not.toBeInTheDocument()
+ })
+ await userEvent.click(screen.getByText('Please select'))
+
+ expect(screen.getByTestId('taxonomic-filter-searchfield')).toHaveValue('')
+ })
+
+ it('opens the rebuilt actions picker', async () => {
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.TAXONOMIC_FILTER_MENU_REBUILD]: true })
+ taxonomicMenuPreferenceLogic.mount()
+ taxonomicMenuPreferenceLogic.actions.setUseNewMenu(true)
+
+ renderPopover({
+ groupType: TaxonomicFilterGroupType.Actions,
+ groupTypes: [TaxonomicFilterGroupType.Actions],
+ })
+
+ await userEvent.click(screen.getByTestId('taxonomic-popover-menu-trigger'))
+ await userEvent.click(screen.getByTestId('taxonomic-filter-menu-new'))
+
+ await waitFor(() => {
+ expect(screen.getByTestId('menu-filter-search')).toBeInTheDocument()
+ })
+ })
+
it('opens dropdown on click and calls onChange with correct args on selection', async () => {
const { onChange } = renderPopover({ placeholder: 'Select an event' })
await userEvent.click(screen.getByText('Select an event'))
diff --git a/frontend/src/queries/nodes/InsightViz/EditorFilters.test.tsx b/frontend/src/queries/nodes/InsightViz/EditorFilters.test.tsx
index b3c9c42867ea..47b0029b2ad2 100644
--- a/frontend/src/queries/nodes/InsightViz/EditorFilters.test.tsx
+++ b/frontend/src/queries/nodes/InsightViz/EditorFilters.test.tsx
@@ -1,9 +1,10 @@
import '@testing-library/jest-dom'
-import { cleanup, render, screen, within } from '@testing-library/react'
+import { cleanup, render, screen, waitFor, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { BindLogic, Provider } from 'kea'
+import api from 'lib/api'
import { insightDataLogic } from 'scenes/insights/insightDataLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
@@ -176,6 +177,24 @@ describe('EditorFilters', () => {
}
})
+ it.each([false, true])('loads actions only when needed (action series: %s)', async (hasActionSeries) => {
+ const loadActions = jest.spyOn(api.actions, 'list').mockResolvedValue({ results: [], count: 0 })
+ try {
+ const query = makeTrendsQuery()
+ if (hasActionSeries) {
+ query.series = [{ kind: NodeKind.ActionsNode, id: 1, name: 'Example action' }]
+ }
+ setupAndRender(query)
+
+ expect(loadActions).toHaveBeenCalledTimes(hasActionSeries ? 1 : 0)
+
+ await userEvent.click(screen.getByTestId('trend-element-subject-0'))
+ await waitFor(() => expect(loadActions).toHaveBeenCalledTimes(1))
+ } finally {
+ loadActions.mockRestore()
+ }
+ })
+
it('hides formula mode toggle for trends', () => {
setupAndRender(makeTrendsQuery())
expect(screen.queryByText('Enable formula mode')).not.toBeInTheDocument()
diff --git a/frontend/src/queries/nodes/InsightViz/GlobalAndOrFilters.tsx b/frontend/src/queries/nodes/InsightViz/GlobalAndOrFilters.tsx
index 02a5f721dee1..831c1a0ff891 100644
--- a/frontend/src/queries/nodes/InsightViz/GlobalAndOrFilters.tsx
+++ b/frontend/src/queries/nodes/InsightViz/GlobalAndOrFilters.tsx
@@ -8,15 +8,21 @@ import { getInsightPropertyFilterGroupTypes } from 'scenes/insights/utils/proper
import { actionsModel } from '~/models/actionsModel'
import { groupsModel } from '~/models/groupsModel'
import { ProductAnalyticsInsightQueryNode } from '~/queries/schema/schema-general'
+import { isActionsNode, isInsightQueryWithSeries } from '~/queries/utils'
import { EditorFilterProps } from '~/types'
import { PropertyGroupFilters } from './PropertyGroupFilters/PropertyGroupFilters'
import { getAllEventNames } from './utils'
export function GlobalAndOrFilters({ insightProps }: EditorFilterProps): JSX.Element {
- const { actions: allActions } = useValues(actionsModel)
const { groupsTaxonomicTypes } = useValues(groupsModel)
const { querySource, hasDataWarehouseSeries } = useValues(insightVizDataLogic(insightProps))
+ const { actions: allActions } = useValues(
+ actionsModel({
+ shouldLoad:
+ !!querySource && isInsightQueryWithSeries(querySource) && querySource.series.some(isActionsNode),
+ })
+ )
const { updateQuerySource } = useActions(insightVizDataLogic(insightProps))
const { hasPageview, hasScreen } = getProjectEventExistence()
diff --git a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx
index 7c78b811ec6e..39767cfab6ec 100644
--- a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx
+++ b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx
@@ -148,7 +148,7 @@ export function ActionFilterRow({
duplicateFilter,
convertFilterToGroup,
} = useActions(logic)
- const { actions } = useValues(actionsModel)
+ const { actions } = useValues(actionsModel({ shouldLoad: filter.type === EntityTypes.ACTIONS }))
const { mathDefinitions } = useValues(mathsLogic)
const { dataWarehouseTablesMap } = useValues(databaseTableListLogic)
const { ensureAllTableFields } = useActions(databaseTableListLogic)
diff --git a/frontend/src/scenes/insights/filters/BreakdownFilter/TaxonomicBreakdownPopover.tsx b/frontend/src/scenes/insights/filters/BreakdownFilter/TaxonomicBreakdownPopover.tsx
index bb2e9168ba31..eb5e562303d2 100644
--- a/frontend/src/scenes/insights/filters/BreakdownFilter/TaxonomicBreakdownPopover.tsx
+++ b/frontend/src/scenes/insights/filters/BreakdownFilter/TaxonomicBreakdownPopover.tsx
@@ -10,7 +10,7 @@ import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { actionsModel } from '~/models/actionsModel'
import { groupsModel } from '~/models/groupsModel'
import { NodeKind } from '~/queries/schema/schema-general'
-import { hogql, isInsightVizNode, isRetentionQuery } from '~/queries/utils'
+import { hogql, isActionsNode, isInsightQueryWithSeries, isInsightVizNode, isRetentionQuery } from '~/queries/utils'
import { taxonomicBreakdownFilterLogic } from './taxonomicBreakdownFilterLogic'
@@ -31,17 +31,25 @@ export const TaxonomicBreakdownPopover = ({
breakdownType,
breakdownValue,
}: TaxonomicBreakdownPopoverProps): JSX.Element => {
- // allEventNames resolves action series through actionsModel, which the shared insight logic does not mount
- useMountedLogic(actionsModel)
const { insightProps } = useValues(insightLogic)
const {
allEventNames,
+ querySource,
query,
hasDataWarehouseSeries,
hasOnlyDataWarehouseSeries,
dataWarehouseSeriesTableNames,
isTrends,
} = useValues(insightVizDataLogic(insightProps))
+ useMountedLogic(
+ actionsModel({
+ shouldLoad:
+ open &&
+ !!querySource &&
+ isInsightQueryWithSeries(querySource) &&
+ querySource.series.some(isActionsNode),
+ })
+ )
const { databaseLoading } = useValues(databaseTableListLogic)
const { groupsTaxonomicTypes } = useValues(groupsModel)
const { includeSessions, taxonomicBreakdownType } = useValues(taxonomicBreakdownFilterLogic)