: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(frontend): count the stable build's css in the eager graph check (#115071)
Paul D'Ambra369f0c94a181
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjsindex 563082cdeda2..871fb1364eaa 100644--- a/frontend/bin/check-eager-graph.mjs+++ b/frontend/bin/check-eager-graph.mjs@@ -5,6 +5,7 @@ import path from 'node:path'import { fileURLToPath } from 'node:url'import { AUTHENTICATED_SHELL, ENTRY, LOGGED_OUT_BOOT } from './bootEntries.mjs'+import { planCssGroups, stableCssBytes } from './stableCssPlan.mjs'const __dirname = path.dirname(fileURLToPath(import.meta.url))const frontendDir = path.resolve(__dirname, '..')@@ -25,24 +26,24 @@ const failForbiddenHits = process.argv.includes('--fail-forbidden-hits')// The eager graph is everything a root actually SHIPS on the critical path — the bytes a// browser downloads and parses before that surface is interactive. It is measured from the// esbuild OUTPUT chunks: the root's entry chunk plus every chunk reachable through static-// (import-statement) chunk edges, plus the one stylesheet the page links (see `linkedStylesheet`;-// it is downloaded before render). Lazy (dynamic-import) chunks are excluded, and tree-shaken+// (import-statement) chunk edges, plus the CSS the stable build loads before the root runs (see+// `stableCssBytes`). Lazy (dynamic-import) chunks are excluded, and tree-shaken// code is already gone from the output — so a side-effect-free re-export barrel only costs// what its used exports actually ship, not its whole surface (the earlier input-graph metric// counted the whole barrel and mistook reachability for shipped weight).// Total dist size can't see this regression class (a fake-lazy import moves no total bytes// but shifts them onto the eager path), which is why this check exists.//-// Budgets are eager output bytes (shipped JS + the linked stylesheet, minified).+// Budgets are eager output bytes (shipped JS + the stable build's CSS for the root, minified).// Ratchet policy: when a bundle-splitting win lands, lower the budget to lock it in;// raise a budget only as a conscious, reviewed decision in the PR that needs it.const ROOTS = [{root: ENTRY,label: 'entry (logged-out pages, app bootstrap)',- // 2026-09-11: 1.54 MiB eager output (0.18 MiB JS + the 1.36 MiB linked stylesheet, 22 files).+ // 2026-10-11: 0.97 MiB eager output (0.17 MiB JS + 0.80 MiB stable CSS, 23 files).// ~20% headroom so routine churn doesn't trip the warn; ratchet down on a split win.- budgetBytes: 1_930_000,+ budgetBytes: 1_200_000,forbidden: ['node_modules/monaco-editor/','src/lib/components/ActivityLog/describers',@@ -69,10 +70,10 @@ const ROOTS = [root: LOGGED_OUT_BOOT,label: 'logged-out boot: index + App + bootApp (preloaded by every page, including /login)',// The backend preloads the App closure for logged-out pages too (preload-manifest.json- // `js`), so this is the whole JS cost of /login. 2026-09-11: 3.51 MiB eager output = 2.14 MiB- // JS (608 files) + the 1.36 MiB linked stylesheet.- // ~15% headroom so routine churn doesn't trip the warn; ratchet down on a split win.- budgetBytes: 4_225_000,+ // `js`), so this is the whole JS cost of /login. 2026-10-11: 3.13 MiB eager output = 2.33 MiB+ // JS (675 files) + 0.80 MiB stable CSS.+ // ~6% headroom so routine churn doesn't trip the warn; ratchet down on a split win.+ budgetBytes: 3_495_000,forbidden: ['node_modules/monaco-editor/',// Authenticated-only code. Either of these on the App path means a component that@@ -91,9 +92,9 @@ const ROOTS = [{root: AUTHENTICATED_SHELL,label: 'authenticated shell (every logged-in page)',- // 2026-09-24: 7.25 MiB eager output = 5.86 MiB JS (2292 files) + the 1.39 MiB linked- // stylesheet. ~15% headroom so routine churn doesn't trip the warn.- budgetBytes: 8_745_000,+ // 2026-10-11: 7.09 MiB eager output = 6.29 MiB JS (2463 files) + 0.80 MiB stable CSS.+ // ~8% headroom so routine churn doesn't trip the warn.+ budgetBytes: 8_015_000,forbidden: ['node_modules/monaco-editor/','src/lib/components/ActivityLog/describers',@@ -123,13 +124,12 @@ const ROOTS = [],},// The most visited logged-in scenes, whose JS gates their LCP. A scene root counts every chunk the- // scene needs, so code it shares with the shell is in both numbers. Like the other roots it adds the- // whole linked stylesheet, not the per-scene CSS the stable build serves, so a budget tracks JS.+ // scene needs, so code it shares with the shell is in both numbers.{root: 'src/scenes/dashboard/Dashboard.tsx',label: 'dashboard scene',- // 2026-10-05: 9.93 MiB (3517 files), linked stylesheet included. ~10% headroom.- budgetBytes: 11_450_000,+ // 2026-10-11: 9.33 MiB (3529 files), stable CSS included. ~10% headroom.+ budgetBytes: 10_800_000,forbidden: [// Neither scene plays recordings. A hit means a static import pulled the playlist and player onto it.'src/scenes/session-recordings/playlist/SessionRecordingsPlaylist.tsx',@@ -145,7 +145,7 @@ const ROOTS = ['src/scenes/project-homepage/today/TodayHome.tsx',],label: 'today home path',- budgetBytes: 9_000_000,+ budgetBytes: 8_270_000,forbidden: ['src/scenes/project-homepage/ai-first/AiFirstHomepage.tsx','src/scenes/project-homepage/today/TodayReportPage.tsx',@@ -155,8 +155,8 @@ const ROOTS = [{root: 'src/scenes/activity/explore/EventsScene.tsx',label: 'events scene',- // 2026-10-05: 9.55 MiB (3371 files), linked stylesheet included. ~10% headroom.- budgetBytes: 11_020_000,+ // 2026-10-11: 8.92 MiB (3373 files), stable CSS included. ~10% headroom.+ budgetBytes: 10_355_000,forbidden: [// Neither scene plays recordings. A hit means a static import pulled the playlist and player onto it.'src/scenes/session-recordings/playlist/SessionRecordingsPlaylist.tsx',@@ -168,8 +168,8 @@ const ROOTS = [{root: 'src/scenes/session-recordings/detail/SessionRecordingDetail.tsx',label: 'replay detail scene',- // 2026-10-01: 14.29 MiB (5280 files), linked stylesheet included. ~10% headroom.- budgetBytes: 16_480_000,+ // 2026-10-11: 11.70 MiB (4204 files), stable CSS included. ~30% headroom.+ budgetBytes: 15_785_000,forbidden: [],},]@@ -324,9 +324,7 @@ function eagerChunkClosure(entry) {return seen}-// The page links only the src/index.tsx entry's stylesheet (writePreloadManifest in build.mjs). esbuild-// gives other chunks a `cssBundle` too, but the browser never downloads those files.-const linkedStylesheet = outputs[entryChunk(ENTRY)]?.cssBundle+const cssPlan = planCssGroups(meta)const summaryLines = ['## Eager graph check', '', '| Root | Eager size | Budget | Files |', '| --- | --- | --- | --- |']const report = { roots: [], errors: [], warnings: [] }@@ -389,10 +387,11 @@ for (const { root: rootSpec, label, budgetBytes, forbidden } of ROOTS) {}}}- // `cssBundle` is not an `imports` edge, so the chunk walk never reaches the sheet every page links.- if (linkedStylesheet) {- totalBytes += outputs[linkedStylesheet].bytes- }+ // CSS is not an `imports` edge, so the chunk walk never reaches it.+ totalBytes += stableCssBytes(+ cssPlan,+ entries.map(({ entry }) => entry)+ )const largest = [...eagerBytesByFile.entries()].sort((a, b) => b[1] - a[1]).slice(0, 15)const overBudget = totalBytes > budgetBytesdiff --git a/frontend/bin/stableCssPlan.mjs b/frontend/bin/stableCssPlan.mjsindex 0007b3be0127..90a5b0f19173 100644--- a/frontend/bin/stableCssPlan.mjs+++ b/frontend/bin/stableCssPlan.mjs@@ -51,7 +51,8 @@ export function planCssGroups({ inputs, outputs }, bootEntries = BOOT_ENTRIES) {if (!linkedStylesheet) {throw new Error('stable css: the entry has no stylesheet to split')}- const order = Object.keys(outputs[linkedStylesheet].inputs)+ const linkedStylesheetInputs = outputs[linkedStylesheet].inputs+ const order = Object.keys(linkedStylesheetInputs)const rank = new Map(order.map((file, index) => [file, index]))const boot = new Set(bootEntries.filter((entry) => inputs[entry]))@@ -160,7 +161,23 @@ export function planCssGroups({ inputs, outputs }, bootEntries = BOOT_ENTRIES) {// Each group's place in the entry stylesheet, so the loader can keep lazy groups in that order// whatever order scenes load them in.const rankOfGroup = new Map([...groups.keys()].map((name) => [name, firstRank(name)]))- return { groups, eager, lazyGroupsByEntry, rankOfGroup }+ const bytesOfGroup = new Map(+ [...groups].map(([name, files]) => [+ name,+ files.reduce((sum, file) => sum + linkedStylesheetInputs[file].bytesInOutput, 0),+ ])+ )+ return { groups, eager, lazyGroupsByEntry, rankOfGroup, bytesOfGroup }+}++/**+ * The CSS bytes a stable page downloads before the given entry chunks run: the eager layers plus+ * the lazy groups those entries wait for. A group holds the same CSS as its files do in the entry+ * stylesheet, so their sizes there are its size, apart from the source-map comment each file ends with.+ */+export function stableCssBytes({ eager, lazyGroupsByEntry, bytesOfGroup }, entryOutputs) {+ const names = new Set([...eager, ...entryOutputs.flatMap((entry) => lazyGroupsByEntry.get(entry) ?? [])])+ return [...names].reduce((sum, name) => sum + bytesOfGroup.get(name), 0)}/**diff --git a/frontend/bin/stableCssPlan.test.ts b/frontend/bin/stableCssPlan.test.tsindex 131b71bba3aa..b96692845754 100644--- a/frontend/bin/stableCssPlan.test.ts+++ b/frontend/bin/stableCssPlan.test.ts@@ -1,6 +1,6 @@import { CHUNK_CSS_GLOBAL } from '@posthog/esbuilder/cssLoader.mjs'-import { cssPrelude, planCssGroups } from './stableCssPlan.mjs'+import { cssPrelude, planCssGroups, stableCssBytes } from './stableCssPlan.mjs'const imports = (...paths: string[]): { imports: { path: string; kind: string }[] } => ({imports: paths.map((path) => ({ path, kind: 'import-statement' })),@@ -28,11 +28,11 @@ const METAFILE = {},'dist/index-A.css': {inputs: {- '../common/tailwind/tailwind.css': {},- 'src/styles/global.scss': {},- 'src/lib/Button.scss': {},- 'src/lib/Shared.scss': {},- 'src/scenes/Scene.scss': {},+ '../common/tailwind/tailwind.css': { bytesInOutput: 1 },+ 'src/styles/global.scss': { bytesInOutput: 2 },+ 'src/lib/Button.scss': { bytesInOutput: 4 },+ 'src/lib/Shared.scss': { bytesInOutput: 8 },+ 'src/scenes/Scene.scss': { bytesInOutput: 16 },},},'dist/App-B.js': { entryPoint: 'src/scenes/App.tsx', inputs: { 'src/scenes/App.tsx': {} } },@@ -67,6 +67,14 @@ describe('planCssGroups', () => {expect(lazyGroupsByEntry.has('dist/App-B.js')).toBe(false)})+ it.each([+ ['a boot page', [], 1 + 2 + 4],+ ['a boot entry with no lazy CSS', ['dist/App-B.js'], 1 + 2 + 4],+ ['a lazy scene and its shared chunk', ['dist/Scene-C.js'], 1 + 2 + 4 + 8 + 16],+ ])('counts the CSS a stable page loads before %s runs', (_, entryOutputs, expectedBytes) => {+ expect(stableCssBytes(planCssGroups(METAFILE), entryOutputs)).toBe(expectedBytes)+ })+it('fails rather than reorder rules when boot stylesheets are out of layer order', () => {const outOfOrder = {...METAFILE,