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(toolbar): retire migration tracker and its narrative (#69481)

Rafael Audibert0c54999f1ef3
diff --git a/.agents/toolbar-migration.md b/.agents/toolbar-migration.md
deleted file mode 100644
index dc172b3139a7..000000000000
--- a/.agents/toolbar-migration.md
+++ /dev/null
@@ -1,144 +0,0 @@
-# Toolbar bundle migration tracker
-
-This file is the committed source of truth for the toolbar bundle modernization (single-file IIFE → classic-script loader + code-split ESM, plus import-graph untangling). Agents and humans working on it: read this first, work the steps **in order**, and in every PR update the Status block and tick the boxes you completed. Keep edits to this file inside the same PR as the work they describe.
-
-## 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), 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.
-- **posthog-js prerequisite**: DONE — release pipeline is layout-agnostic and verified as a no-op against today's build. Nothing blocks any step. See Step 0 for the constraints it imposes on the build here.
-
-## Why
-
-The toolbar (`frontend/src/toolbar/`, entry `frontend/src/toolbar/index.tsx`) is built as a single IIFE (`frontend/toolbar-config.mjs`), which force-inlines all 157 dynamic `import()`s in its graph, and it imports the main app — `scenes/urls.ts:5` pulls `~/products` (every product manifest), `~/types` has runtime imports (`lib/Chart`, `lib/api`, an `hls.js`-dragging re-export). Tree shaking can't rescue it (no `sideEffects` fields), so `toolbar-config.mjs` keeps hand-curated denylists + kea shims (`frontend/src/toolbar/shims/`) — which leaked until the third PR (`scenes/dataThemeLogic.tsx` imports `./teamLogic` relatively, bypassing the then-exact-string shim; fixed by matching relative and `~/` imports too). Before that fix the bundle sat just under the 10MB CloudFront gzip cliff (`frontend/bin/check-toolbar-size.mjs`); it now ships at ~4.06 MB.
-
-Measured from `frontend/toolbar-esbuild-meta.json` (dev bytes; prod ≈ dev × 0.42):
-
-- 6.43MB of 22.17MB is reachable only via existing `import()`s → defers with zero source changes once splitting lands.
-- ~50 import edges cross from toolbar/lib into the app zone; cutting ~33 of them → 8.62MB dev (−61%).
-- Single edge cuts often save ~0 bytes (redundant paths); the per-step metric is the guard's shrinking allowlist, not bytes.
-
-End state: ~1-2KB loader, enforced eager-chunk budget, every chunk far under 10MB, denylist reduced to documented seams, `check-toolbar-graph.mjs` preventing regression.
-
-## Compatibility model (do not break this)
-
-posthog-js (all versions, forever) injects a **classic** `<script crossOrigin="anonymous">` for `toolbar.js` and on `load` calls `window.ph_load_toolbar(params, posthog)` (fallback `ph_load_editor`). The loader must keep that contract exactly; chunk loading is internal via `import()` relative to `document.currentScript.src`. Consequences:
-
-- Old SDKs on the default unversioned `/static/toolbar.js` get the split toolbar transparently (better: smaller eager fetch).
-- Old SDK versions on the versioned CDN (`strict_script_versioning`) keep their pinned single-file builds untouched forever.
-- New SDK releases publish the split layout into new pinned dirs — the posthog-js publish step is already layout-agnostic (Step 0).
-- `window.posthogToolbarController` is public surface — the loader must expose a forwarding stub synchronously.
-- No eval / `new Function` anywhere new (customer CSPs; `frontend/bin/check-toolbar-csp-eval.mjs`).
-
-## Steps
-
-Work one step per PR (Graphite stack via `gt`; keep the stack shallow — merge the base before extending; batch pushes). Every PR: run the verification commands at the bottom and update Status.
-
-### Step 0 — posthog-js prerequisite (external repo) — DONE
-
-- [x] Requirements doc written and handed off with the posthog-js change (originally drafted here as `POSTHOG_JS_TOOLBAR_REQUIREMENTS.md`; it now lives with the posthog-js work)
-- [x] posthog-js release pipeline is layout-agnostic: `collectReleaseAssets()` (`tooling/release/src/upload-posthog-js-s3.ts`) recursively publishes `dist/toolbar/` when present, with explicit content types (`.js` → `application/javascript` — ESM chunks are strict-MIME CORS fetches) and `max-age=31536000, immutable`, at the versioned, major-alias, AND compatibility prefixes; the `build-toolbar` job in `release.yml` accepts an unhashed canonical `toolbar.js`/`toolbar.css`, greps `toolbar/` too for `TOOLBAR_PUBLIC_PATH`, strips source maps inside `toolbar/`, and uploads `frontend/dist/toolbar` (missing dir = warn). Covered by an end-to-end test (`upload-posthog-js-s3.test.ts`). Verified as a no-op against today's single-file build.
-
-**Constraints this imposes on Step 2** (design already matches; do not drift):
-
-- The loader must be emitted as unhashed canonical `dist/toolbar.js` (their normalize step expects it).
-- Keep the `__POSTHOG_TOOLBAR_PUBLIC_PATH__` define present in the shipped app output (their verify step greps `toolbar.js` + `toolbar/` for it; it remains the runtime CSS URL mechanism).
-- Chunk resolution must stay relative to `document.currentScript.src` / the importing module — never absolute — because the same artifacts are served from the versioned, major-alias, and compatibility prefixes.
-- Don't rely on source maps being served next to chunks on the versioned CDN (they're stripped there).
-
-### Step 1 — boundary guard (so later steps ratchet)
-
-- [x] Commit this tracker
-- [x] New `frontend/bin/check-toolbar-graph.mjs` reading `frontend/toolbar-esbuild-meta.json`. It computes the "survivor" closure (reachable from `src/toolbar/index.tsx` without walking into the app zone: `src/products*`, `src/scenes/**`, `src/layout/**`, `src/models/**`, `products/**`) and fails on (a) any survivor → app-zone edge not in the checked-in baseline `frontend/bin/toolbar-graph-baseline.json` (47 edges on 2026-07-07), (b) baseline entries that no longer exist (delete them to ratchet), (c) denied packages (`monaco-editor`, `chart.js`, `mermaid`, `hls.js`) present anywhere in the graph, (d) total source input bytes over budget (99.74 MiB measured, 104.9 MiB budget)
-- [x] oxlint: `frontend/src/toolbar/**` override in `.oxlintrc.json` with `no-restricted-imports` (scenes/products/layout/models patterns with today's imports as explicit `!` exceptions; `lib/api` value imports). Lint is fast feedback; the metafile check is the source of truth
-- [x] Wire into `.github/workflows/ci-frontend.yml` next to `check-toolbar-size` (runs against the PR's own metafile, before the base rebuild overwrites it)
-
-Done when: CI runs the graph check green with the baseline allowlist.
-
-### Step 2 — loader + ESM code splitting (in review: `rafa/toolbar-migration-4-loader-esm-splitting`)
-
-Landed layout: `dist/toolbar.js` (1.2KB classic loader) + `dist/toolbar/` (ESM entry `toolbar-app-<hash>.js`, hashless fallback `toolbar-app.js`, `chunk-*-<hash>.js`, per-chunk CSS, `toolbar-app.css` hashless entry CSS loaded into the shadow root, `assets/` fonts) + `dist/toolbar.css` (transition-window copy for stale-cached single-file toolbar.js only).
-
-- [x] `frontend/toolbar-config.mjs`: `getToolbarAppBuildConfig` (ESM, `splitting: true`, outdir `dist/toolbar`, per-file `var define = undefined;` banner) + `finalizeToolbarBuild` (hashless copies, CSS promotion, loader build with `__POSTHOG_TOOLBAR_APP_ENTRY__` baked in), wired into `frontend/build.mjs` and `frontend/bin/build-toolbar.mjs` (dev watch mode verified)
-- [x] **`publicPath` must stay unset on the app build** (explicit `publicPath: undefined` to override commonConfig's `/static`): esbuild bakes publicPath into chunk import specifiers as absolute URLs, which breaks serving the same artifacts from any region/self-hosted/CDN prefix. Chunk imports are relative; svgs inline as data URLs (a relative specifier string would resolve against the customer page URL); font url()s in the CSS are relative and resolve because the CSS is fetched from inside `dist/toolbar/` (`ToolbarApp.tsx` now loads `toolbar/toolbar-app.css`). Bonus: retires the hardcoded `us.posthog.com` asset URLs (EU used to load fonts from US)
-- [x] `frontend/src/toolbar/loader.ts`: classic-script contract kept (`ph_load_toolbar`/`ph_load_editor`/controller stub synchronously); import with retry/backoff; hashless `toolbar-app.js?t={5-min bucket}` fallback; degrade to no-toolbar with console.warn
-- [x] `frontend/src/toolbar/index.tsx`: `export loadToolbar` + controller; window assigns kept for back-compat
-- [x] `check-toolbar-size.mjs` rewrite: per-file 10MB CloudFront limit across all outputs, eager-set budget 3.3MB (measured 2.97MB), loader <20KB (measured 1,153 bytes). Shared metafile helpers in `bin/toolbar-metafile.mjs`
-- [x] `check-toolbar-csp-eval.mjs` rewrite: scoped counts — loader 0, eager closure 1 (toolbarLogic probe), total 5 (4 pixi in lazy hedgehog chunks)
-- [x] Per-chunk CSS accepted (esbuild 0.25 emits it): only the entry CSS is loaded into the shadow root, so toolbar features must keep styles statically imported — verified all chunk-CSS inputs also land in the entry CSS; recheck at Step 7
-- [x] `buildInParallel` now logs callback errors before exiting (previously swallowed silently)
-- [x] Playwright smoke test (throwaway, not committed): static server over dist/ + strict CSP (`script-src 'self'`, no unsafe-eval) + classic-script injection exactly like posthog-js + `ph_load_toolbar` call → entry + 6 eager chunks fetched relative to the loader origin, shadow root mounts, controller stub delegates (`isLoaded` flips true), zero page errors
-- [x] Real-SDK smoke test (throwaway): published posthog-js (1.398.2 from node_modules, untouched) drives the whole flow — parses `#__posthog` authorize state, injects `/static/toolbar.js?v=&t=`, loader import()s the split app, shadow root mounts, controller live, zero page errors
-- [x] Local-stack click-through (Playwright driving `hogli up` at localhost:8010, throwaway script): real workspace via `/api/setup_test/`, authorized URL added, `redirect_to_site` → host page → toolbar mounts unauthenticated → full OAuth authorize flow (Authenticate → confirm modal → OAuth grant → redirect back) → `isAuthenticated: true` → all six feature menus open with real seeded data (heatmaps, actions, flags, event debugger, web vitals, experiments) → clicking Hedgehog mode fetches 10 pixi/hedgehog chunks on demand → styled bar renders from shadow-root CSS. Note: `redirect_to_site` no longer issues a `temporaryToken` — toolbar auth is OAuth now, so the unauthenticated first mount is expected behavior, not a regression
-- [x] `Toolbar.stories.tsx` verified locally against the full stack: all five Toolbar stories mount (shadow root + bar, no page errors) in `storybook dev`, plus feature-flags scene and exporter-funnel stories as products-split smoke. The CI visual-regression failure on #69088 was a job cancelled at its 60-minute timeout (infra), not a rendering break — re-run it when marking ready for review
-
-Result: 1.06MB (26%) of app JS deferred with zero source changes; every file far under the 10MB cliff (largest 1.77MB). Known-unsupported: exact-path CSP allowlists (`script-src .../toolbar.js`) — chunks need the directory allowed.
-
-### Step 3 — toolbar-owned `urls` duplicate (landed before Step 2, see reorder note)
-
-Approach (revised on review): rather than restructuring the generated products manifest so `scenes/urls` stops dragging it in, the toolbar gets its own deliberately duplicated `frontend/src/toolbar/urls.ts` with only the url helpers it links to, and a parity test keeps it honest. A first version of this PR split `products-urls.tsx` out of the generator; that was reverted as over-engineered — the duplicate + test is simpler to review and keeps the generator untouched.
-
-- [x] `frontend/src/toolbar/urls.ts`: the 12 helpers toolbar code uses (`action(s)`, `experiment(s)`, `featureFlag(s)`, `productTour`, `sessionProfile`, `settings`, `survey(s)`, `webAnalyticsWebVitals`), plus a documented `urlToResource` null stub (the real one walks a matcher tree built from every product manifest; its only toolbar-shipped consumer is Link's drag-to-notebook annotation, inert on customer pages)
-- [x] `frontend/src/toolbar/urls.test.ts`: parity test asserting each helper matches `scenes/urls` byte-for-byte over sample args (the test deliberately crosses the boundary — that's its job); a helper without samples fails
-- [x] All 11 toolbar files import `~/toolbar/urls`; their `-> src/scenes/urls.ts` baseline edges are deleted (47 → 36)
-- [x] The 3 lib files shipped in the toolbar (`TZLabel`, `HeatmapEventsPanel`, `Link`) still import `scenes/urls` — they're shared with the app and can't be repointed; the third PR's `scenes/urls` shim resolves them to the toolbar duplicate at build time, removing their edges and taking `scenes/urls` + the products manifest out of the toolbar graph entirely
-- [ ] Verify the app/exporter eager-graph improvements with the `check-eager-graph` owners
-
-### Step 4 — `~/types` hygiene (in review: `rafa/toolbar-migration-5-types-replay-shared-cut`)
-
-**Finding that shrank this step**: esbuild already erases imports whose specifiers are all type-position-only (they show as `external: true` in the metafile with no resolved edge), so the planned `import type` conversion and leaf-enum extraction were unnecessary for the bundle graph — `src/types.ts` had exactly ONE surviving runtime import: the `SnapshotSourceType` value re-export.
-
-- [x] `export { SnapshotSourceType }` → `export type { ... }` in `types.ts`; the three value-users (snapshotDataLogic + two player tests) import the enum from `@posthog/replay-shared` directly. Removes all 27 replay-shared files from the toolbar graph
-- [x] Retired the `hls.js` deny in `toolbar-config.mjs` (its only path in was replay-shared); reintroduction still fails via FORBIDDEN_PACKAGES in `check-toolbar-graph.mjs`
-- [x] Ratchets: graph budget 18 MB → 15.5 MB (measured 13.40 MiB, 1010 files), eager budget 3.3 MB → 3.05 MB (measured 2,764,847 — the cut freed 203 KB of eager JS and one eager chunk)
-- [-] `import type` conversion / `lib/Chart` type-only / leaf-enum moves: NOT NEEDED for the bundle (see finding); only worth doing as general hygiene if oxlint `consistent-type-imports` lands repo-wide
-- [ ] `chart.js` deny retirement: still blocked — `lib/Chart` stays denied because Sparkline/LineGraph value-import it outside types.ts (Step 6 territory)
-
-### Step 5 — toolbar-owned direct edges
-
-- [x] `toolbar/experiments/experimentsTabLogic.tsx`: stopped importing `scenes/experiments/experimentsLogic` — the pure status helpers (`getExperimentStatus`/`isLaunched`/`isExperimentPaused`/`hasEnded`) moved to leaf module `scenes/experiments/experimentStatus.ts` (re-exported from experimentsLogic for app importers); data fetching already went via `toolbarApi`
-- [x] `toolbar/debug/EventDebugMenu.tsx`: `PanelSettings` moved from `scenes/session-recordings/components/` to `lib/components/PanelSettings/` (its deps were already all-lib)
-- [ ] `toolbar/debug/eventDebugMenuLogic.ts`: drop/trim the 339KB `core-filter-definitions-by-group.json` taxonomy import — deprioritized: Step 7 made the debugger menu (and this JSON) lazy, so it's deferred-bytes only
-- [x] `toolbar/actions/StepField.tsx`: `products/actions/frontend/utils/hints` moved to `lib/components/UrlMatchingHints.tsx` (shared by the actions product's ActionStep and the toolbar)
-
-### Step 6 — shared lib → scenes back-edges (each also helps the main app)
-
-- [x] `lib/lemon-ui/Link/Link.tsx` → `DraggableToNotebook`: inverted with the flagship DI seam — `lib/lemon-ui/Link/useLinkDrag.ts` holds a swappable hook (inert default), `registerNotebookLinkDrag()` (called from `bootApp()`, before first render — swapping later would break hook order) installs the notebook implementation. Toolbar and exporter keep the inert default and stop bundling notebooks drag; a jest test covers the registered wiring end to end (drag start → uri-list payload)
-- [x] `lib/lemon-ui/LemonColor/*` → `dataThemeLogic` and HedgehogMode/JSONViewer/LemonColorGlyph → `themeLogic`: both logics (plus `themes.ts`) moved to `lib/logic/` — they're global UI state whose app-zone deps (sceneLogic, userLogic, teamLogic) already resolve to toolbar shims, so the move is placement-only. Old paths re-export for the ~60 app importers; all `src/lib` importers repointed. Cuts 6 baseline edges (props/context seam not needed)
-- [x] `lib/lemon-ui/LemonMarkdown/index.ts`: the barrel no longer re-exports `LemonMarkdownWithMermaid` (the one product user imports the module directly); the `mermaid` deny in `toolbar-config.mjs` is retired, reintroduction caught by FORBIDDEN_PACKAGES
-- [x] `HeatmapEventsPanel` → `PersonDisplay`: replaced with a plain span (PersonDisplay renders exactly that for a distinct_id-only person with `noPopover`); `TZLabel` → teamLogic edge now shimmed at resolve time (`~/scenes/teamLogic` matching)
-- [x] `KeyboardShortcut` moved out of `layout/navigation-3000/components/` into `lib/components/KeyboardShortcut/` (25 importers repointed; cuts the 4 lemon-ui → layout edges)
-- [x] `preflightLogic` moved from `scenes/PreflightCheck/` to `lib/logic/preflightLogic` (it's global app state, not scene state; its `scenes/urls` import resolves through the toolbar shim). All `src/lib/**` importers repointed; a `scenes/PreflightCheck/preflightLogic.tsx` re-export keeps the other ~100 app importers working, so a follow-up repoint is optional cleanup. Cuts 5 baseline edges (incidentStatusLogic, MCPInstallCommand, payGateMiniLogic, superpowersLogic, eventUsageLogic)
-- [x] `eventUsageLogic` → web-analytics achievements: inverted — `webAnalyticsAchievementsLogic` now owns interaction recording (a `recordInteraction` action absorbing `recordInteraction.ts`, deleted) and listens to the five `reportWebAnalytics*` action types itself. Cuts 2 edges and drops the achievements + generated web_analytics API modules (~62 KB, 8 files) from the toolbar graph. Behavior note: recording now requires the achievements logic mounted, which the web analytics scene menu bar guarantees wherever those reports fire
-- [ ] `TZLabel` → urls (already shim-resolved to `~/toolbar/urls`; boundary-only); `eventUsageLogic` → `product-tours/constants` (1 KB leaf, part of the product-tours seam family)
-
-### Step 7 — lazy boundaries in toolbar source (in review: `rafa/toolbar-migration-6-lazy-menus`)
-
-- [x] The nine `visibleMenu` bodies + `ProductToursSidebar`/`SurveySidebar`/`FieldNotesOverlay` are `React.lazy(() => retryImport(() => import(...)))` behind `Suspense` (Spinner fallback in the menu container, null for sidebars). `eventDebugMenuLogic` (and its 225KB taxonomy JSON) is component-only so it defers with the debugger menu
-- [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`
-- [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)
-
-- [ ] 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)
-
-`toolbar/product-tours/productToursLogic.ts` → `scenes/product-tours/editor/generateStepHtml.ts` is a legitimate dep costing ~1MB dev (tiptap + prosemirror + highlight.js). Right fix: precompute step HTML at authoring time in the app, store on the `ProductTourStep` payload, render sanitized in the toolbar (dompurify already bundled). Until decided, Step 7's lazy boundary defers it.
-
-## Verification (every step)
-
-```bash
-pnpm --filter=@posthog/frontend build:esbuild
-node frontend/bin/check-toolbar-size.mjs
-node frontend/bin/check-toolbar-graph.mjs # from Step 1 on
-node frontend/bin/check-toolbar-csp-eval.mjs
-pnpm --filter=@posthog/frontend visualize-toolbar-bundle # eyeball the graph
-```
-
-Byte estimates in this doc are dev bytes × ~0.42 ≈ prod — verify with the real minified build. When bytes don't move, the shrinking Step 1 allowlist is the progress metric. Toolbar behavior: launch on the local app (`hogli start`) and click through the tabs; for format changes also run the CSP/old-SDK Playwright checks from Step 2.
diff --git a/.oxlintrc.json b/.oxlintrc.json
index b1fcd11ef5ff..c361859ee681 100644
--- a/.oxlintrc.json
+++ b/.oxlintrc.json
@@ -334,15 +334,15 @@
"!scenes/experiments/utils",
"!~/scenes/experiments/utils"
],
- "message": "The toolbar ships to customer pages and must not depend on app scenes. Import from lib/, or fetch via toolbarFetch. Existing exceptions are being removed per .agents/toolbar-migration.md; the full transitive boundary is enforced by frontend/bin/check-toolbar-graph.mjs."
+ "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."
},
{
"group": ["~/products", "products/**", "~/products/**"],
- "message": "The toolbar must not import product manifests or product frontends — that pulls the whole product graph into the customer-facing bundle. See .agents/toolbar-migration.md."
+ "message": "The toolbar must not import product manifests or product frontends — that pulls the whole product graph into the customer-facing bundle."
},
{
"group": ["layout/**", "~/layout/**", "models/**", "~/models/**"],
- "message": "The toolbar must not import app layout or global models. See .agents/toolbar-migration.md."
+ "message": "The toolbar must not import app layout or global models."
}
],
"paths": [
diff --git a/frontend/bin/build-toolbar.mjs b/frontend/bin/build-toolbar.mjs
index 5e939bdb83e0..ba2a8f441f8c 100644
--- a/frontend/bin/build-toolbar.mjs
+++ b/frontend/bin/build-toolbar.mjs
@@ -1,10 +1,10 @@
#!/usr/bin/env node
/**
- * Builds the toolbar bundle for use alongside Vite dev server.
+ * Builds the toolbar bundle for use alongside the Vite dev server.
*
* When using Vite for development, the main app is served via Vite's dev server with HMR.
- * However, the toolbar is loaded as a separate IIFE bundle via /static/toolbar.js,
- * which is proxied to Django. This script watches and rebuilds the toolbar when
+ * The toolbar is a separate bundle loaded via /static/toolbar.js (proxied to Django), so it
+ * isn't part of the Vite graph. This script builds and watches it, rebuilding when
* toolbar-related files change.
*/
import * as path from 'path'
diff --git a/frontend/bin/check-toolbar-graph.mjs b/frontend/bin/check-toolbar-graph.mjs
index dc82ebfba35e..d3fe6b5bdbbd 100644
--- a/frontend/bin/check-toolbar-graph.mjs
+++ b/frontend/bin/check-toolbar-graph.mjs
@@ -15,9 +15,8 @@ const baselinePath = path.join(__dirname, 'toolbar-graph-baseline.json')
// 1. "Survivors" are the modules still reachable from the toolbar entry when traversal
// refuses to walk INTO the app zone (scenes/, layout/, models/, products manifests).
// Every survivor edge that crosses into the app zone is a real dependency the toolbar
-// code holds on the app — the thing the migration (.agents/toolbar-migration.md) is
-// cutting one by one. New crossing edges fail; removed ones must be deleted from the
-// checked-in baseline so progress ratchets.
+// code holds on the app. New crossing edges fail; cutting an edge means deleting it from
+// the checked-in baseline so the win is locked in.
// Non-survivor crossings (app-zone code importing more app-zone code) aren't listed:
// they disappear on their own when the last survivor edge into their family is cut.
//
@@ -30,7 +29,9 @@ const ENTRY = 'src/toolbar/index.tsx'
const APP_ZONE = [/^src\/products/, /^src\/scenes\//, /^src\/layout\//, /^src\/models\//, /^\.\.\/products\//]
-// Denied at resolve time in toolbar-config.mjs — must not appear in the graph at all.
+// 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.
const FORBIDDEN_PACKAGES = [
'node_modules/monaco-editor/',
'node_modules/chart.js/',
@@ -38,11 +39,9 @@ const FORBIDDEN_PACKAGES = [
'node_modules/hls.js/',
]
-// Ratchet policy: when a cut lands, lower the budget to lock it in; raise it only as a
-// conscious, reviewed decision in the PR that needs it.
-// 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.
+// 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
function fail(message) {
@@ -102,7 +101,7 @@ if (newEdges.length) {
newEdges.map((e) => ` ${e}`).join('\n') +
`\nThe toolbar bundle must not grow new dependencies on app code (scenes/, layout/, models/, ` +
`products manifests) — it ships to customer pages. Import from lib/, move the shared code out ` +
- `of the app zone, or fetch via toolbarFetch instead. See .agents/toolbar-migration.md.`
+ `of the app zone, or fetch via toolbarFetch instead.`
)
}
diff --git a/frontend/bin/check-toolbar-size.mjs b/frontend/bin/check-toolbar-size.mjs
index 104c4d2779f3..e25fbce697e3 100644
--- a/frontend/bin/check-toolbar-size.mjs
+++ b/frontend/bin/check-toolbar-size.mjs
@@ -14,14 +14,11 @@ import { eagerOutputs, findEntryOutput, jsOutputs, readToolbarMetafile } from '.
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 a cut lands, lower the
+// 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.
-// 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 = 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.
const MAX_LOADER_BYTES = 20_000
function humanBytes(bytes) {
@@ -101,7 +98,7 @@ function main() {
fail(
`Eager toolbar JS is ${humanBytes(eagerBytes)} across ${eagerJs.length} files, over the ` +
`${humanBytes(MAX_EAGER_BYTES)} budget. Something newly reachable through static imports — ` +
- 'lazy-load it (import()) or cut the import edge. See .agents/toolbar-migration.md.'
+ 'lazy-load it (import()) or cut the import edge.'
)
}
diff --git a/frontend/bin/toolbar-graph-baseline.json b/frontend/bin/toolbar-graph-baseline.json
index 8b535898353f..4c0e7895d9a3 100644
--- a/frontend/bin/toolbar-graph-baseline.json
+++ b/frontend/bin/toolbar-graph-baseline.json
@@ -1,5 +1,5 @@
{
- "//": "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.",
+ "//": "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",
diff --git a/frontend/src/toolbar/shims/hoggies.tsx b/frontend/src/toolbar/shims/hoggies.tsx
deleted file mode 100644
index 7a1cc9b6f7de..000000000000
--- a/frontend/src/toolbar/shims/hoggies.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import type { ComponentType } from 'react'
-
-import type { AssetSvgProps } from '@posthog/brand'
-
-import type { HoggiePngModule } from 'lib/brand/hoggies'
-
-// Toolbar shim — hoggie illustrations are decorative, and the toolbar runs on customer
-// sites where every extra asset request (and CSP entry) counts, so they render nothing
-// in the toolbar instead.
-export function pngHoggie(_module: HoggiePngModule): ComponentType<AssetSvgProps> {
- return function ShimmedHoggie(): null {
- return null
- }
-}
diff --git a/frontend/toolbar-config.mjs b/frontend/toolbar-config.mjs
index bdd629e2c96e..f13e497b90cf 100644
--- a/frontend/toolbar-config.mjs
+++ b/frontend/toolbar-config.mjs
@@ -6,8 +6,8 @@ import { commonConfig, copyRRWebWorkerFiles, createHashlessEntrypoints, esbuildB
// `TOOLBAR_PUBLIC_PATH`, when set, overrides the default `publicPath` so the
// toolbar bundle and its assets can be hosted under a versioned, content-pinned
// URL on the posthog-js CDN. Used by posthog-js's release workflow to ship a
-// fully self-contained toolbar bundle. When unset, behaviour is unchanged from
-// before this knob existed (Django-served `https://us.posthog.com/static/`).
+// fully self-contained toolbar bundle. When unset, the bundle is served from
+// Django `/static/`.
//
// esbuild uses this verbatim as a URL prefix, so a trailing slash is required;
// add one if the caller forgot.
@@ -26,9 +26,6 @@ const shimmedModules = {
'scenes/sceneLogic': 'src/toolbar/shims/sceneLogic.ts',
'scenes/teamLogic': 'src/toolbar/shims/teamLogic.ts',
'lib/logic/featureFlagLogic': 'src/toolbar/shims/featureFlagLogic.ts',
- // Hoggie illustrations are decorative; the shim renders null so no PNG assets or image
- // requests reach the toolbar bundle that runs on customer sites (asset URLs are CSP-relevant).
- 'lib/brand/hoggies': 'src/toolbar/shims/hoggies.tsx',
// 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
@@ -47,20 +44,14 @@ const deniedPaths = [
'scenes/session-recordings/player/snapshot-processing/DecompressionWorkerManager.ts',
]
-// Heavy third-party libraries the toolbar never renders, but which leak in transitively
-// through the shared scene graph (mostly via scenes/urls.ts -> products.tsx). Code splitting
-// would defer the lazily-`import()`-ed ones rather than inline them, but until their import
-// edges are cut at the source (.agents/toolbar-migration.md), denying them at resolve time
-// keeps them out of the artifact set entirely — bin/check-toolbar-graph.mjs asserts absence.
+// 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(\/|$)/,
- // hls.js and mermaid need no deny anymore: hls.js's only path in was @posthog/replay-shared,
- // whose last importer (~/types' SnapshotSourceType value re-export) is now type-only, and
- // mermaid's was the LemonMarkdown barrel, which no longer re-exports the mermaid variant.
- // Reintroduction is caught by FORBIDDEN_PACKAGES in bin/check-toolbar-graph.mjs.
]
const deniedPatterns = [
@@ -79,20 +70,19 @@ const deniedPatterns = [
/**
* 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:
+ * the toolbar must not ship. Tree shaking can't drop them (the shared packages aren't marked
+ * side-effect-free) and app code shouldn't contort itself for the toolbar, so imports are
+ * replaced at resolve time:
*
* - 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).
+ * 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.
*
* 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
@@ -162,7 +152,7 @@ function createToolbarModulePlugin(dirname) {
}
}
-// The toolbar ships as two artifacts (see .agents/toolbar-migration.md):
+// The toolbar ships as two artifacts:
//
// dist/toolbar.js — a tiny classic-script loader (src/toolbar/loader.ts). posthog-js
// injects it with a plain <script> tag on customer pages and calls