: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): ratchet budgets and document the deny layer as load-bearing (#69147)
Rafael Audibert0cedafc5e650
diff --git a/.agents/toolbar-migration.md b/.agents/toolbar-migration.mdindex 77cdfa838a0e..dc172b3139a7 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). 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.+- **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), and a twelfth did the Step 8 cleanup half (ratchets, deny audit — all denies proven load-bearing — and the rewritten toolbar-config rationale). The ONLY remaining item is the `sideEffects` flip, deliberately last: land it as its own PR after the stack merges, with storybook/e2e verification. 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.@@ -124,8 +124,8 @@ Approach (revised on review): rather than restructuring the generated products m### Step 8 — tree-shaking enablers + cleanup (highest breakage risk; last)-- [ ] Add `"sideEffects"` to `frontend/package.json` + lemon-ui package: `**/*.scss`, `**/*.css`, entrypoints, `src/toolbar/patch.ts`, kea plugin/registration modules (`src/kea-disposables.ts`), anything touching `window` at import. NOTE: the `@posthog/lemon-ui` barrel imports `global.scss` on line 1 — must be listed or styles vanish. Verify with storybook/e2e-- [ ] Ratchet budgets to the new floor; drop remaining redundant `deniedThirdPartyPackages` entries one at a time; rewrite the `toolbar-config.mjs` comment (rationale is now the eager-chunk budget, not the 10MB cliff); delete shims replaced by DI seams, document the rest as intentional injection points+- [ ] Add `"sideEffects"` to `frontend/package.json` + lemon-ui package: `**/*.scss`, `**/*.css`, entrypoints, `src/toolbar/patch.ts`, kea plugin/registration modules (`src/kea-disposables.ts`), anything touching `window` at import (including `scenes/App.tsx`'s `registerNotebookLinkDrag()` call site — it's an explicit bootApp call so it survives, but audit anyway). NOTE: the `@posthog/lemon-ui` barrel imports `global.scss` on line 1 — must be listed or styles vanish. Verify with storybook/e2e. **Land this after the rest of the stack merges** — it's the highest-breakage-risk change and shouldn't sit under anything+- [x] Ratchets + deny audit + docs: graph budget 15.5 MB → 14.8 MB (`14_800_000` bytes = 14.11 MiB as the guard reports it; measured 13.80 MiB, so ~0.3 MiB headroom), eager already at 1.7 MB. Deny-retirement audit ran empirically: removing ALL denies re-inlines 125.58 MiB (11,365 files) via `PayGateMini → scenes/billing`; with billing still denied, the lib-zone paths (CodeSnippet → monaco, Sparkline/LineGraph → chart.js, replay player, query schema) push eager 1.5 → 8.8 MB. So every deny is load-bearing — none deleted; findings recorded in the rewritten `toolbar-config.mjs` header comment, which now explains the shims as intentional injection points and points at the three guard scripts. No shims are DI-replaced yet (useLinkDrag replaced a direct import, not a shim)### Flagged — needs product decision (not blocking)diff --git a/frontend/bin/check-toolbar-graph.mjs b/frontend/bin/check-toolbar-graph.mjsindex c4c639a2b98a..dc82ebfba35e 100644--- a/frontend/bin/check-toolbar-graph.mjs+++ b/frontend/bin/check-toolbar-graph.mjs@@ -43,7 +43,7 @@ const FORBIDDEN_PACKAGES = [// 2026-07-07: 13.95 MiB of source input reachable (1042 files) after the shim-leak fix took// the app scene graph out of the bundle; 13.40 MiB (1010 files) after the replay-shared cut.// Headroom for churn, but any reintroduced leak jumps back to ~100 MiB and fails loudly.-const TOTAL_INPUT_BYTES_BUDGET = 15_500_000+const TOTAL_INPUT_BYTES_BUDGET = 14_800_000function fail(message) {console.error(`\n❌ ${message}`)diff --git a/frontend/toolbar-config.mjs b/frontend/toolbar-config.mjsindex 27e7dda2ddbc..bdd629e2c96e 100644--- a/frontend/toolbar-config.mjs+++ b/frontend/toolbar-config.mjs@@ -78,17 +78,25 @@ const deniedPatterns = []/**- * The toolbar includes many parts of the main posthog app,- * but we don't want to include everything in the toolbar bundle.- * Partly because it would be too big, and partly because some things- * in the main app cause problems for people using CSPs on their sites.+ * The toolbar shares lib/ code with the main app, and that code reaches app-only modules+ * the toolbar must not ship: no tree shaking rescues it (no sideEffects annotations yet),+ * and app code shouldn't contort itself for the toolbar. So imports are replaced at+ * resolve time:*- * It wasn't possible to tree-shake the dependencies out of the bundle,- * and we don't want to change the app code significantly just for the toolbar.+ * - Shimmed modules get swapped for lightweight stand-ins (kea logics satisfying connect()+ * contracts, and the parity-tested urls duplicate). These are intentional injection+ * points, not tech debt — 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 (verified+ * empirically, 2026-07): removing them all re-inlines 125 MiB of source via+ * PayGateMini -> scenes/billing, and even with billing still denied the lib-zone paths+ * (CodeSnippet -> monaco, Sparkline/LineGraph -> chart.js, replay player, query schema)+ * push the eager set from 1.5 MB to 8.8 MB. Retiring a deny requires first cutting its+ * import path at the source (.agents/toolbar-migration.md).*- * So instead we replace some imports in the toolbar:- * - Shimmed modules get swapped for lightweight kea logics (needed by connect())- * - Denied modules get replaced with an inert proxy+ * 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+ * budget), and bin/check-toolbar-csp-eval.mjs (no eval on customer pages).*/function createToolbarModulePlugin(dirname) {// Shims must also catch relative imports of the same modules (e.g. dataThemeLogic's