: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
fix(toolbar): cut the accidental LemonToast and LemonTable eager chains (#69143)
Rafael Audibertca639cd3f41e
diff --git a/.agents/toolbar-migration.md b/.agents/toolbar-migration.mdindex d3f821ee8c35..77cdfa838a0e 100644--- a/.agents/toolbar-migration.md+++ b/.agents/toolbar-migration.md@@ -4,7 +4,7 @@ This file is the committed source of truth for the toolbar bundle modernization## Status-- **Current step**: Steps 1–4 and 7 implemented and in review as a Graphite stack (drafts), plus a seventh PR batching the simple Step 5/6 moves (PanelSettings, UrlMatchingHints, KeyboardShortcut, LemonMarkdown mermaid barrel — baseline 31 → 25) an eighth cutting the preflight + web-analytics-achievements edges (baseline 25 → 18), a ninth moving themeLogic/dataThemeLogic to `lib/logic/` (baseline 18 → 12), and a tenth inverting Link→DraggableToNotebook with the `useLinkDrag` DI seam (baseline 12 → 11). A lint-guard PR (#69133) sits at the bottom of the stack (oxlint exhaustive-deps suppressions where `--fix-dangerously` corrupted files). Next: the Step 7 eager-logic audit, then Step 8 (riskiest, last). The remaining survey-labels/taxonomy/experiments/product-tours edges are candidates for documented intentional seams rather than cuts.+- **Current step**: Steps 1–4 and 7 implemented and in review as a Graphite stack (drafts), plus a seventh PR batching the simple Step 5/6 moves (PanelSettings, UrlMatchingHints, KeyboardShortcut, LemonMarkdown mermaid barrel — baseline 31 → 25) an eighth cutting the preflight + web-analytics-achievements edges (baseline 25 → 18), a ninth moving themeLogic/dataThemeLogic to `lib/logic/` (baseline 18 → 12), and a tenth inverting Link→DraggableToNotebook with the `useLinkDrag` DI seam (baseline 12 → 11). A lint-guard PR (#69133) sits at the bottom of the stack (oxlint exhaustive-deps suppressions where `--fix-dangerously` corrupted files). An eleventh PR completed the Step 7 eager audit (LemonToast and LemonTable accidental chains cut — eager 1.88 → 1.54 MB, baseline 11 → 10, `eventUsageLogic` out of the toolbar graph entirely). Next: Step 8 (riskiest, last). The remaining survey-labels/taxonomy/experiments/product-tours edges are candidates for documented intentional seams rather than cuts.- **Last updated**: 2026-07-07- **PRs**: Step 1 — `rafa/toolbar-migration-1-graph-guard` (#69045); Step 3 — `rafa/toolbar-migration-2-products-urls-split` (#69071); chain cuts + shim-leak fix — `rafa/toolbar-migration-3-shim-leak-and-chain-cuts` (#69088); Step 2 — `rafa/toolbar-migration-4-loader-esm-splitting` (#69093); Step 4 — `rafa/toolbar-migration-5-types-replay-shared-cut` (#69106); Step 7 — `rafa/toolbar-migration-6-lazy-menus` (#69113); Step 5/6 batch — `rafa/toolbar-migration-7-simple-edge-cuts` (#69122) (each stacked on the previous)- **Reorder note (resolved)**: a trial Step 2 build emitted **487 dead chunks** — with `products.tsx` reachable, every product scene's dynamic import becomes a real chunk in `dist/toolbar/`. The gate was: flip the format only once `products.tsx` leaves the graph. That's now done via two moves in the third PR. First, the remaining chains all funneled through one root cause: the kea shims only matched exact alias strings (`scenes/teamLogic`), so relative imports (`dataThemeLogic` → `./teamLogic`) and `~/`-prefixed imports pulled the REAL logics and their whole app graph — fixed with relative + `~/` matching in `createToolbarModulePlugin`, disconnecting `products.tsx`, `scenes.ts`, `teamLogic`, `PersonDisplay`, and `experimentsLogic` in one move. Second, `scenes/urls` itself (imported by lib components shared with the app) is shimmed to the toolbar's parity-tested `~/toolbar/urls` duplicate from Step 3, taking the last products-manifest path out. Bundle graph 8448 → ~1000 files (99 → ~13.5 MiB source), shipped `dist/toolbar.js` 9.95 MB → ~4 MB (was just under the 10 MB CloudFront cliff). Graph budget ratcheted 110 MB → 18 MB.@@ -120,7 +120,7 @@ Approach (revised on review): rather than restructuring the generated products m- [x] `productToursLogic` imports `generateStepHtml` (tiptap/prosemirror/highlight.js, ~500KB) dynamically via a memoized `retryImport` — only fetched when a tour is edited/previewed; the two draft-compare subscriptions became async (module-cache awaits preserve call order after first load)- [x] Eager budget ratcheted 3.05 MB → 2.1 MB (measured 1,905,558 — eager JS down 31%, deferred now 1.93 MB ≈ 50% of app JS)- [x] New guard in `check-toolbar-size.mjs`: every CSS input in any chunk stylesheet must also be in the entry stylesheet (the only one the shadow root loads) — fails the build if a lazy feature's styles would silently never render. Watch out: with splitting, every dynamic-import target carries `entryPoint` in the metafile; use `findEntryOutput`-- [ ] Audit eagerly-mounted per-tab logics (e.g. `webVitalsToolbarLogic.mount()` in `ToolbarApp.tsx`, `actionsLogic` via toolbarLogic dragging fuse.js) — keep a slim eager core where background collection is deliberate+- [x] Eager-set audit (traced with a metafile BFS from the entry): the two accidental chains were (1) `LemonToast` → `incidentStatusLogic` → superpowers → MCP hint → `eventUsageLogic` → the 224 KB taxonomy JSON — LemonToast only needed the status string + status-page URL, now in leaf `lib/components/HelpMenu/incidentStatus.ts`; and (2) `LemonTable` → `columnUtils` (whose column factories render `TZLabel`) → `eventUsageLogic` — the pure layout helpers LemonTable actually uses moved to `columnLayoutUtils.ts`. Eager JS 1.88 → 1.54 MB (−18%), budget ratcheted 2.1 → 1.7 MB, and `eventUsageLogic` left the toolbar graph entirely (−25 files, one more baseline edge deleted). Both fixes also slim the main app/exporter entries. Deliberately KEPT eager: posthog-js via `toolbarPosthogJS` (toolbar telemetry), `webVitalsToolbarLogic.mount()` (background collection), and the per-feature logic connects in `toolbarLogic` (menu-button loading spinners; drags fuse.js ~24 KB — not worth an async seam)### Step 8 — tree-shaking enablers + cleanup (highest breakage risk; last)diff --git a/frontend/bin/check-toolbar-size.mjs b/frontend/bin/check-toolbar-size.mjsindex 8db96d68ce10..104c4d2779f3 100644--- a/frontend/bin/check-toolbar-size.mjs+++ b/frontend/bin/check-toolbar-size.mjs@@ -18,7 +18,7 @@ const MAX_FILE_BYTES = 10_000_000// budget to lock it in; raise it only as a conscious, reviewed decision in the PR that needs it.// 2026-07-07: 2,967,721 bytes measured when splitting landed; 2,764,847 after the// replay-shared cut; 1,905,558 after the lazy menu boundaries; ~10% headroom.-const MAX_EAGER_BYTES = 2_100_000+const MAX_EAGER_BYTES = 1_700_000// 3. The loader is injected on every customer page that enables the toolbar and must stay tiny.// 2026-07-07: 1,153 bytes minified.diff --git a/frontend/bin/toolbar-graph-baseline.json b/frontend/bin/toolbar-graph-baseline.jsonindex ddbdff196b23..8b535898353f 100644--- a/frontend/bin/toolbar-graph-baseline.json+++ b/frontend/bin/toolbar-graph-baseline.json@@ -2,7 +2,6 @@"//": "Toolbar -> app-zone import edges that exist today, enforced by bin/check-toolbar-graph.mjs. Do not add entries; delete them as the migration (.agents/toolbar-migration.md) cuts each edge.","edges": ["src/lib/components/PropertyKeyInfo.tsx -> src/scenes/surveys/surveyQuestionLabelsLogic.ts",- "src/lib/utils/eventUsageLogic.ts -> src/scenes/product-tours/constants.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",diff --git a/frontend/src/lib/components/HelpMenu/incidentStatus.ts b/frontend/src/lib/components/HelpMenu/incidentStatus.tsnew file mode 100644index 000000000000..8e65b24e9e1a--- /dev/null+++ b/frontend/src/lib/components/HelpMenu/incidentStatus.ts@@ -0,0 +1,21 @@+// Leaf module for the incident status shared between incidentStatusLogic (which polls the+// status page and writes here) and LemonToast (which reads it to decorate error toasts).+// Deliberately logic-free: LemonToast is imported by virtually every bundle, and importing+// the full incidentStatusLogic from it would drag the help-menu/superpowers/MCP-hint graph+// (including eventUsageLogic and the taxonomy JSON) into all of them.++export type NormalizedStatus = 'operational' | 'degraded_performance' | 'partial_outage' | 'major_outage'++export const STATUS_PAGE_BASE = 'https://www.posthogstatus.com'++export const DEFAULT_STATUS: NormalizedStatus = 'operational'++let currentStatus: NormalizedStatus = DEFAULT_STATUS++export function setIncidentStatus(status: NormalizedStatus): void {+ currentStatus = status+}++export function getIncidentStatus(): NormalizedStatus {+ return currentStatus+}diff --git a/frontend/src/lib/components/HelpMenu/incidentStatusLogic.tsx b/frontend/src/lib/components/HelpMenu/incidentStatusLogic.tsxindex 394f35c957c7..3956efbb17ae 100644--- a/frontend/src/lib/components/HelpMenu/incidentStatusLogic.tsx+++ b/frontend/src/lib/components/HelpMenu/incidentStatusLogic.tsx@@ -8,6 +8,7 @@ import { preflightLogic } from 'lib/logic/preflightLogic'import { Region } from '~/types'+import { NormalizedStatus, STATUS_PAGE_BASE, setIncidentStatus } from './incidentStatus'import type { incidentStatusLogicType } from './incidentStatusLogicType'// Raw status page API types@@ -16,8 +17,9 @@ export type Impact = 'partial_outage' | 'degraded_performance' | 'full_outage'export type IncidentStatus = 'investigating' | 'identified' | 'monitoring'export type MaintenanceStatus = 'maintenance_in_progress' | 'maintenance_scheduled'-// Normalized status for display-export type NormalizedStatus = 'operational' | 'degraded_performance' | 'partial_outage' | 'major_outage'+// The normalized display status and its shared read/write module live in ./incidentStatus, a+// deliberate leaf so LemonToast can read the status without importing this logic's graph.+export { getIncidentStatus, setIncidentStatus, STATUS_PAGE_BASE, type NormalizedStatus } from './incidentStatus'export interface AffectedComponent {id: string@@ -66,11 +68,8 @@ export interface ComponentIncidentAlert {severity: 'warning' | 'error'}-export const STATUS_PAGE_BASE = 'https://www.posthogstatus.com'const REFRESH_INTERVAL = 60 * 1000 * 5 // 5 minutes-const DEFAULT_STATUS: NormalizedStatus = 'operational'-// A failed `fetch` to an external host throws a `TypeError` ("Failed to fetch", "NetworkError when// attempting to fetch resource", "Load failed", ...). These are expected and outside our control —// ad blockers, tracking-protection extensions, DNS hiccups, brief status-page outages — so they're@@ -80,16 +79,6 @@ function isNetworkError(error: unknown): boolean {return error instanceof TypeError}-let currentStatus: NormalizedStatus = DEFAULT_STATUS--export function setIncidentStatus(status: NormalizedStatus): void {- currentStatus = status-}--export function getIncidentStatus(): NormalizedStatus {- return currentStatus-}-// incident.io component name for the PostHog AI service. An incident is treated as affecting AI only// when it tags a component with this exact name under the current region's group (see getRelevantGroupName).export const AI_COMPONENT_NAME = 'PostHog AI'diff --git a/frontend/src/lib/hooks/useColumnWidths.ts b/frontend/src/lib/hooks/useColumnWidths.tsindex 8fe30752da6a..cab72b9ddb49 100644--- a/frontend/src/lib/hooks/useColumnWidths.ts+++ b/frontend/src/lib/hooks/useColumnWidths.ts@@ -1,7 +1,7 @@import { useCallback, useEffect, useRef, useState } from 'react'-import { DEFAULT_COLUMN_WIDTH } from '../lemon-ui/LemonTable/columnUtils'-import { determineColumnKey } from '../lemon-ui/LemonTable/columnUtils'+import { DEFAULT_COLUMN_WIDTH } from '../lemon-ui/LemonTable/columnLayoutUtils'+import { determineColumnKey } from '../lemon-ui/LemonTable/columnLayoutUtils'import { LemonTableColumn } from '../lemon-ui/LemonTable/types'interface UseColumnWidthsProps {diff --git a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsxindex 3276e0c36753..74ca39e63fce 100644--- a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx+++ b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx@@ -18,7 +18,7 @@ import { useColumnWidths } from '../../hooks/useColumnWidths'import { PaginationAuto, PaginationControl, PaginationManual, usePagination } from '../PaginationControl'import { Tooltip } from '../Tooltip'import { BulkSelectionBar } from './BulkSelectionBar'-import { determineColumnKey, getStickyColumnInfo } from './columnUtils'+import { determineColumnKey, getStickyColumnInfo } from './columnLayoutUtils'import { LemonTableLoader } from './LemonTableLoader'import { Sorting, SortingIndicator, getNextSorting } from './sorting'import { TableRow } from './TableRow'diff --git a/frontend/src/lib/lemon-ui/LemonTable/TableRow.tsx b/frontend/src/lib/lemon-ui/LemonTable/TableRow.tsxindex 2c6fb7fa8049..79644eef378f 100644--- a/frontend/src/lib/lemon-ui/LemonTable/TableRow.tsx+++ b/frontend/src/lib/lemon-ui/LemonTable/TableRow.tsx@@ -6,7 +6,7 @@ import { IconCollapse, IconExpand } from '@posthog/icons'import { LemonButton } from 'lib/lemon-ui/LemonButton'import { More } from 'lib/lemon-ui/LemonButton/More'-import { getStickyColumnInfo } from './columnUtils'+import { getStickyColumnInfo } from './columnLayoutUtils'import { ExpandableConfig, LemonTableColumn, LemonTableColumnGroup, TableCellRepresentation } from './types'export interface TableRowProps<T extends Record<string, any>> {diff --git a/frontend/src/lib/lemon-ui/LemonTable/columnLayoutUtils.ts b/frontend/src/lib/lemon-ui/LemonTable/columnLayoutUtils.tsnew file mode 100644index 000000000000..533b35a7e14f--- /dev/null+++ b/frontend/src/lib/lemon-ui/LemonTable/columnLayoutUtils.ts@@ -0,0 +1,90 @@+// Pure column-layout helpers used by LemonTable internals. Kept separate from+// columnUtils.tsx, whose column factories render TZLabel/ProfilePicture and would+// otherwise drag that graph (including eventUsageLogic and the taxonomy JSON) into+// every bundle that renders a LemonTable.+import { LemonTableColumn } from './types'++export const DEFAULT_COLUMN_WIDTH = 120++interface PinnedColumnInfo {+ isSticky: boolean+ leftPosition: number+}++/**+ * Get the pinned column info+ * @param columnKey - The key of the column+ * @param stickyColumns - The pinned columns+ * @param stickyColumnWidths - The widths of the pinned columns+ * @param allColumns - All the columns+ * @returns The pinned column info+ * example:+ * getStickyColumnInfo(+ * 'source',+ * ['source', 'campaign'],+ * [100, 200],+ * [+ * { key: 'campaign', dataIndex: 'campaign' },+ * { key: 'source', dataIndex: 'source' },+ * ]+ * ) -> {+ * isSticky: true,+ * leftPosition: 100+ * }+ */+export function getStickyColumnInfo<T extends Record<string, any>>(+ columnKey: string,+ stickyColumns: string[] | undefined,+ stickyColumnWidths: number[] | undefined,+ allColumns: LemonTableColumn<T, any>[] | undefined+): PinnedColumnInfo {+ if (!stickyColumns?.length) {+ return { isSticky: false, leftPosition: 0 }+ }++ const isSticky = stickyColumns.includes(columnKey)++ if (!isSticky || !allColumns) {+ return { isSticky, leftPosition: 0 }+ }++ const columnPositionMap = new Map<string, number>()+ allColumns.forEach((col, index) => {+ const key = col.key ?? col.dataIndex+ if (key) {+ columnPositionMap.set(key, index)+ }+ })++ const columnIndex = columnPositionMap.get(columnKey) ?? -1++ // Calculate left position for pinned column+ let leftPosition = 0+ if (stickyColumnWidths) {+ for (let i = 0; i < stickyColumns.length; i++) {+ const key = stickyColumns[i]+ const keyIndex = columnPositionMap.get(key) ?? -1+ if (keyIndex >= 0 && keyIndex < columnIndex) {+ const width = stickyColumnWidths[i]+ leftPosition += width && width > 0 ? width : DEFAULT_COLUMN_WIDTH+ }+ }+ }++ return { isSticky, leftPosition }+}++/**+ * Determine the column's key, using `dataIndex` as fallback.+ * If `obligationReason` is specified, will throw an error if the key can't be determined.+ */+export function determineColumnKey(column: LemonTableColumn<any, any>, obligationReason: string): string+export function determineColumnKey(column: LemonTableColumn<any, any>, obligationReason?: undefined): string | null+export function determineColumnKey(column: LemonTableColumn<any, any>, obligationReason?: string): string | null {+ const columnKey = column.key || column.dataIndex+ if (obligationReason && columnKey == null) {+ // == is intentional to catch undefined too+ throw new Error(`Column \`key\` or \`dataIndex\` must be defined for ${obligationReason}`)+ }+ return columnKey+}diff --git a/frontend/src/lib/lemon-ui/LemonTable/columnUtils.tsx b/frontend/src/lib/lemon-ui/LemonTable/columnUtils.tsxindex 1311408f6d7d..17072c5f99ae 100644--- a/frontend/src/lib/lemon-ui/LemonTable/columnUtils.tsx+++ b/frontend/src/lib/lemon-ui/LemonTable/columnUtils.tsx@@ -7,6 +7,11 @@ import { LemonTag } from '../LemonTag'import { ProfilePicture } from '../ProfilePicture'import { LemonTableColumn } from './types'+// Moved to a render-free leaf so LemonTable internals can use them without importing+// this file's column factories (and their TZLabel/eventUsageLogic graph); re-exported+// here for existing importers.+export { DEFAULT_COLUMN_WIDTH, determineColumnKey, getStickyColumnInfo } from './columnLayoutUtils'+export function atColumn<T extends Record<string, any>>(key: keyof T,title: string,@@ -80,88 +85,3 @@ export function statusColumn<T extends { enabled: boolean }>(): LemonTableColumnsorter: (a, b) => Number(b.enabled) - Number(a.enabled),}}--export const DEFAULT_COLUMN_WIDTH = 120--interface PinnedColumnInfo {- isSticky: boolean- leftPosition: number-}--/**- * Get the pinned column info- * @param columnKey - The key of the column- * @param stickyColumns - The pinned columns- * @param stickyColumnWidths - The widths of the pinned columns- * @param allColumns - All the columns- * @returns The pinned column info- * example:- * getStickyColumnInfo(- * 'source',- * ['source', 'campaign'],- * [100, 200],- * [- * { key: 'campaign', dataIndex: 'campaign' },- * { key: 'source', dataIndex: 'source' },- * ]- * ) -> {- * isSticky: true,- * leftPosition: 100- * }- */-export function getStickyColumnInfo<T extends Record<string, any>>(- columnKey: string,- stickyColumns: string[] | undefined,- stickyColumnWidths: number[] | undefined,- allColumns: LemonTableColumn<T, any>[] | undefined-): PinnedColumnInfo {- if (!stickyColumns?.length) {- return { isSticky: false, leftPosition: 0 }- }-- const isSticky = stickyColumns.includes(columnKey)-- if (!isSticky || !allColumns) {- return { isSticky, leftPosition: 0 }- }-- const columnPositionMap = new Map<string, number>()- allColumns.forEach((col, index) => {- const key = col.key ?? col.dataIndex- if (key) {- columnPositionMap.set(key, index)- }- })-- const columnIndex = columnPositionMap.get(columnKey) ?? -1-- // Calculate left position for pinned column- let leftPosition = 0- if (stickyColumnWidths) {- for (let i = 0; i < stickyColumns.length; i++) {- const key = stickyColumns[i]- const keyIndex = columnPositionMap.get(key) ?? -1- if (keyIndex >= 0 && keyIndex < columnIndex) {- const width = stickyColumnWidths[i]- leftPosition += width && width > 0 ? width : DEFAULT_COLUMN_WIDTH- }- }- }-- return { isSticky, leftPosition }-}--/**- * Determine the column's key, using `dataIndex` as fallback.- * If `obligationReason` is specified, will throw an error if the key can't be determined.- */-export function determineColumnKey(column: LemonTableColumn<any, any>, obligationReason: string): string-export function determineColumnKey(column: LemonTableColumn<any, any>, obligationReason?: undefined): string | null-export function determineColumnKey(column: LemonTableColumn<any, any>, obligationReason?: string): string | null {- const columnKey = column.key || column.dataIndex- if (obligationReason && columnKey == null) {- // == is intentional to catch undefined too- throw new Error(`Column \`key\` or \`dataIndex\` must be defined for ${obligationReason}`)- }- return columnKey-}diff --git a/frontend/src/lib/lemon-ui/LemonToast/LemonToast.tsx b/frontend/src/lib/lemon-ui/LemonToast/LemonToast.tsxindex 6d52c2e09153..2a483305b667 100644--- a/frontend/src/lib/lemon-ui/LemonToast/LemonToast.tsx+++ b/frontend/src/lib/lemon-ui/LemonToast/LemonToast.tsx@@ -3,7 +3,7 @@ import { toast, type ToastOptions } from 'react-toastify'import { IconCheckCircle, IconInfo, IconWarning, IconX } from '@posthog/icons'-import { getIncidentStatus, STATUS_PAGE_BASE } from 'lib/components/HelpMenu/incidentStatusLogic'+import { getIncidentStatus, STATUS_PAGE_BASE } from 'lib/components/HelpMenu/incidentStatus'import { isChristmas } from 'lib/holidays'import { hashCodeForString } from 'lib/utils/strings'