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.

chore(frontend): load the property taxonomy next to logged-in scenes (#126882)

Paul D'Ambracba42ab0b3c2
diff --git a/common/storybook/.storybook/preview.tsx b/common/storybook/.storybook/preview.tsx
index 201ec0b23efc..fdac7ec27766 100644
--- a/common/storybook/.storybook/preview.tsx
+++ b/common/storybook/.storybook/preview.tsx
@@ -1,5 +1,7 @@
import '~/styles'
+import '~/taxonomy/registerCoreFilterDefinitions'
+
import { Controls, Description, Primary, Stories, Subtitle, Title } from '@storybook/addon-docs/blocks'
import type { Preview } from '@storybook/react'
import { configure as configureTestingLibrary } from '@testing-library/dom'
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjs
index 4f2d65ad0dc8..0a044c6296ea 100644
--- a/frontend/bin/check-eager-graph.mjs
+++ b/frontend/bin/check-eager-graph.mjs
@@ -121,6 +121,8 @@ const ROOTS = [
'src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts',
// The replay submenu of the project tree pulls in the playlist and saved filter logics.
'src/layout/panel-layout/ProjectTree/menus/SessionReplayMenuItems.tsx',
+ // A hit means a module on the shell path imports taxonomy/registerCoreFilterDefinitions.
+ 'src/taxonomy/core-filter-definitions-by-group.json',
// The wizard run card opens this drawer on click, and the drawer pulls in quill primitives.
'products/wizard/frontend/runs/WizardRunDetailsDrawer.tsx',
// The Today layout renders only behind the today-rail-nav flag, and it pulls in quill primitives.
diff --git a/frontend/jest.setupAfterEnv.ts b/frontend/jest.setupAfterEnv.ts
index 01fffc389e95..1de859d0abb1 100644
--- a/frontend/jest.setupAfterEnv.ts
+++ b/frontend/jest.setupAfterEnv.ts
@@ -1,3 +1,7 @@
import * as React from 'react'
global.React = React
+
+// A require, not an import, because the taxonomy builds JSX and needs the global React set above.
+// eslint-disable-next-line @typescript-eslint/no-require-imports
+require('~/taxonomy/registerCoreFilterDefinitions')
diff --git a/frontend/src/exporter/index.tsx b/frontend/src/exporter/index.tsx
index 9d74f525bd10..5fda0e12b9e9 100644
--- a/frontend/src/exporter/index.tsx
+++ b/frontend/src/exporter/index.tsx
@@ -1,6 +1,8 @@
import '~/styles'
import './Exporter.scss'
+import '~/taxonomy/registerCoreFilterDefinitions'
+
import { createRoot } from 'react-dom/client'
import { polyfillCountryFlags } from 'lib/countryFlagEmojiPolyfill'
diff --git a/frontend/src/layout/navigation-3000/sidepanel/SidePanelContent.test.tsx b/frontend/src/layout/navigation-3000/sidepanel/SidePanelContent.test.tsx
new file mode 100644
index 000000000000..39c83e513e65
--- /dev/null
+++ b/frontend/src/layout/navigation-3000/sidepanel/SidePanelContent.test.tsx
@@ -0,0 +1,57 @@
+import { act, cleanup, render, screen } from '@testing-library/react'
+
+import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
+
+import { getFilterLabel } from '~/taxonomy/helpers'
+import * as taxonomyLoader from '~/taxonomy/loadCoreFilterDefinitions'
+import * as taxonomy from '~/taxonomy/taxonomy'
+import { initKeaTests } from '~/test/init'
+import { SidePanelTab } from '~/types'
+
+import { SidePanelContent } from './SidePanelContent'
+
+function PanelWithLabel(): JSX.Element {
+ return <span>{getFilterLabel('$pageview', TaxonomicFilterGroupType.Events)}</span>
+}
+
+describe('SidePanelContent', () => {
+ beforeEach(() => {
+ initKeaTests()
+ })
+
+ afterEach(() => {
+ cleanup()
+ jest.restoreAllMocks()
+ })
+
+ it('waits for the taxonomy before it renders the panel', async () => {
+ let loaded = false
+ let release: (() => void) | undefined
+ jest.spyOn(taxonomy, 'areCoreFilterDefinitionsLoaded').mockImplementation(() => loaded)
+ jest.spyOn(taxonomyLoader, 'loadCoreFilterDefinitions').mockImplementation(
+ () =>
+ new Promise<void>((resolve) => {
+ release = () => {
+ loaded = true
+ resolve()
+ }
+ })
+ )
+
+ render(<SidePanelContent activeTab={SidePanelTab.Activity} Content={PanelWithLabel} />)
+ await act(async () => {})
+ expect(screen.queryByText('Pageview')).toBeNull()
+
+ await act(async () => release!())
+ expect(screen.queryByText('Pageview')).not.toBeNull()
+ })
+
+ it('renders the panel at once when the taxonomy is already loaded', () => {
+ const loadSpy = jest.spyOn(taxonomyLoader, 'loadCoreFilterDefinitions')
+
+ render(<SidePanelContent activeTab={SidePanelTab.Activity} Content={PanelWithLabel} />)
+
+ expect(screen.queryByText('Pageview')).not.toBeNull()
+ expect(loadSpy).not.toHaveBeenCalled()
+ })
+})
diff --git a/frontend/src/layout/navigation-3000/sidepanel/SidePanelContent.tsx b/frontend/src/layout/navigation-3000/sidepanel/SidePanelContent.tsx
index 4c3c38e186db..837a2e49cdf5 100644
--- a/frontend/src/layout/navigation-3000/sidepanel/SidePanelContent.tsx
+++ b/frontend/src/layout/navigation-3000/sidepanel/SidePanelContent.tsx
@@ -5,6 +5,7 @@ import { Spinner } from 'lib/lemon-ui/Spinner'
import { ChunkLoadErrorBoundary } from 'scenes/ChunkLoadErrorBoundary'
import { ErrorBoundary } from '~/layout/ErrorBoundary'
+import { CoreFilterDefinitionsGate } from '~/taxonomy/CoreFilterDefinitionsGate'
import { SidePanelTab } from '~/types'
import { SidePanelNavigation } from './SidePanelNavigation'
@@ -24,7 +25,9 @@ export const SidePanelContent = memo(function SidePanelContent({
<ErrorBoundary>
<ChunkLoadErrorBoundary>
<Suspense fallback={<Spinner className="text-4xl mx-auto mt-16" />}>
- <Content />
+ <CoreFilterDefinitionsGate>
+ <Content />
+ </CoreFilterDefinitionsGate>
</Suspense>
</ChunkLoadErrorBoundary>
</ErrorBoundary>
diff --git a/frontend/src/layout/today/TodayContextPanelContent.tsx b/frontend/src/layout/today/TodayContextPanelContent.tsx
index 228806332270..ccb7a0eb75d3 100644
--- a/frontend/src/layout/today/TodayContextPanelContent.tsx
+++ b/frontend/src/layout/today/TodayContextPanelContent.tsx
@@ -8,6 +8,7 @@ import { ChunkLoadErrorBoundary } from 'scenes/ChunkLoadErrorBoundary'
import { ErrorBoundary } from '~/layout/ErrorBoundary'
import { SIDE_PANEL_TABS } from '~/layout/navigation-3000/sidepanel/sidePanelTabs'
+import { CoreFilterDefinitionsGate } from '~/taxonomy/CoreFilterDefinitionsGate'
import { SidePanelTab } from '~/types'
import { TodayAiPanel } from './TodayAiPanel'
@@ -58,7 +59,9 @@ export const TodayContextPanelContent = memo(function TodayContextPanelContent({
{/* Keep chunk-load failures out of the panel error reporter so stale assets reload once instead. */}
<ChunkLoadErrorBoundary>
<Suspense fallback={<Spinner className="mx-auto mt-16" />}>
- <Content />
+ <CoreFilterDefinitionsGate>
+ <Content />
+ </CoreFilterDefinitionsGate>
</Suspense>
</ChunkLoadErrorBoundary>
</ErrorBoundary>
diff --git a/frontend/src/lib/components/EntityFilterInfo.tsx b/frontend/src/lib/components/EntityFilterInfo.tsx
index 9ea38ebed697..046585359867 100644
--- a/frontend/src/lib/components/EntityFilterInfo.tsx
+++ b/frontend/src/lib/components/EntityFilterInfo.tsx
@@ -9,7 +9,7 @@ import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { ensureStringIsNotBlank } from 'lib/utils/strings'
import { getEventDefinitionIcon } from 'scenes/data-management/events/DefinitionHeader'
import { FEATURE_FLAG_CALLED_EVENT, FLAG_EVALUATIONS_TABLE } from 'scenes/feature-flags/flagEvaluationsTable'
-import { FLAG_CALLS_SERIES_NAME } from 'scenes/insights/filters/ActionFilter/flagCallsSeries'
+import { flagCallsSeriesName } from 'scenes/insights/filters/ActionFilter/flagCallsSeries'
import {
SeriesNode,
isActionsSeriesNode,
@@ -45,7 +45,7 @@ export function toDisplayEntityFilter(filter: DisplayableEntity): DisplayEntityF
type: EntityTypes.EVENTS,
id: FEATURE_FLAG_CALLED_EVENT,
// Any name other than the table's is a rename, for example one set through the API.
- name: name && name !== FLAG_EVALUATIONS_TABLE ? name : FLAG_CALLS_SERIES_NAME,
+ name: name && name !== FLAG_EVALUATIONS_TABLE ? name : flagCallsSeriesName(),
table_name: undefined,
}
}
diff --git a/frontend/src/lib/components/TaxonomicFilter/utils/hiddenEvents.ts b/frontend/src/lib/components/TaxonomicFilter/utils/hiddenEvents.ts
index cdaceb3bd68e..ad668cbcced4 100644
--- a/frontend/src/lib/components/TaxonomicFilter/utils/hiddenEvents.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/utils/hiddenEvents.ts
@@ -1,7 +1,7 @@
import { ExcludedProperties, TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { FlagEvaluationsModeEnumApi } from '~/generated/core/api.schemas'
-import { CORE_FILTER_DEFINITIONS_BY_GROUP } from '~/taxonomy/taxonomy'
+import { CORE_FILTER_DEFINITIONS_BY_GROUP, deriveFromCoreFilterDefinitions } from '~/taxonomy/taxonomy'
const EVENTS_MODE = FlagEvaluationsModeEnumApi.Number0
@@ -13,19 +13,21 @@ const EVENTS_MODE = FlagEvaluationsModeEnumApi.Number0
* The label is in there because lists render core events by their label, so "Feature flag called" is
* a string the user has actually seen and is as likely to type as the raw key.
*/
-const EVENTS_HIDDEN_IN_QUERY_BUILDERS: { name: string; searchTerms: string[] }[] = Object.entries(
- CORE_FILTER_DEFINITIONS_BY_GROUP.events
+const eventsHiddenInQueryBuilders = deriveFromCoreFilterDefinitions((): { name: string; searchTerms: string[] }[] =>
+ Object.entries(CORE_FILTER_DEFINITIONS_BY_GROUP.events)
+ // The "All Events" remap in the taxonomy leaves the '' key holding no definition, so read defensively.
+ .filter(([, definition]) => definition?.hidden_in_query_builders)
+ .map(([name, definition]) => ({
+ name,
+ searchTerms: [name, definition.label]
+ .filter((term): term is string => typeof term === 'string' && term.length > 0)
+ .map((term) => term.toLowerCase()),
+ }))
)
- // The "All Events" remap in the taxonomy leaves the '' key holding no definition, so read defensively.
- .filter(([, definition]) => definition?.hidden_in_query_builders)
- .map(([name, definition]) => ({
- name,
- searchTerms: [name, definition.label]
- .filter((term): term is string => typeof term === 'string' && term.length > 0)
- .map((term) => term.toLowerCase()),
- }))
-const HIDDEN_EVENT_NAMES = EVENTS_HIDDEN_IN_QUERY_BUILDERS.map(({ name }) => name)
+const hiddenEventNamesInTaxonomy = deriveFromCoreFilterDefinitions((): string[] =>
+ eventsHiddenInQueryBuilders().map(({ name }) => name)
+)
/**
* Names the Events group adds to its own exclusions.
@@ -43,7 +45,7 @@ export function hiddenEventNames(
if (includeHiddenEvents || (flagEvaluationsMode ?? EVENTS_MODE) === EVENTS_MODE) {
return []
}
- return HIDDEN_EVENT_NAMES
+ return hiddenEventNamesInTaxonomy()
}
/** The https link in the move notices flag's payload, or null while there is no announcement to link to. */
@@ -65,7 +67,9 @@ export function eventsWithMoveNotice(
flagEvaluationsMode: FlagEvaluationsModeEnumApi | undefined,
moveNoticesEnabled: boolean
): string[] {
- return moveNoticesEnabled && (flagEvaluationsMode ?? EVENTS_MODE) === EVENTS_MODE ? HIDDEN_EVENT_NAMES : []
+ return moveNoticesEnabled && (flagEvaluationsMode ?? EVENTS_MODE) === EVENTS_MODE
+ ? hiddenEventNamesInTaxonomy()
+ : []
}
/**
@@ -88,7 +92,7 @@ export function hiddenEventMatchingSearch(
if (!query) {
return null
}
- const match = EVENTS_HIDDEN_IN_QUERY_BUILDERS.find(({ searchTerms }) => searchTerms.includes(query))
+ const match = eventsHiddenInQueryBuilders().find(({ searchTerms }) => searchTerms.includes(query))
return match && excludedEventNames.includes(match.name) ? match.name : null
}
diff --git a/frontend/src/lib/components/TaxonomicFilter/utils/mcpProperties.ts b/frontend/src/lib/components/TaxonomicFilter/utils/mcpProperties.ts
index 630da3cc9f3b..4717ccb0e9f1 100644
--- a/frontend/src/lib/components/TaxonomicFilter/utils/mcpProperties.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/utils/mcpProperties.ts
@@ -1,6 +1,10 @@
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
-import { CORE_FILTER_DEFINITIONS_BY_GROUP, POSTHOG_EVENT_PROMOTED_PROPERTIES } from '~/taxonomy/taxonomy'
+import {
+ CORE_FILTER_DEFINITIONS_BY_GROUP,
+ deriveFromCoreFilterDefinitions,
+ POSTHOG_EVENT_PROMOTED_PROPERTIES,
+} from '~/taxonomy/taxonomy'
/**
* MCP analytics helpers for the taxonomic filter (`taxonomicFilterLogic.tsx`).
@@ -34,17 +38,11 @@ export function includesMCPAnalyticsEvents(eventNames: string[]): boolean {
* can't drift apart. The rest of the known schema follows in taxonomy order. */
const PRIORITY_MCP_PROPERTIES: string[] = POSTHOG_EVENT_PROMOTED_PROPERTIES[MCP_TOOL_CALL_EVENT]
-// Derived once from the (already static, module-load-resolved) taxonomy — no need to cache
-// beyond the top-level const, since CORE_FILTER_DEFINITIONS_BY_GROUP never changes at runtime.
-const MCP_PROPERTY_FILTER_OPTIONS: string[] = (() => {
+export const getMCPPropertyFilterOptions = deriveFromCoreFilterDefinitions((): string[] => {
const known = Object.keys(CORE_FILTER_DEFINITIONS_BY_GROUP[TaxonomicFilterGroupType.MCPProperties])
const prioritized = PRIORITY_MCP_PROPERTIES.filter((key) => known.includes(key))
return [...prioritized, ...known.filter((key) => !PRIORITY_MCP_PROPERTIES.includes(key))]
-})()
-
-export function getMCPPropertyFilterOptions(): string[] {
- return MCP_PROPERTY_FILTER_OPTIONS
-}
+})
/** Seeded into the Suggested tab when the picker is scoped to `$mcp_tool_call`, so
* success/failure splits are one click away. `$mcp_tool_name` also lands there via
diff --git a/frontend/src/render-query/index.tsx b/frontend/src/render-query/index.tsx
index 64e9b9b95e6d..a5d1f447a138 100644
--- a/frontend/src/render-query/index.tsx
+++ b/frontend/src/render-query/index.tsx
@@ -1,6 +1,8 @@
import '~/styles'
import './RenderQuery.scss'
+import '~/taxonomy/registerCoreFilterDefinitions'
+
import { createRoot } from 'react-dom/client'
import { initKea } from '~/initKea'
diff --git a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx
index 0e1c2c84dbf2..7f1d96f69c28 100644
--- a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx
+++ b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx
@@ -61,7 +61,7 @@ import {
import {
FLAG_CALLS_SERIES_DESCRIPTION,
- FLAG_CALLS_SERIES_NAME,
+ flagCallsSeriesName,
FLAG_CALLS_UNSUPPORTED_MATH_TYPES,
FLAG_EVALUATIONS_SERIES_FIELDS,
flagCallsFiltersFromEventFilters,
@@ -308,7 +308,7 @@ export function ActionFilterRow({
updateSeriesEntity(index, {
kind: dataWarehouseNodeKind ?? NodeKind.DataWarehouseNode,
key: FLAG_EVALUATIONS_TABLE,
- name: FLAG_CALLS_SERIES_NAME,
+ name: flagCallsSeriesName(),
...FLAG_EVALUATIONS_SERIES_FIELDS,
})
if (isEventsSeriesNode(node) && node.event === FEATURE_FLAG_CALLED_EVENT) {
@@ -317,7 +317,7 @@ export function ActionFilterRow({
const removedCount = (node.properties?.length ?? 0) - flagCallsFilters.length
if (removedCount > 0) {
lemonToast.info(
- `${FLAG_CALLS_SERIES_NAME} supports only flag key, response and SQL filters, so ${removedCount} other ${removedCount === 1 ? 'filter was' : 'filters were'} removed.`
+ `${flagCallsSeriesName()} supports only flag key, response and SQL filters, so ${removedCount} other ${removedCount === 1 ? 'filter was' : 'filters were'} removed.`
)
}
}
diff --git a/frontend/src/scenes/insights/filters/ActionFilter/flagCallsSeries.ts b/frontend/src/scenes/insights/filters/ActionFilter/flagCallsSeries.ts
index 78ee92b70663..e679e324a9b6 100644
--- a/frontend/src/scenes/insights/filters/ActionFilter/flagCallsSeries.ts
+++ b/frontend/src/scenes/insights/filters/ActionFilter/flagCallsSeries.ts
@@ -24,7 +24,9 @@ import {
PropertyOperator,
} from '~/types'
-export const FLAG_CALLS_SERIES_NAME: string = CORE_FILTER_DEFINITIONS_BY_GROUP.events[FEATURE_FLAG_CALLED_EVENT].label
+export function flagCallsSeriesName(): string {
+ return CORE_FILTER_DEFINITIONS_BY_GROUP.events[FEATURE_FLAG_CALLED_EVENT]?.label ?? FEATURE_FLAG_CALLED_EVENT
+}
/** Replaces the event's core description on insight pickers where picking the event builds a flag calls series. */
export const FLAG_CALLS_SERIES_DESCRIPTION = `Sent by PostHog SDKs each time a feature flag is evaluated.
diff --git a/frontend/src/scenes/insights/insightVizDataLogic.ts b/frontend/src/scenes/insights/insightVizDataLogic.ts
index 2f6b3d3146be..83ddaf0705ab 100644
--- a/frontend/src/scenes/insights/insightVizDataLogic.ts
+++ b/frontend/src/scenes/insights/insightVizDataLogic.ts
@@ -31,7 +31,7 @@ import {
import { MathAvailability } from 'scenes/insights/filters/ActionFilter/ActionFilterRow/types'
import { cleanSeriesNodes } from 'scenes/insights/filters/ActionFilter/cleanSeriesNodes'
import {
- FLAG_CALLS_SERIES_NAME,
+ flagCallsSeriesName,
dataWarehouseSeriesNodes,
everyWarehouseSeriesReadsFlagCalls,
flagCallsBreakdownFromEventBreakdown,
@@ -3266,7 +3266,7 @@ const handleQuerySourceUpdateSideEffects = (
hasEventBasedBreakdown(breakdownFilter)
if (mixesEventAndDataWarehouseSeries || hasEventBreakdownOnDataWarehouseSeries) {
if (hasBreakdownFilter(breakdownFilter)) {
- const subject = readsFlagCalls(nextQuery) ? FLAG_CALLS_SERIES_NAME : 'A data warehouse series'
+ const subject = readsFlagCalls(nextQuery) ? flagCallsSeriesName() : 'A data warehouse series'
lemonToast.info(
hasEventBreakdownOnDataWarehouseSeries
? `${subject} doesn't support this breakdown, so it's removed.`
diff --git a/frontend/src/scenes/sceneLogic.test.tsx b/frontend/src/scenes/sceneLogic.test.tsx
index 4e92aa6f3550..f2fc63d41260 100644
--- a/frontend/src/scenes/sceneLogic.test.tsx
+++ b/frontend/src/scenes/sceneLogic.test.tsx
@@ -24,6 +24,7 @@ import { userLogic } from 'scenes/userLogic'
import * as exporterViewLogic from '~/exporter/exporterViewLogic'
import { useMocks } from '~/mocks/jest'
+import * as taxonomyLoader from '~/taxonomy/loadCoreFilterDefinitions'
import { initKeaTests } from '~/test/init'
import {
AccessControlLevel,
@@ -60,6 +61,8 @@ const failingLogic = kea<testLogicType>([
}),
])
+type Deferred = { resolve: () => void; reject: (error: Error) => void }
+
// Held so a test can reject a still-pending scene import after navigating somewhere else.
let pendingImportRejection: ((error: Error) => void) | null = null
@@ -194,6 +197,51 @@ describe('sceneLogic', () => {
})
})
+ it.each([
+ ['loads', (release: Deferred) => release.resolve(), Scene.Settings],
+ [
+ 'fails to load',
+ (release: Deferred) => release.reject(new Error('taxonomy chunk failed')),
+ Scene.ErrorSceneLoad,
+ ],
+ ])('holds a logged-in scene until the taxonomy %s', async (_outcome, settle, expectedScene) => {
+ let release: Deferred | undefined
+ const loadSpy = jest.spyOn(taxonomyLoader, 'loadCoreFilterDefinitions').mockImplementation(
+ () =>
+ new Promise<void>((resolve, reject) => {
+ release = { resolve, reject }
+ })
+ )
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {})
+ try {
+ router.actions.push(urls.settings('user'))
+ await expectLogic(logic).delay(1)
+ expect(logic.values.activeSceneId).toEqual(Scene.DataManagement)
+
+ settle(release!)
+ await expectLogic(logic).delay(1)
+ expect(logic.values.activeSceneId).toEqual(expectedScene)
+ } finally {
+ loadSpy.mockRestore()
+ consoleErrorSpy.mockRestore()
+ }
+ })
+
+ it('does not hold a logged-out public page for the taxonomy', async () => {
+ const loadSpy = jest
+ .spyOn(taxonomyLoader, 'loadCoreFilterDefinitions')
+ .mockImplementation(() => new Promise<void>(() => {}))
+ try {
+ userLogic.actions.loadUserSuccess(null)
+ router.actions.push(urls.passwordResetComplete(MOCK_USER_UUID, 'a-token'))
+ await expectLogic(logic).delay(1)
+
+ expect(logic.values.activeSceneId).toEqual(Scene.PasswordResetComplete)
+ } finally {
+ loadSpy.mockRestore()
+ }
+ })
+
it('keeps teamLogic mounted after every other mount reference is released', () => {
// openScene and activeSceneId read teamLogic.values directly. Without a mount reference of
// its own, navigation throws as soon as nothing else holds teamLogic up.
diff --git a/frontend/src/scenes/sceneLogic.tsx b/frontend/src/scenes/sceneLogic.tsx
index 86e6de3e866d..51fb318cc13b 100644
--- a/frontend/src/scenes/sceneLogic.tsx
+++ b/frontend/src/scenes/sceneLogic.tsx
@@ -56,6 +56,7 @@ import { urls } from 'scenes/urls'
import { isSharedView } from '~/exporter/exporterViewLogic'
import { FileSystemIconType, ProductKey } from '~/queries/schema/schema-general'
+import { loadCoreFilterDefinitions } from '~/taxonomy/loadCoreFilterDefinitions'
import { AccessControlLevel, UserType } from '~/types'
import { handleLoginRedirect } from './authentication/auth/loginLogic'
@@ -75,6 +76,15 @@ interface MountedSceneLogic {
unmount: () => void
}
+// A failed load must fail the scene, because code that builds queries from an empty taxonomy returns wrong results.
+function loadCoreFilterDefinitionsFor(sceneId: string, loggedIn: boolean): Promise<void> {
+ const sceneConfig = sceneConfigurations[sceneId]
+ if (sceneConfig?.onlyUnauthenticated || (sceneConfig?.allowUnauthenticated && !loggedIn)) {
+ return Promise.resolve()
+ }
+ return retryImport(loadCoreFilterDefinitions)
+}
+
const generateTabId = (): string => crypto?.randomUUID?.()?.split('-')?.pop() || `${Date.now()}-${Math.random()}`
/**
@@ -1088,7 +1098,10 @@ export const sceneLogic = kea<sceneLogicType>([
// Capture the importer in the narrowed scope; the early guard above ensures it's
// defined, but that narrowing wouldn't flow into the retryImport closure.
const importScene = props.scenes[sceneId]
- importedScene = await retryImport(() => importScene())
+ ;[importedScene] = await Promise.all([
+ retryImport(() => importScene()),
+ loadCoreFilterDefinitionsFor(sceneId, !!userLogic.values.user),
+ ])
} catch (error: any) {
if (isChunkLoadError(error)) {
// Reloaded once in the last 20 seconds and now reloading again? Show network error
diff --git a/frontend/src/taxonomy/CoreFilterDefinitionsGate.tsx b/frontend/src/taxonomy/CoreFilterDefinitionsGate.tsx
new file mode 100644
index 000000000000..f58d8b481bf5
--- /dev/null
+++ b/frontend/src/taxonomy/CoreFilterDefinitionsGate.tsx
@@ -0,0 +1,21 @@
+import type { ReactNode } from 'react'
+
+import { retryImport } from 'lib/utils/retryImport'
+
+import { loadCoreFilterDefinitions } from './loadCoreFilterDefinitions'
+import { areCoreFilterDefinitionsLoaded } from './taxonomy'
+
+let loadFailure: { error: unknown } | null = null
+
+// Label helpers never re-render when the taxonomy arrives, so content that reads labels must wait for it.
+export function CoreFilterDefinitionsGate({ children }: { children: ReactNode }): JSX.Element {
+ if (loadFailure) {
+ throw loadFailure.error
+ }
+ if (!areCoreFilterDefinitionsLoaded()) {
+ throw retryImport(loadCoreFilterDefinitions).catch((error) => {
+ loadFailure = { error }
+ })
+ }
+ return <>{children}</>
+}
diff --git a/frontend/src/taxonomy/loadCoreFilterDefinitions.ts b/frontend/src/taxonomy/loadCoreFilterDefinitions.ts
new file mode 100644
index 000000000000..e93fb03aa08c
--- /dev/null
+++ b/frontend/src/taxonomy/loadCoreFilterDefinitions.ts
@@ -0,0 +1,13 @@
+let loading: Promise<void> | null = null
+
+// The logged-out boot imports this through sceneLogic, so the taxonomy module loads lazily too.
+export function loadCoreFilterDefinitions(): Promise<void> {
+ loading ??= Promise.all([import('./taxonomy'), import('./core-filter-definitions-by-group.json')]).then(
+ ([taxonomy, definitions]) => taxonomy.setCoreFilterDefinitions(definitions.default),
+ (error) => {
+ loading = null
+ throw error
+ }
+ )
+ return loading
+}
diff --git a/frontend/src/taxonomy/registerCoreFilterDefinitions.ts b/frontend/src/taxonomy/registerCoreFilterDefinitions.ts
new file mode 100644
index 000000000000..0b05eb262af9
--- /dev/null
+++ b/frontend/src/taxonomy/registerCoreFilterDefinitions.ts
@@ -0,0 +1,6 @@
+// For entry points that render filters on first paint without sceneLogic (the exporter, render-query, the toolbar,
+// tests, Storybook). Never import this from the app, because it puts the taxonomy back on the eager path.
+import coreFilterDefinitionsByGroup from './core-filter-definitions-by-group.json'
+import { setCoreFilterDefinitions } from './taxonomy'
+
+setCoreFilterDefinitions(coreFilterDefinitionsByGroup)
diff --git a/frontend/src/taxonomy/taxonomy.test.ts b/frontend/src/taxonomy/taxonomy.test.ts
new file mode 100644
index 000000000000..932d8ceea110
--- /dev/null
+++ b/frontend/src/taxonomy/taxonomy.test.ts
@@ -0,0 +1,64 @@
+import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
+import type * as hiddenEventsModule from 'lib/components/TaxonomicFilter/utils/hiddenEvents'
+
+import type * as helpersModule from './helpers'
+import type * as loaderModule from './loadCoreFilterDefinitions'
+import type * as taxonomyModule from './taxonomy'
+
+type Modules = {
+ taxonomy: typeof taxonomyModule
+ helpers: typeof helpersModule
+ hiddenEvents: typeof hiddenEventsModule
+ loader: typeof loaderModule
+}
+
+describe('core filter definitions', () => {
+ it.each<[string, (modules: Modules) => unknown, unknown, unknown]>([
+ [
+ 'an event label',
+ ({ helpers }) => helpers.getFilterLabel('$pageview', TaxonomicFilterGroupType.Events),
+ '$pageview',
+ 'Pageview',
+ ],
+ [
+ 'a group property definition',
+ ({ helpers }) => helpers.getCoreFilterDefinition('$group_key', 'groups_0' as TaxonomicFilterGroupType),
+ null,
+ expect.objectContaining({ label: 'Group key' }),
+ ],
+ [
+ 'the filter type of a property',
+ ({ helpers }) => helpers.getFirstFilterTypeFor('$browser'),
+ null,
+ TaxonomicFilterGroupType.EventProperties,
+ ],
+ [
+ 'session duration as a numerical event property',
+ ({ taxonomy }) => taxonomy.CORE_FILTER_DEFINITIONS_BY_GROUP.numerical_event_properties.$session_duration,
+ undefined,
+ expect.objectContaining({ label: 'Session duration' }),
+ ],
+ [
+ 'the events hidden from query builders',
+ ({ hiddenEvents }) => hiddenEvents.eventsWithMoveNotice(undefined, true),
+ [],
+ ['$feature_flag_called'],
+ ],
+ ['the property key list', ({ taxonomy }) => taxonomy.PROPERTY_KEYS.includes('$browser'), false, true],
+ ])('reads %s safely before the load and fully after it', async (_name, read, beforeLoad, afterLoad) => {
+ // The jest setup fills the shared taxonomy, so read a fresh copy that starts empty, as on a page load.
+ await jest.isolateModulesAsync(async () => {
+ const modules: Modules = {
+ taxonomy: require('./taxonomy'),
+ helpers: require('./helpers'),
+ hiddenEvents: require('lib/components/TaxonomicFilter/utils/hiddenEvents'),
+ loader: require('./loadCoreFilterDefinitions'),
+ }
+
+ expect(read(modules)).toEqual(beforeLoad)
+
+ await modules.loader.loadCoreFilterDefinitions()
+ expect(read(modules)).toEqual(afterLoad)
+ })
+ })
+})
diff --git a/frontend/src/taxonomy/taxonomy.tsx b/frontend/src/taxonomy/taxonomy.tsx
index b8b62f010ea9..806d7c0db440 100644
--- a/frontend/src/taxonomy/taxonomy.tsx
+++ b/frontend/src/taxonomy/taxonomy.tsx
@@ -3,33 +3,85 @@ import type { DataWarehousePopoverField } from 'lib/components/TaxonomicFilter/t
import { UTM_CAMPAIGN_NAME_SCHEMA_FIELD, UTM_SOURCE_NAME_SCHEMA_FIELD } from '~/taxonomy/marketingAnalytics'
import { CoreFilterDefinition } from '~/types'
-import coreFilterDefinitionsByGroup from './core-filter-definitions-by-group.json'
+import type coreFilterDefinitionsJson from './core-filter-definitions-by-group.json'
import { transformFilterDefinitions } from './transformations'
-export type CoreFilterDefinitionsGroup = Exclude<keyof typeof coreFilterDefinitionsByGroup, '//'>
+type CoreFilterDefinitionsJson = typeof coreFilterDefinitionsJson
+export type CoreFilterDefinitionsGroup = Exclude<keyof CoreFilterDefinitionsJson, '//'>
-export const CORE_FILTER_DEFINITIONS_BY_GROUP = Object.entries(coreFilterDefinitionsByGroup).reduce(
- (acc, [key, group]) => {
+// The Record type makes typecheck fail when the taxonomy gains or loses a group.
+const GROUPS: Record<CoreFilterDefinitionsGroup, true> = {
+ elements: true,
+ error_tracking_issues: true,
+ event_metadata: true,
+ event_properties: true,
+ events: true,
+ groups: true,
+ log_entries: true,
+ mcp_properties: true,
+ metadata: true,
+ numerical_event_properties: true,
+ person_metadata: true,
+ person_properties: true,
+ replay: true,
+ revenue_analytics_properties: true,
+ session_properties: true,
+}
+
+// Filled in place, so a module can keep a reference to it or to one of its groups.
+export const CORE_FILTER_DEFINITIONS_BY_GROUP = Object.fromEntries(
+ Object.keys(GROUPS).map((group) => [group, {}])
+) as Record<CoreFilterDefinitionsGroup, Record<string, CoreFilterDefinition>>
+CORE_FILTER_DEFINITIONS_BY_GROUP.numerical_event_properties = CORE_FILTER_DEFINITIONS_BY_GROUP.event_properties
+
+export const PROPERTY_KEYS: string[] = []
+
+let definitionsLoaded = false
+
+export function areCoreFilterDefinitionsLoaded(): boolean {
+ return definitionsLoaded
+}
+
+export function setCoreFilterDefinitions(definitionsByGroup: CoreFilterDefinitionsJson): void {
+ if (definitionsLoaded) {
+ return
+ }
+ for (const [key, group] of Object.entries(definitionsByGroup)) {
if (key === '//' || typeof group === 'string') {
// ignore the comment
- return acc
+ continue
}
- return Object.assign(acc, { [key]: transformFilterDefinitions(group) })
- },
- {} as Record<CoreFilterDefinitionsGroup, Record<string, CoreFilterDefinition>>
-)
-
-// We treat `$session_duration` as an event property in the context of series `math`, but it's fake in a sense
-CORE_FILTER_DEFINITIONS_BY_GROUP.event_properties.$session_duration =
- CORE_FILTER_DEFINITIONS_BY_GROUP.session_properties.$session_duration
+ Object.assign(
+ CORE_FILTER_DEFINITIONS_BY_GROUP[key as CoreFilterDefinitionsGroup],
+ transformFilterDefinitions(group)
+ )
+ }
+ const { events, event_properties, session_properties } = CORE_FILTER_DEFINITIONS_BY_GROUP
+ // We treat `$session_duration` as an event property in the context of series `math`, but it's fake in a sense
+ event_properties.$session_duration = session_properties.$session_duration
-CORE_FILTER_DEFINITIONS_BY_GROUP.numerical_event_properties = CORE_FILTER_DEFINITIONS_BY_GROUP.event_properties
+ // Change "All Events" to empty string
+ events[''] = events['All Events']
+ delete events['All Events']
-// Change "All Events" to empty string
-CORE_FILTER_DEFINITIONS_BY_GROUP.events[''] = CORE_FILTER_DEFINITIONS_BY_GROUP.events['All Events']
-delete CORE_FILTER_DEFINITIONS_BY_GROUP.events['All Events']
+ PROPERTY_KEYS.push(...Object.keys(event_properties))
+ definitionsLoaded = true
+}
-export const PROPERTY_KEYS = Object.keys(CORE_FILTER_DEFINITIONS_BY_GROUP.event_properties)
+/** Wraps a value computed from the taxonomy. It is cached once the taxonomy has loaded, and computed fresh until then. */
+export function deriveFromCoreFilterDefinitions<T>(derive: () => T): () => T {
+ let derived: { value: T } | null = null
+ return () => {
+ if (derived) {
+ return derived.value
+ }
+ const value = derive()
+ if (definitionsLoaded) {
+ derived = { value }
+ }
+ return value
+ }
+}
/**
* these are properties that PostHog add to events they track for their own purposes
diff --git a/frontend/src/toolbar/shared/debug/eventCategories.ts b/frontend/src/toolbar/shared/debug/eventCategories.ts
index fa7c4446c4d7..8abc71d5f6bd 100644
--- a/frontend/src/toolbar/shared/debug/eventCategories.ts
+++ b/frontend/src/toolbar/shared/debug/eventCategories.ts
@@ -1,3 +1,5 @@
+import '~/taxonomy/registerCoreFilterDefinitions'
+
import { CORE_FILTER_DEFINITIONS_BY_GROUP } from '~/taxonomy/taxonomy'
import type { EventType } from '~/types'