fix(vxrn): wrap dev native bundle in function scope to stop global var leaks#715
Merged
Conversation
…r leaks
rolldown dev() emits the native bundle as a script, so module top-level
vars (RN fetch.js's `var Headers, Request, Response`) leak as
non-configurable global properties. RN's polyfillGlobal then fails
('Failed to set polyfill. Headers is not configurable'), which in dev
becomes a blocking LogBox redbox — the app never mounts, every appium
navigation times out, and the iOS dev jobs hit the 45-min limit.
Wrap everything after the prelude in an IIFE so module top-level vars stay
function-scoped (matching the prod build). The prelude stays at script
scope (it installs globals); the runtime is assigned via globalThis and
HMR updates run through a direct eval, so both survive the wrap.
|
🚅 Deployed to the one-pr-715 environment in onestack.dev
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Native iOS Tests (dev, rolldown)times out (45-min job limit → run cancelled). Root-caused from the cancelled run's failure screenshots: the dev app is stuck on a LogBox redboxFailed to set polyfill. Headers is not configurable., soquick-navigate-pixelnever mounts and every appium navigation waits the full 120s before falling back → the suite blows the timeout.Mechanism (verified against the actual dev bundle)
rolldown's
dev()emits the native bundle as a script. RN'sLibraries/Network/fetch.jsdeclaresvar fetch_hot, fetch$1, Headers, Request, Response$1;at top level — and a top-levelvarin a script creates a non-configurable property on the global object. Soglobal.Headers/global.Requestbecome non-configurable. RN'ssetUpXHRthen runspolyfillGlobal('Headers')→polyfillObjectPropertydoesObject.defineProperty(global, 'Headers', { configurable: true, … }), which throwsCannot redefine property→ RN turns that intoconsole.error('Failed to set polyfill. Headers is not configurable.'). In dev that becomes a blocking redbox.prod is immune: its modules are wrapped in closures (no global leak) and it has no LogBox — which is why
prod, rolldownpasses.Proven in isolation:
Fix
Wrap everything after the prelude in an IIFE (
wrapNativeBundleModuleScope, dev path only) so module top-levelvars stay function-scoped, matching the prod build. The prelude stays at script scope (it deliberately installsglobalThis.global/__DEV__/process/…). Intentional globals survive: the runtime is assigned viaglobalThis.__rolldown_runtime__, and HMR updates run through a directevalinside the wrap, so they still see the closure's helpers/module bindings.Verification
;(function() {is inserted right after the prelude, the leakingvar … Headersdecl is now inside the wrap,})();closes before the (preserved) sourceMappingURL, andnode --checkparses it.wrapNativeBundleModuleScope(wrap structure + no-op without marker + syntactic validity). vxrn suite 39/39, typecheck 0, oxlint 0/0.workflow_dispatchrun of this branch (below).