Skip to content

Commit 68cd4e5

Browse files
authored
fix(browser): fix slim bundle + extension bundles crash from inconsistent property mangling (#3316)
* test: add playwright tests for slim bundle + extension bundles (#3313) Regression tests that load the actual built module.slim.js and extension-bundles.js in a browser and exercise every extension bundle. * fix: share terser nameCache across entries for consistent property mangling Without a shared nameCache, terser independently mangles _-prefixed properties to different short names in each rollup entry, causing runtime crashes when module.slim.js and extension-bundles.js are combined. Top-level variable names (vars) are reset per-entry since each ES module has its own scope. Fixes #3313 * test: post-build check for cross-bundle mangling consistency Parses source maps after every build to verify that all shared _-prefixed properties were mangled to the same short names. Fails the build with exact diagnostics if they diverge. * chore: add changeset * review: parameterise duplicate init tests, stricter mismatch check
1 parent 356fb33 commit 68cd4e5

File tree

7 files changed

+656
-720
lines changed

7 files changed

+656
-720
lines changed

.changeset/warm-moons-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'posthog-js': patch
3+
---
4+
5+
Fix slim bundle + extension bundles crash caused by inconsistent property mangling

packages/browser/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"start": "pnpm build-react && NODE_OPTIONS=\"--max-old-space-size=8192\" pnpm build-rollup -w",
1313
"dev": "tsc -b && NODE_OPTIONS=\"--max-old-space-size=8192\" rollup -cw",
1414
"build": "tsc -b && rollup -c",
15-
"postbuild": "node scripts/strip-lib-package-json.js",
15+
"postbuild": "node scripts/strip-lib-package-json.js && node scripts/check-mangled-property-consistency.js",
1616
"package": "pnpm pack --out $PACKAGE_DEST/%s.tgz",
1717
"lint": "eslint src && eslint playwright",
1818
"lint:fix": "eslint src --fix && eslint playwright --fix",
@@ -55,19 +55,19 @@
5555
"react/slim/package.json"
5656
],
5757
"dependencies": {
58+
"@opentelemetry/api": "^1.9.0",
59+
"@opentelemetry/api-logs": "^0.208.0",
60+
"@opentelemetry/exporter-logs-otlp-http": "^0.208.0",
61+
"@opentelemetry/resources": "^2.2.0",
62+
"@opentelemetry/sdk-logs": "^0.208.0",
5863
"@posthog/core": "workspace:*",
5964
"@posthog/types": "workspace:*",
6065
"core-js": "^3.38.1",
6166
"dompurify": "^3.3.2",
6267
"fflate": "^0.4.8",
6368
"preact": "^10.28.2",
6469
"query-selector-shadow-dom": "^1.0.1",
65-
"web-vitals": "^5.1.0",
66-
"@opentelemetry/api": "^1.9.0",
67-
"@opentelemetry/api-logs": "^0.208.0",
68-
"@opentelemetry/exporter-logs-otlp-http": "^0.208.0",
69-
"@opentelemetry/resources": "^2.2.0",
70-
"@opentelemetry/sdk-logs": "^0.208.0"
70+
"web-vitals": "^5.1.0"
7171
},
7272
"devDependencies": {
7373
"@babel/core": "catalog:",
@@ -78,6 +78,7 @@
7878
"@babel/preset-env": "catalog:",
7979
"@babel/preset-typescript": "catalog:",
8080
"@jest/globals": "^29.7.0",
81+
"@jridgewell/sourcemap-codec": "^1.5.5",
8182
"@playwright/test": "^1.52.0",
8283
"@posthog-tooling/rollup-utils": "workspace:*",
8384
"@posthog/rrweb-plugin-console-record": "^0.0.53",
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<html>
2+
<head>
3+
<title>PostHog Slim Bundle + Extension Bundles Test</title>
4+
</head>
5+
<body>
6+
<h1>Slim Bundle Test</h1>
7+
<div id="status">loading...</div>
8+
9+
<script type="module">
10+
import posthog from '/dist/module.slim.js'
11+
import {
12+
AllExtensions,
13+
FeatureFlagsExtensions,
14+
ErrorTrackingExtensions,
15+
ToolbarExtensions,
16+
SurveysExtensions,
17+
SessionReplayExtensions,
18+
AnalyticsExtensions,
19+
ExperimentsExtensions,
20+
ConversationsExtensions,
21+
LogsExtensions,
22+
ProductToursExtensions,
23+
SiteAppsExtensions,
24+
TracingExtensions,
25+
} from '/dist/extension-bundles.js'
26+
27+
window.posthog = posthog
28+
window.AllExtensions = AllExtensions
29+
window.FeatureFlagsExtensions = FeatureFlagsExtensions
30+
window.ErrorTrackingExtensions = ErrorTrackingExtensions
31+
window.ToolbarExtensions = ToolbarExtensions
32+
window.SurveysExtensions = SurveysExtensions
33+
window.SessionReplayExtensions = SessionReplayExtensions
34+
window.AnalyticsExtensions = AnalyticsExtensions
35+
window.ExperimentsExtensions = ExperimentsExtensions
36+
window.ConversationsExtensions = ConversationsExtensions
37+
window.LogsExtensions = LogsExtensions
38+
window.ProductToursExtensions = ProductToursExtensions
39+
window.SiteAppsExtensions = SiteAppsExtensions
40+
window.TracingExtensions = TracingExtensions
41+
window.__slim_bundle_ready = true
42+
</script>
43+
</body>
44+
</html>

0 commit comments

Comments
 (0)