fix(build): tree-shake React reconciler dev build to prevent PerformanceMeasure leak (#4462)

The ink 6→7 upgrade (v0.15.11) pulled in react-reconciler 0.33, whose
development build calls performance.measure() on every component render.
Since NODE_ENV was never set to "production" in the esbuild define map,
the bundle shipped both dev and prod builds and selected dev at runtime,
causing an unbounded measureEntryBuffer leak (~45% of heap after moderate
use, confirmed via heap snapshots).

Set process.env.NODE_ENV to "production" at build time so esbuild
statically resolves the conditional require and tree-shakes the entire
15k-line dev build. Bundle shrinks by ~700 KB / 15,800 lines.
This commit is contained in:
胡玮文 2026-05-23 21:00:32 +08:00 committed by GitHub
parent 0cb9ff0a23
commit 61d91ad716
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -112,6 +112,11 @@ esbuild
},
define: {
'process.env.CLI_VERSION': JSON.stringify(pkg.version),
// react-reconciler ≥0.33 (ink 7) gates its dev build behind NODE_ENV
// and calls performance.measure() on every render, leaking
// PerformanceMeasure objects into the global measureEntryBuffer.
// Setting production here tree-shakes the entire dev build (~15k lines).
'process.env.NODE_ENV': JSON.stringify('production'),
// Make global available for compatibility
global: 'globalThis',
// Redirect free __dirname/__filename references to the shim so that