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(cli): stop calling turbopack page stubs a bundler misconfiguration (#129016)

James Gill48fd6d2c7cc2
diff --git a/cli/.sampo/changesets/quiet-turbopack-page-stubs.md b/cli/.sampo/changesets/quiet-turbopack-page-stubs.md
new file mode 100644
index 000000000000..b8c0654e3f3e
--- /dev/null
+++ b/cli/.sampo/changesets/quiet-turbopack-page-stubs.md
@@ -0,0 +1,5 @@
+---
+cargo/posthog-cli: patch
+---
+
+Stop reporting Next.js Turbopack server page stubs as a possible bundler misconfiguration when `sourcemap upload` skips their empty source maps
diff --git a/cli/src/sourcemaps/plain/upload.rs b/cli/src/sourcemaps/plain/upload.rs
index 9e398160062f..92ce9a65320a 100644
--- a/cli/src/sourcemaps/plain/upload.rs
+++ b/cli/src/sourcemaps/plain/upload.rs
@@ -13,10 +13,14 @@ use tracing::{debug, info, warn};
/// Sibling-JS size below which an empty sourcemap is treated as a harmless
/// bundler-generated wrapper (e.g. Turbopack App Router page entries,
-/// webpack re-export shims). Observed wrapper files in the wild are
-/// under 1 KiB; 2 KiB leaves comfortable headroom for tools that inject
-/// extra glue (PostHog chunk-id IIFE, etc.) without misclassifying real code.
-const WRAPPER_JS_SIZE_THRESHOLD_BYTES: usize = 2048;
+/// webpack re-export shims). Turbopack page entries reach about 3 KiB after
+/// chunk-id injection (#70235), and every layout, loading or error file on the
+/// route makes the entry larger. Every empty map is skipped whatever its size,
+/// so this cutoff only picks the log message and which of the
+/// `empty_skipped_wrapper` and `empty_skipped_suspect` telemetry counts the
+/// map adds to. A bundler that drops maps for a whole build also writes empty
+/// maps for chunks well above 4 KiB, so the summary still reports it.
+const WRAPPER_JS_SIZE_THRESHOLD_BYTES: usize = 4096;
/// Cap on the suspect paths named in the summary line. They share one line, and an
/// oversized line kills the process on a non-blocking stderr pipe (see `FileSelectionArgs`).
@@ -167,45 +171,8 @@ pub fn upload_pairs(
let (empty_pairs, valid_pairs): (Vec<_>, Vec<_>) = pairs
.into_iter()
.partition(|pair| pair.sourcemap.is_empty());
- let mut empty_skipped_wrapper = 0usize;
- let mut empty_skipped_suspect = 0usize;
- let mut suspect_paths: Vec<String> = Vec::new();
- for pair in &empty_pairs {
- let js_size = pair.source.inner.content.len();
- let map_path = pair.sourcemap.inner.path.display();
- if js_size < WRAPPER_JS_SIZE_THRESHOLD_BYTES {
- empty_skipped_wrapper += 1;
- debug!(
- "Skipping {}: sourcemap is empty and sibling JS is {} bytes — bundler-generated wrapper, nothing to symbolicate",
- map_path, js_size
- );
- } else {
- empty_skipped_suspect += 1;
- if suspect_paths.len() < MAX_LISTED_SUSPECT_PATHS {
- suspect_paths.push(map_path.to_string());
- }
- debug!(
- "Skipping {}: sourcemap is empty but sibling JS is {} bytes — possible bundler misconfiguration",
- map_path, js_size
- );
- }
- }
- if empty_skipped_suspect > 0 {
- let unlisted = empty_skipped_suspect - suspect_paths.len();
- let rest = if unlisted > 0 {
- format!(" and {unlisted} more (set RUST_LOG=debug to list them all)")
- } else {
- String::new()
- };
- info!(
- "Skipped {} empty sourcemaps whose sibling JS file is at least {} bytes: {}{}. If those files must symbolicate, check your bundler's source-map setting (e.g. webpack `devtool`, Next.js `productionBrowserSourceMaps`, server compiler config).",
- empty_skipped_suspect,
- WRAPPER_JS_SIZE_THRESHOLD_BYTES,
- suspect_paths.join(", "),
- rest
- );
- }
let empty_skipped = empty_pairs.len();
+ let empty_skipped_suspect = report_empty_pairs(&empty_pairs);
let uploads = prepare_uploads(valid_pairs, args.release_mode)?;
@@ -218,7 +185,10 @@ pub fn upload_pairs(
("file_count", json!(file_count)),
("total_bytes", json!(total_bytes)),
("empty_skipped", json!(empty_skipped)),
- ("empty_skipped_wrapper", json!(empty_skipped_wrapper)),
+ (
+ "empty_skipped_wrapper",
+ json!(empty_skipped - empty_skipped_suspect),
+ ),
("empty_skipped_suspect", json!(empty_skipped_suspect)),
],
);
@@ -315,6 +285,46 @@ fn select_uploadable_pairs(pairs: Vec<SourcePair>) -> Vec<SourcePair> {
uploadable
}
+fn report_empty_pairs(empty_pairs: &[SourcePair]) -> usize {
+ let mut empty_skipped_suspect = 0usize;
+ let mut suspect_paths: Vec<String> = Vec::new();
+ for pair in empty_pairs {
+ let js_size = pair.source.inner.content.len();
+ let map_path = pair.sourcemap.inner.path.display();
+ if js_size < WRAPPER_JS_SIZE_THRESHOLD_BYTES {
+ debug!(
+ "Skipping {}: sourcemap is empty and sibling JS is {} bytes — bundler-generated wrapper, nothing to symbolicate",
+ map_path, js_size
+ );
+ } else {
+ empty_skipped_suspect += 1;
+ if suspect_paths.len() < MAX_LISTED_SUSPECT_PATHS {
+ suspect_paths.push(map_path.to_string());
+ }
+ debug!(
+ "Skipping {}: sourcemap is empty but sibling JS is {} bytes — possible bundler misconfiguration",
+ map_path, js_size
+ );
+ }
+ }
+ if empty_skipped_suspect > 0 {
+ let unlisted = empty_skipped_suspect - suspect_paths.len();
+ let rest = if unlisted > 0 {
+ format!(" and {unlisted} more (set RUST_LOG=debug to list them all)")
+ } else {
+ String::new()
+ };
+ info!(
+ "Skipped {} empty sourcemaps whose sibling JS file is at least {} bytes: {}{}. If those files must symbolicate, check your bundler's source-map setting (e.g. webpack `devtool`, Next.js `productionBrowserSourceMaps`, server compiler config).",
+ empty_skipped_suspect,
+ WRAPPER_JS_SIZE_THRESHOLD_BYTES,
+ suspect_paths.join(", "),
+ rest
+ );
+ }
+ empty_skipped_suspect
+}
+
/// Build the upload payloads for `pairs`, at most one per chunk id. Event mode derives the id
/// from content, so a hashless alias copied beside `app-<hash>.js` collides with its original.
fn prepare_uploads(
@@ -683,6 +693,25 @@ mod tests {
assert_eq!(std::fs::read_to_string(&map_path).unwrap(), replacement_map);
}
+ #[test]
+ fn empty_maps_split_into_wrappers_and_suspects_at_4_kib() {
+ let dir = tempfile::tempdir().unwrap();
+ for (name, js_size) in [("page", 2900), ("stub", 4095), ("chunk", 4096)] {
+ let reference = format!("\n//# sourceMappingURL={name}.js.map\n");
+ let source = "x".repeat(js_size - reference.len()) + &reference;
+ std::fs::write(dir.path().join(format!("{name}.js")), source).unwrap();
+ std::fs::write(
+ dir.path().join(format!("{name}.js.map")),
+ r#"{"version":3,"sources":[],"names":[],"mappings":""}"#,
+ )
+ .unwrap();
+ }
+ let pairs = read_dir_pairs(dir.path());
+ assert_eq!(pairs.len(), 3);
+
+ assert_eq!(report_empty_pairs(&pairs), 1);
+ }
+
#[test]
fn overlapping_roots_yield_each_pair_once() {
let dir = tempfile::tempdir().unwrap();
diff --git a/hog/src/commands/error-tracking/error-tracking.test.ts b/hog/src/commands/error-tracking/error-tracking.test.ts
index c6604165576a..ed8218d1f481 100644
--- a/hog/src/commands/error-tracking/error-tracking.test.ts
+++ b/hog/src/commands/error-tracking/error-tracking.test.ts
@@ -11,7 +11,7 @@ import {
writeFileSync,
} from 'node:fs'
import { tmpdir } from 'node:os'
-import { join } from 'node:path'
+import { basename, join } from 'node:path'
import { cleanUp, cssTargets } from '@/error-tracking/cleanup'
import { contentHash, SymbolDataType, writeSymbolData } from '@/error-tracking/container'
@@ -158,6 +158,37 @@ describe('hog error-tracking upload', () => {
expect(readFileSync(join(folder, untouched), 'utf8')).toBe(before)
})
+ test('upload --dry-run calls an empty map a bundler problem only when its file is 4096 bytes or more', async () => {
+ const files: Record<string, string> = {
+ 'dist/ok.js': 'a();\n//# sourceMappingURL=ok.js.map\n//# chunkId=00000000-0000-4000-8000-000000000000',
+ 'dist/ok.js.map': MAP,
+ }
+ for (const [name, size, id] of [
+ ['page', 2900, 1],
+ ['stub', 4095, 2],
+ ['chunk', 4096, 3],
+ ] as const) {
+ const tail = `\n//# sourceMappingURL=${name}.js.map\n//# chunkId=00000000-0000-4000-8000-00000000000${id}`
+ files[`dist/${name}.js`] = 'a'.repeat(size - tail.length) + tail
+ files[`dist/${name}.js.map`] = JSON.stringify({ version: 3, sources: [], names: [], mappings: '' })
+ }
+ const result = await runHog(['et', 'upload', '--dry-run', 'dist'], {
+ env: { CLAUDECODE: '1' },
+ cwd: project(files),
+ useDisk: true,
+ })
+
+ expect(result.exitCode).toBe(0)
+ const reasons = Object.fromEntries(
+ result.json().skipped.map((skip: { path: string; reason: string }) => [basename(skip.path), skip.reason])
+ )
+ expect(reasons).toEqual({
+ 'page.js': 'the sourcemap is empty',
+ 'stub.js': 'the sourcemap is empty',
+ 'chunk.js': 'the sourcemap is empty although the file is large. Check your bundler sourcemap setting.',
+ })
+ })
+
test('--delete-after leaves alone CSS maps outside the selected paths, ignored maps, and JSON that is not a map', () => {
const folder = project({
'dist/broken.css': 'a{}\n/*# sourceMappingURL=%FF.css.map */\n',
diff --git a/hog/src/error-tracking/js-flow.ts b/hog/src/error-tracking/js-flow.ts
index 54998fb63631..f2ec84c7df06 100644
--- a/hog/src/error-tracking/js-flow.ts
+++ b/hog/src/error-tracking/js-flow.ts
@@ -152,8 +152,9 @@ export function preparePairs(pairs: SourcePair[], mode: ReleaseMode): PreparedPa
if (isEmptyMapContent(pair.map)) {
skipped.push({
path: pair.sourcePath,
+ // Keep in step with WRAPPER_JS_SIZE_THRESHOLD_BYTES in cli/src/sourcemaps/plain/upload.rs.
reason:
- Buffer.byteLength(pair.source) < 2048
+ Buffer.byteLength(pair.source) < 4096
? 'the sourcemap is empty'
: 'the sourcemap is empty although the file is large. Check your bundler sourcemap setting.',
})