[Flight] Guard __webpack_get_script_filename__ for non-Webpack bundlers - #37365
Open
koreahghg wants to merge 1 commit into
Open
[Flight] Guard __webpack_get_script_filename__ for non-Webpack bundlers#37365koreahghg wants to merge 1 commit into
koreahghg wants to merge 1 commit into
Conversation
addChunkDebugInfo called __webpack_get_script_filename__ unconditionally to collect DEV-only chunk debug info. Real Webpack compiles this identifier into a reference to __webpack_require__.u, but bundlers that only emulate the classic Webpack runtime (e.g. Metro) don't define it, so any DEV build throws a ReferenceError the first time a Suspense boundary resolves a client reference with chunks (fixes react#37038). Fall back to __webpack_require__.u, the primitive this call already compiles down to under real Webpack, when the newer global is absent.
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.
Summary
Fixes #37038.
addChunkDebugInfoinReactFlightClientConfigBundlerWebpackBrowser.jscalls__webpack_get_script_filename__(chunkId)unconditionally to collect DEV-only chunk debug/IO info. Real Webpack compiles this identifier into a constant-folded reference to__webpack_require__.u(see Webpack'sAPIPlugin), so it's effectively free there. Bundlers that only emulate the classic Webpack runtime APIs (e.g. Metro, used by Expo) implement__webpack_require__,__webpack_chunk_load__, and__webpack_require__.u, but never define this newer global, so any DEV build throwsReferenceError: Property '__webpack_get_script_filename__' doesn't existthe first time a Suspense boundary resolves a Server Function / client reference with chunks.This is DEV-only (the call is skipped entirely when
!__DEV__), so production builds are unaffected, but it breaks Metro's dev bundle outright.This change guards the call with a
typeofcheck and falls back to__webpack_require__.u(chunkId)— the exact primitive__webpack_get_script_filename__compiles down to under real Webpack, and one this same file already relies on elsewhere (thewebpackGetChunkFilenamepatch a few lines up).How did you test this change?
ReactFlightClientConfigBundlerWebpackBrowser-test.jswith two tests: one simulating a Metro-like environment (__webpack_require__.udefined,__webpack_get_script_filename__absent) assertingaddChunkDebugInfono longer throws and resolves the filename via the fallback; one confirming the real-Webpack global is still preferred when present.ReferenceErroragainst the pre-fix code, and passes after the fix.node ./scripts/prettier/index.js write-changed— clean.node ./scripts/tasks/linc.js— clean.dom-browseranddom-node-webpackrenderers — no errors.node ./scripts/jest/jest-cli.js ReactFlightClientConfigBundlerWebpackBrowser(dev and--prod) — pass; correctly gated out (@gate __DEV__) under--prod.ReactFlightDOMBrowser(60 tests) andreact-server-dom-webpacksuites — same pass/fail counts before and after this change (remaining failures are pre-existing, environment-specific: Windows path separators in a snapshot, and an unrelatedAbortSignal.anyrealm mismatch — confirmed identical on unmodifiedmain).www-classicandwww-modernrelease channels — pass.