Commit a2f9c1a
test(lighthouse-react): Use static imports gated by MODE for tree-shaking (#21030)
## Summary
Replace the dynamic `await import('./sentry/<mode>')` branching in
`main.tsx` with a single static `import * as Sentry from
'@sentry/react'` guarded by `import.meta.env.MODE`. This more closely
mirrors what a real consumer app looks like: a static SDK import at the
top, with `Sentry.init()` called conditionally. The build matrix still
produces three distinct bundles via `vite build --mode <mode>`, but the
code path is now realistic instead of a code-splitting trick.
## How tree-shaking handles each mode
Vite inlines `import.meta.env.MODE` as a string literal at build time.
Rollup then eliminates dead `if` branches, and `@sentry/react`'s
`"sideEffects": false` lets the namespace import be tree-shaken away
entirely when no member is referenced.
- **`no-sentry`**: both branches are statically dead → `Sentry.*`
unreferenced → the entire `@sentry/react` import is dropped from the
bundle.
- **`init-only`**: only `Sentry.init({ enabled: false })` survives;
`browserTracingIntegration` / `replayIntegration` are tree-shaken.
- **`tracing-replay`**: full SDK + tracing + replay.
## Verified bundle output
| Mode | Bundle | Sentry SDK symbols¹ |
|---|---|---|
| `no-sentry` | 144 KB | 0 |
| `init-only` | 229 KB (+85 KB) | present |
| `tracing-replay` | 418 KB (+274 KB) | 7 |
¹ Count of `captureException` / `startSpan` / `getCurrentScope` /
`__SENTRY__` / `sentry-trace` occurrences in the output JS. The only
`Sentry` literal in the `no-sentry` bundle is the marketing copy string
in `App.tsx`, not SDK code.
The per-mode helper files in `src/sentry/` are no longer needed and have
been deleted.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 16734d0 commit a2f9c1a
4 files changed
Lines changed: 19 additions & 38 deletions
File tree
- dev-packages/e2e-tests/test-applications/lighthouse-react/src
- sentry
Lines changed: 19 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | | - | |
| 23 | + | |
| 24 | + | |
Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 0 additions & 13 deletions
This file was deleted.
0 commit comments