sentry-replay.ts1.2 KBView on GitHub
/**
 * Session Replay, isolated behind a dynamic-import boundary.
 *
 * This file exists purely to give Rollup a dynamic entry point. `replayIntegration` pulls in rrweb
 * (~136 KB of the Sentry bundle), and rrweb must not be reachable from any *static* import or it
 * lands in the critical-path chunk.
 *
 * The obvious-looking version of this — calling `await import('@sentry/react')` from inside
 * `lib/sentry.ts` — does NOT work, and was tried and measured: because `lib/sentry.ts` already
 * imports `@sentry/react` statically, the dynamic import resolves to a module that is already in
 * the graph, so Rollup has nothing to split and the critical path does not move (verified: 3.372 MB
 * before and after). Importing `replayIntegration` here instead, in a module whose *only* importer
 * is an `import()` call, is what actually creates the separate chunk.
 *
 * Do not import this file statically from anywhere. Doing so silently undoes the split.
 *
 * See docs/design/frontend-load-performance.md §3 F2.
 */
import { replayIntegration } from '@sentry/react';

export function createReplayIntegration() {
  return replayIntegration({
    maskAllText: true,
    maskAllInputs: true,
    blockAllMedia: true,
  });
}