: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(toolbar): cut remaining app-zone edges and shrink the deny list (#69483)
Rafael Audibert7182bb9dc60a
diff --git a/.oxlintrc.json b/.oxlintrc.jsonindex c361859ee681..2c9421df5562 100644--- a/.oxlintrc.json+++ b/.oxlintrc.json@@ -329,10 +329,7 @@"!~/scenes/urls","!scenes/product-tours/stepUtils","!scenes/product-tours/constants",- "!scenes/product-tours/editor/generateStepHtml",- "!scenes/experiments/experimentStatus",- "!scenes/experiments/utils",- "!~/scenes/experiments/utils"+ "!scenes/product-tours/editor/generateStepHtml"],"message": "The toolbar ships to customer pages and must not depend on app scenes. Import from lib/, or fetch via toolbarFetch. The listed exceptions are the toolbar's intentional seams; the full transitive boundary is enforced by frontend/bin/check-toolbar-graph.mjs."},diff --git a/frontend/bin/check-toolbar-graph.mjs b/frontend/bin/check-toolbar-graph.mjsindex d3fe6b5bdbbd..e16c743e4071 100644--- a/frontend/bin/check-toolbar-graph.mjs+++ b/frontend/bin/check-toolbar-graph.mjs@@ -29,9 +29,8 @@ const ENTRY = 'src/toolbar/index.tsx'const APP_ZONE = [/^src\/products/, /^src\/scenes\//, /^src\/layout\//, /^src\/models\//, /^\.\.\/products\//]-// Packages the toolbar never renders and must not appear in its graph at all. monaco-editor and-// chart.js are denied at resolve time in toolbar-config.mjs; mermaid and hls.js have no import-// path into the toolbar, and this guards against one being reintroduced.+// Packages the toolbar never renders and must not appear in its graph at all. None have an+// import path into the toolbar today; this guard fails the build if a change reintroduces one.const FORBIDDEN_PACKAGES = ['node_modules/monaco-editor/','node_modules/chart.js/',@@ -42,7 +41,7 @@ const FORBIDDEN_PACKAGES = [// Ratchet policy: when an edge is cut, lower the budget to lock it in; raise it only as a// conscious, reviewed decision in the PR that needs it. There is headroom for churn, but any// reintroduced leak jumps the graph back toward ~100 MiB and fails loudly.-const TOTAL_INPUT_BYTES_BUDGET = 14_800_000+const TOTAL_INPUT_BYTES_BUDGET = 14_400_000function fail(message) {console.error(`\n❌ ${message}`)diff --git a/frontend/bin/check-toolbar-size.mjs b/frontend/bin/check-toolbar-size.mjsindex e25fbce697e3..d6de39c5d55d 100644--- a/frontend/bin/check-toolbar-size.mjs+++ b/frontend/bin/check-toolbar-size.mjs@@ -16,7 +16,7 @@ const MAX_FILE_BYTES = 10_000_000// 2. Eager-set budget: the entry plus everything statically imported from it — the bytes every// toolbar load fetches before any feature runs. Ratchet policy: when an edge is cut, lower the// budget to lock it in; raise it only as a conscious, reviewed decision in the PR that needs it.-const MAX_EAGER_BYTES = 1_700_000+const MAX_EAGER_BYTES = 1_650_000// 3. The loader is injected on every customer page that enables the toolbar and must stay tiny.const MAX_LOADER_BYTES = 20_000diff --git a/frontend/bin/toolbar-graph-baseline.json b/frontend/bin/toolbar-graph-baseline.jsonindex 4c0e7895d9a3..7b7ddd065755 100644--- a/frontend/bin/toolbar-graph-baseline.json+++ b/frontend/bin/toolbar-graph-baseline.json@@ -1,11 +1,6 @@{"//": "Toolbar -> app-zone import edges that exist today, enforced by bin/check-toolbar-graph.mjs. These are the toolbar's intentional seams into app code. Do not add entries; delete an entry if you cut its edge.","edges": [- "src/lib/components/PropertyKeyInfo.tsx -> src/scenes/surveys/surveyQuestionLabelsLogic.ts",- "src/taxonomy/helpers.ts -> src/scenes/surveys/surveyQuestionLabelsLogic.ts",- "src/taxonomy/taxonomy.tsx -> src/scenes/web-analytics/tabs/marketing-analytics/utils.ts",- "src/toolbar/experiments/experimentsTabLogic.tsx -> src/scenes/experiments/experimentStatus.ts",- "src/toolbar/experiments/experimentsTabLogic.tsx -> src/scenes/experiments/utils.ts","src/toolbar/product-tours/ProductToursSidebar.tsx -> src/scenes/product-tours/stepUtils.tsx","src/toolbar/product-tours/StepCard.tsx -> src/scenes/product-tours/stepUtils.tsx","src/toolbar/product-tours/productToursLogic.ts -> src/scenes/product-tours/constants.ts",diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex 0952a854670c..80abc85b700c 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -1,8 +1,8 @@import { DataColorToken } from 'lib/colors'// eslint-disable-next-line import/no-cycleimport { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'-import { ConversionGoalSchema } from 'scenes/web-analytics/tabs/marketing-analytics/utils'+import { ConversionGoalSchema } from '~/taxonomy/marketingAnalytics'import {AnyFilterLike,AnyGroupScopeFilter,diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/common/ConversionGoalDropdown.tsx b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/common/ConversionGoalDropdown.tsxindex 056befaf7c4f..249bb8e8bfae 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/common/ConversionGoalDropdown.tsx+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/common/ConversionGoalDropdown.tsx@@ -13,16 +13,15 @@ import {NodeKind,} from '~/queries/schema/schema-general'import { isDataWarehouseNode } from '~/queries/utils'-import { conversionGoalPopoverFields } from '~/taxonomy/taxonomy'-import { ActionFilter, BaseMathType, AnyDataWarehouseFilter, EntityTypes, FilterType, PropertyMathType } from '~/types'-import {ConversionGoalSchema,DISTINCT_ID_FIELD_SCHEMA_FIELD,TIMESTAMP_FIELD_SCHEMA_FIELD,UTM_CAMPAIGN_NAME_SCHEMA_FIELD,UTM_SOURCE_NAME_SCHEMA_FIELD,-} from '../../../utils'+} from '~/taxonomy/marketingAnalytics'+import { conversionGoalPopoverFields } from '~/taxonomy/taxonomy'+import { ActionFilter, BaseMathType, AnyDataWarehouseFilter, EntityTypes, FilterType, PropertyMathType } from '~/types'interface ConversionGoalDropdownProps {value: ConversionGoalFilter@@ -139,7 +138,8 @@ export function ConversionGoalDropdown({// Override the schema with the schema from the data warehouseif (data_warehouse?.[0]?.type === EntityTypes.DATA_WAREHOUSE) {const dwNode = data_warehouse[0] as AnyDataWarehouseFilter &- Record<ConversionGoalSchema, string>+ Record<ConversionGoalSchema, string> &+ Partial<Pick<DataWarehouseNode, 'id_field' | 'dw_source_type'>>const schema = dwNodeconst overrideSchema: Record<ConversionGoalSchema, string> = {utm_campaign_name: schema[UTM_CAMPAIGN_NAME_SCHEMA_FIELD],diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/utils.ts b/frontend/src/taxonomy/marketingAnalytics.tssimilarity index 55%rename from frontend/src/scenes/web-analytics/tabs/marketing-analytics/utils.tsrename to frontend/src/taxonomy/marketingAnalytics.tsindex 1bea33b639d0..2da06e6dbac2 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/utils.ts+++ b/frontend/src/taxonomy/marketingAnalytics.ts@@ -1,16 +1,18 @@-import { MarketingAnalyticsSchemaField } from '~/queries/schema/schema-general'+export const UTM_CAMPAIGN_NAME_SCHEMA_FIELD = 'utm_campaign_name' as const+export const UTM_SOURCE_NAME_SCHEMA_FIELD = 'utm_source_name' as const+export const DISTINCT_ID_FIELD_SCHEMA_FIELD = 'distinct_id_field' as const+export const TIMESTAMP_FIELD_SCHEMA_FIELD = 'timestamp_field' as const-export const UTM_CAMPAIGN_NAME_SCHEMA_FIELD = 'utm_campaign_name'-export const UTM_SOURCE_NAME_SCHEMA_FIELD = 'utm_source_name'-export const DISTINCT_ID_FIELD_SCHEMA_FIELD = 'distinct_id_field'-export const TIMESTAMP_FIELD_SCHEMA_FIELD = 'timestamp_field'+// KLUDGE: This should ideally be a union of the strings above,+// however the backend is pretty borked and assumes it's a string everywhere+// and migrating away from this is not trivial+export type ConversionGoalSchema = string+type ConversionGoalSchemaType = { type: string[]; required: boolean; isCurrency: boolean }-export const MARKETING_ANALYTICS_CONVERSION_GOAL_SCHEMA: Record<string, MarketingAnalyticsSchemaField> = {+export const MARKETING_ANALYTICS_CONVERSION_GOAL_SCHEMA: Record<ConversionGoalSchema, ConversionGoalSchemaType> = {// UTM fields are required for conversion goals to properly track attribution[UTM_CAMPAIGN_NAME_SCHEMA_FIELD]: { type: ['string'], required: true, isCurrency: false },[UTM_SOURCE_NAME_SCHEMA_FIELD]: { type: ['string'], required: true, isCurrency: false },[TIMESTAMP_FIELD_SCHEMA_FIELD]: { type: ['datetime', 'date', 'string'], required: true, isCurrency: false },[DISTINCT_ID_FIELD_SCHEMA_FIELD]: { type: ['string'], required: false, isCurrency: false },}--export type ConversionGoalSchema = keyof typeof MARKETING_ANALYTICS_CONVERSION_GOAL_SCHEMAdiff --git a/frontend/src/taxonomy/taxonomy.tsx b/frontend/src/taxonomy/taxonomy.tsxindex a31a399f08ee..8635d0aa83c9 100644--- a/frontend/src/taxonomy/taxonomy.tsx+++ b/frontend/src/taxonomy/taxonomy.tsx@@ -1,9 +1,6 @@-import { DataWarehousePopoverField } from 'lib/components/TaxonomicFilter/types'-import {- UTM_CAMPAIGN_NAME_SCHEMA_FIELD,- UTM_SOURCE_NAME_SCHEMA_FIELD,-} from 'scenes/web-analytics/tabs/marketing-analytics/utils'+import type { DataWarehousePopoverField } from 'lib/components/TaxonomicFilter/types'+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'diff --git a/frontend/src/toolbar/experiments/experimentsTabLogic.tsx b/frontend/src/toolbar/experiments/experimentsTabLogic.tsxindex ba0dae74be7d..799babf0bf57 100644--- a/frontend/src/toolbar/experiments/experimentsTabLogic.tsx+++ b/frontend/src/toolbar/experiments/experimentsTabLogic.tsx@@ -4,9 +4,7 @@ import { subscriptions } from 'kea-subscriptions'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'import { EXPERIMENT_TARGET_SELECTOR } from 'lib/utils/actions'-import { isLaunched } from 'scenes/experiments/experimentStatus'-import { percentageDistribution } from '~/scenes/experiments/utils'import { toolbarLogic } from '~/toolbar/bar/toolbarLogic'import { experimentsLogic } from '~/toolbar/experiments/experimentsLogic'import {@@ -20,7 +18,7 @@ import { toolbarConfigLogic } from '~/toolbar/toolbarConfigLogic'import { toolbarPosthogJS } from '~/toolbar/toolbarPosthogJS'import { WebExperiment, WebExperimentDraftType, WebExperimentForm } from '~/toolbar/types'import { urls } from '~/toolbar/urls'-import { elementToQuery, joinWithUiHost } from '~/toolbar/utils'+import { elementToQuery, isLaunched, joinWithUiHost, percentageDistribution } from '~/toolbar/utils'import { Experiment, ExperimentIdType } from '~/types'import type { experimentsTabLogicType } from './experimentsTabLogicType'diff --git a/frontend/src/toolbar/shims/shims.test.ts b/frontend/src/toolbar/shims/shims.test.tsindex c797cdd52554..48fd9f7c94c3 100644--- a/frontend/src/toolbar/shims/shims.test.ts+++ b/frontend/src/toolbar/shims/shims.test.ts@@ -5,6 +5,7 @@ import { initKeaTests } from '~/test/init'import { featureFlagLogic, getFeatureFlagPayload } from './featureFlagLogic'import { membersLogic } from './membersLogic'import { sceneLogic } from './sceneLogic'+import { surveyQuestionLabelsLogic } from './surveyQuestionLabelsLogic'import { isAuthenticatedTeam, teamLogic } from './teamLogic'import { userLogic } from './userLogic'@@ -20,6 +21,7 @@ describe('toolbar shims', () => {['sceneLogic', sceneLogic, { sceneConfig: null }],['teamLogic', teamLogic, { currentTeam: null, timezone: 'UTC', weekStartDay: 0 }],['featureFlagLogic', featureFlagLogic, { featureFlags: {} }],+ ['surveyQuestionLabelsLogic', surveyQuestionLabelsLogic, { surveyQuestionLabels: {} }],])('%s provides expected defaults', (_name, logic, expected) => {logic.mount()expectLogic(logic).toMatchValues(expected)@@ -53,6 +55,7 @@ describe('toolbar shims', () => {sceneLogic.mount()teamLogic.mount()featureFlagLogic.mount()+ surveyQuestionLabelsLogic.mount()expect(fetchSpy).not.toHaveBeenCalled()})diff --git a/frontend/src/toolbar/shims/surveyQuestionLabelsLogic.ts b/frontend/src/toolbar/shims/surveyQuestionLabelsLogic.tsnew file mode 100644index 000000000000..10fc8ec2ce8b--- /dev/null+++ b/frontend/src/toolbar/shims/surveyQuestionLabelsLogic.ts@@ -0,0 +1,20 @@+import { kea, path, reducers } from 'kea'++import type { surveyQuestionLabelsLogicType } from './surveyQuestionLabelsLogicType'++// Toolbar shim — survey question labels come from an authenticated endpoint the toolbar can't+// reach on customer pages (lib/api is denied), so the labels are always empty here. Consumers+// (PropertyKeyInfo, taxonomy helpers) fall back to their generic labels.+export interface SurveyQuestionLabel {+ surveyId: string+ surveyName: string+ questionText: string+ questionIndex: number+}++export const surveyQuestionLabelsLogic = kea<surveyQuestionLabelsLogicType>([+ path(['toolbar', 'shims', 'surveyQuestionLabelsLogic']),+ reducers({+ surveyQuestionLabels: [{} as Record<string, SurveyQuestionLabel>, {}],+ }),+])diff --git a/frontend/src/toolbar/utils.ts b/frontend/src/toolbar/utils.tsindex fed7a62633e6..8e3bdf611df0 100644--- a/frontend/src/toolbar/utils.ts+++ b/frontend/src/toolbar/utils.ts@@ -8,7 +8,7 @@ import { toolbarLogger } from '~/toolbar/toolbarLogger'import { captureToolbarException } from '~/toolbar/toolbarPosthogJS'import { ActionStepForm, ElementRect } from '~/toolbar/types'import { finder } from '~/toolbar/vendor/finder'-import { ActionStepType } from '~/types'+import { Experiment, ActionStepType, ExperimentStatus } from '~/types'import { ActionStepPropertyKey } from './actions/ActionStep'@@ -735,6 +735,47 @@ export function makeNavigateWrapper(onNavigate: () => void, patchKey: string): (}}+// Toolbar-owned copy of the app's experiment variant-split helper. Duplicated rather than+// imported from scenes/experiments/utils, which drags 37KB and app-only modules into the+// customer-facing bundle for this one pure function.+export function percentageDistribution(variantCount: number): number[] {+ const basePercentage = Math.floor(100 / variantCount)+ const percentages = new Array(variantCount).fill(basePercentage)++ // try to equally distribute `remaining` across variants+ let remaining = 100 - basePercentage * variantCount+ for (let i = 0; remaining > 0; i++, remaining--) {+ percentages[i] += 1+ }++ return percentages+}++// Toolbar-owned copy of the app's experiment status helpers. Duplicated rather than imported+// from scenes/experiments/experimentStatus so the toolbar bundle doesn't reach into the app+// scene zone for these two pure functions.+type ExperimentStatusInput = Pick<Experiment, 'status' | 'start_date' | 'end_date'> | null | undefined++function getExperimentStatus(experiment: ExperimentStatusInput): ExperimentStatus {+ if (!experiment) {+ return ExperimentStatus.Draft+ }+ if (experiment.status) {+ return experiment.status+ }+ if (experiment.end_date) {+ return ExperimentStatus.Stopped+ }+ if (experiment.start_date) {+ return ExperimentStatus.Running+ }+ return ExperimentStatus.Draft+}++export function isLaunched(experiment: ExperimentStatusInput): boolean {+ return getExperimentStatus(experiment) !== ExperimentStatus.Draft+}+export function joinWithUiHost(uiHost: string, path: string): string {const trimmedHost = (uiHost || '').replace(/\/+$/, '')const trimmedPath = (path || '').trim()diff --git a/frontend/toolbar-config.mjs b/frontend/toolbar-config.mjsindex f13e497b90cf..b801d33b2ec1 100644--- a/frontend/toolbar-config.mjs+++ b/frontend/toolbar-config.mjs@@ -26,6 +26,9 @@ const shimmedModules = {'scenes/sceneLogic': 'src/toolbar/shims/sceneLogic.ts','scenes/teamLogic': 'src/toolbar/shims/teamLogic.ts','lib/logic/featureFlagLogic': 'src/toolbar/shims/featureFlagLogic.ts',+ // Survey question labels load from an authenticated endpoint the toolbar can't reach, so+ // the shim keeps its shared consumers (PropertyKeyInfo, taxonomy helpers) out of the app zone.+ 'scenes/surveys/surveyQuestionLabelsLogic': 'src/toolbar/shims/surveyQuestionLabelsLogic.ts',// Not a kea shim: the toolbar's parity-tested urls duplicate (see src/toolbar/urls.ts).// Toolbar code imports it directly; this entry covers lib/ components shared with the// app (TZLabel, Link, HeatmapEventsPanel), whose scenes/urls import would otherwise pull@@ -44,29 +47,9 @@ const deniedPaths = ['scenes/session-recordings/player/snapshot-processing/DecompressionWorkerManager.ts',]-// Heavy third-party libraries the toolbar never renders but which would otherwise leak in-// transitively through the shared scene graph. Denying them at resolve time keeps them out of-// the artifact set entirely; bin/check-toolbar-graph.mjs asserts their absence.-const deniedThirdPartyPackages = [- // chart.js + its annotation plugin (via Sparkline). Charts in the toolbar go through the- // already-denied LineGraph.- /^chart\.js(\/|$)/,- /^chartjs-plugin-annotation(\/|$)/,-]--const deniedPatterns = [- /monaco/,- /scenes\/insights\/filters\/ActionFilter/,- /lib\/components\/CodeSnippet/,- /scenes\/session-recordings\/player/,- /queries\/schema-guard/,- /queries\/schema.json/,- /queries\/QueryEditor\/QueryEditor/,- /scenes\/billing/,- /scenes\/data-warehouse/,- /LineGraph/,- ...deniedThirdPartyPackages,-]+// PayGateMini (shipped in the toolbar) imports scenes/billing, which we can't bundle because it+// pulls in chart.js, monaco, and the rest of the app's billing scene graph.+const deniedPatterns = [/scenes\/billing/]/*** The toolbar shares lib/ code with the main app, and that code reaches app-only modules@@ -78,11 +61,10 @@ const deniedPatterns = [* contracts, and the parity-tested urls duplicate). These are intentional injection points:* the toolbar genuinely needs different answers (its own team context, no scene routing)* than the app.- * - Denied modules get replaced with an inert proxy. Every deny is load-bearing: without them- * PayGateMini pulls in scenes/billing (re-inlining the app scene graph), and even with- * billing denied the lib-zone paths (CodeSnippet -> monaco, Sparkline/LineGraph -> chart.js,- * the replay player, the query schema) balloon the eager set. A deny can only be retired- * once its import path is cut at the source.+ * - Denied modules get replaced with an inert proxy. The deny list is kept minimal: only the+ * paths a toolbar-shipped module actually reaches today (chiefly PayGateMini -> scenes/billing)+ * need cutting here. Regressions that reintroduce heavier dependencies are caught by the guard+ * scripts rather than pre-emptively denied.** The enforced invariants live in bin/check-toolbar-size.mjs (eager-chunk budget, per-file* CloudFront limit), bin/check-toolbar-graph.mjs (boundary edges, forbidden packages, source