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.

fix(toolbar): make the SnapshotSourceType re-export in ~/types type-only (#69106)

Rafael Audibertf2bd593d2362
diff --git a/.agents/toolbar-migration.md b/.agents/toolbar-migration.md
index 7496a9f542af..37ce63f94bc4 100644
--- a/.agents/toolbar-migration.md
+++ b/.agents/toolbar-migration.md
@@ -4,9 +4,9 @@ This file is the committed source of truth for the toolbar bundle modernization
## Status
-- **Current step**: Step 2 (loader + ESM splitting) is implemented and in review on `rafa/toolbar-migration-4-loader-esm-splitting` — see its section for the remaining parity gates before ready-for-review. Next after that: Step 4 (`~/types` hygiene) and the remaining Step 5/6 edges.
+- **Current step**: Steps 1–4 all implemented and in review as a 5-deep Graphite stack (drafts). Next: merge the base of the stack before extending further (per repo stacking guidance), then remaining Step 5/6 edges and Step 7 lazy boundaries.
- **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, stacked on Step 1); chain cuts + shim-leak fix — `rafa/toolbar-migration-3-shim-leak-and-chain-cuts` (#69088, stacked on #69071); Step 2 — `rafa/toolbar-migration-4-loader-esm-splitting` (stacked on #69088)
+- **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` (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.
@@ -72,7 +72,7 @@ Landed layout: `dist/toolbar.js` (1.2KB classic loader) + `dist/toolbar/` (ESM e
- [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
-- [ ] `Toolbar.stories.tsx` green in CI (runs on the PR)
+- [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.
@@ -86,13 +86,15 @@ Approach (revised on review): rather than restructuring the generated products m
- [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
+### Step 4 — `~/types` hygiene (in review: `rafa/toolbar-migration-5-types-replay-shared-cut`)
-- [ ] Convert type-only imports in `frontend/src/types.ts` to `import type`; make `lib/Chart` type-only
-- [ ] Drop the runtime `export { SnapshotSourceType } from '@posthog/replay-shared'` re-export (kills the `hls.js` deny); import it from a leaf module where used
-- [ ] Move genuine leaf enums (`SessionRecordingPlayerMode`, `WEB_SAFE_FONTS`, ...) to leaf modules; update importers
-- [ ] Optional: oxlint `typescript/consistent-type-imports` on types.ts
-- [ ] Shrink allowlist + drop retired deny entries (`hls.js`, half of `chart.js`)
+**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
diff --git a/frontend/bin/check-toolbar-graph.mjs b/frontend/bin/check-toolbar-graph.mjs
index bfce42bb39cc..c4c639a2b98a 100644
--- a/frontend/bin/check-toolbar-graph.mjs
+++ b/frontend/bin/check-toolbar-graph.mjs
@@ -41,9 +41,9 @@ const FORBIDDEN_PACKAGES = [
// 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; headroom for churn, but any reintroduced leak
-// jumps back to ~100 MiB and fails loudly.
-const TOTAL_INPUT_BYTES_BUDGET = 18_000_000
+// 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
function fail(message) {
console.error(`\n❌ ${message}`)
diff --git a/frontend/bin/check-toolbar-size.mjs b/frontend/bin/check-toolbar-size.mjs
index 0e35e807820a..e4f964982b42 100644
--- a/frontend/bin/check-toolbar-size.mjs
+++ b/frontend/bin/check-toolbar-size.mjs
@@ -16,8 +16,9 @@ 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
// 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; ~10% headroom.
-const MAX_EAGER_BYTES = 3_300_000
+// 2026-07-07: 2,967,721 bytes measured when splitting landed; 2,764,847 after the
+// replay-shared cut; ~10% headroom.
+const MAX_EAGER_BYTES = 3_050_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/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.test.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.test.ts
index ff235d5c8115..e56f32cb14c6 100644
--- a/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.test.ts
+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic.test.ts
@@ -3,7 +3,7 @@ import { api } from 'lib/api.mock'
import { expectLogic } from 'kea-test-utils'
import { HttpResponse } from 'msw'
-import { processAllSnapshots, SourceKey, ViewportResolution } from '@posthog/replay-shared'
+import { processAllSnapshots, SnapshotSourceType, SourceKey, ViewportResolution } from '@posthog/replay-shared'
import { dayjs } from 'lib/dayjs'
import { convertSnapshotsByWindowId } from 'scenes/session-recordings/__mocks__/recording_snapshots'
@@ -14,12 +14,7 @@ import { userLogic } from 'scenes/userLogic'
import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'
import { HogQLQueryResponse } from '~/queries/schema/schema-general'
-import {
- RecordingSnapshot,
- SessionRecordingSnapshotSource,
- SessionRecordingSnapshotSourceResponse,
- SnapshotSourceType,
-} from '~/types'
+import { RecordingSnapshot, SessionRecordingSnapshotSource, SessionRecordingSnapshotSourceResponse } from '~/types'
import { sortedRecordingSnapshots } from '../__mocks__/recording_snapshots'
import { sessionRecordingEventUsageLogic } from '../sessionRecordingEventUsageLogic'
diff --git a/frontend/src/scenes/session-recordings/player/snapshot-processing/patch-meta-event.test.ts b/frontend/src/scenes/session-recordings/player/snapshot-processing/patch-meta-event.test.ts
index 50a8f312afc4..f8fa15653e60 100644
--- a/frontend/src/scenes/session-recordings/player/snapshot-processing/patch-meta-event.test.ts
+++ b/frontend/src/scenes/session-recordings/player/snapshot-processing/patch-meta-event.test.ts
@@ -4,13 +4,14 @@ import { EventType } from 'posthog-js/rrweb-types'
import { ReplayTelemetry } from '@posthog/replay-shared'
import {
ProcessingCache,
+ SnapshotSourceType,
ViewportResolution,
clearThrottle,
keyForSource,
processAllSnapshots,
} from '@posthog/replay-shared'
-import { RecordingSnapshot, SessionRecordingSnapshotSource, SnapshotSourceType } from '~/types'
+import { RecordingSnapshot, SessionRecordingSnapshotSource } from '~/types'
const posthogTelemetry: ReplayTelemetry = {
capture: (event, properties) => posthog.capture(event, properties),
diff --git a/frontend/src/scenes/session-recordings/player/snapshotDataLogic.tsx b/frontend/src/scenes/session-recordings/player/snapshotDataLogic.tsx
index 6cf8d83ce56c..a0257a951fe5 100644
--- a/frontend/src/scenes/session-recordings/player/snapshotDataLogic.tsx
+++ b/frontend/src/scenes/session-recordings/player/snapshotDataLogic.tsx
@@ -5,7 +5,7 @@ import { loaders } from 'kea-loaders'
import posthog from 'posthog-js'
import { keyForSource } from '@posthog/replay-shared'
-import { SnapshotStore, SourceLoadingState } from '@posthog/replay-shared'
+import { SnapshotSourceType, SnapshotStore, SourceLoadingState } from '@posthog/replay-shared'
import api, { RecordingDeletedError } from 'lib/api'
import 'lib/dayjs'
@@ -18,7 +18,6 @@ import {
SessionRecordingSnapshotParams,
SessionRecordingSnapshotSource,
SessionRecordingSnapshotSourceResponse,
- SnapshotSourceType,
} from '~/types'
import { SeekTarget, planNextBatch } from './snapshot-store/planNextBatch'
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 7226fc7ef745..a8b21d0f13ae 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -1371,7 +1371,6 @@ export type EncodedRecordingSnapshot = _EncodedRecordingSnapshot
export type RecordingSnapshot = _RecordingSnapshot
export type SessionRecordingSnapshotSource = _SessionRecordingSnapshotSource
export type SessionRecordingSnapshotSourceResponse = _SessionRecordingSnapshotSourceResponse
-export { SnapshotSourceType } from '@posthog/replay-shared'
export type SessionRecordingSnapshotParams = (
| {
diff --git a/frontend/toolbar-config.mjs b/frontend/toolbar-config.mjs
index f0483b72df74..914329074fb3 100644
--- a/frontend/toolbar-config.mjs
+++ b/frontend/toolbar-config.mjs
@@ -60,8 +60,9 @@ const deniedThirdPartyPackages = [
// already-denied LineGraph.
/^chart\.js(\/|$)/,
/^chartjs-plugin-annotation(\/|$)/,
- // hls.js video streaming, dynamically imported by the shared replay rrweb plugins.
- /^hls\.js(\/|$)/,
+ // hls.js needs no deny anymore: its only path in was @posthog/replay-shared, whose last
+ // importer (~/types' SnapshotSourceType value re-export) is now type-only. Reintroduction
+ // is caught by FORBIDDEN_PACKAGES in bin/check-toolbar-graph.mjs.
]
const deniedPatterns = [