Skip to content

[Flight] Guard __webpack_get_script_filename__ for non-Webpack bundlers - #37365

Open
koreahghg wants to merge 1 commit into
react:mainfrom
koreahghg:fix/flight-metro-script-filename
Open

[Flight] Guard __webpack_get_script_filename__ for non-Webpack bundlers#37365
koreahghg wants to merge 1 commit into
react:mainfrom
koreahghg:fix/flight-metro-script-filename

Conversation

@koreahghg

Copy link
Copy Markdown

Summary

Fixes #37038.

addChunkDebugInfo in ReactFlightClientConfigBundlerWebpackBrowser.js calls __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's APIPlugin), 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 throws ReferenceError: Property '__webpack_get_script_filename__' doesn't exist the 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 typeof check 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 (the webpackGetChunkFilename patch a few lines up).

How did you test this change?

  • Added ReactFlightClientConfigBundlerWebpackBrowser-test.js with two tests: one simulating a Metro-like environment (__webpack_require__.u defined, __webpack_get_script_filename__ absent) asserting addChunkDebugInfo no longer throws and resolves the filename via the fallback; one confirming the real-Webpack global is still preferred when present.
  • Verified the new test reproduces the exact reported ReferenceError against the pre-fix code, and passes after the fix.
  • node ./scripts/prettier/index.js write-changed — clean.
  • node ./scripts/tasks/linc.js — clean.
  • Flow, dom-browser and dom-node-webpack renderers — no errors.
  • node ./scripts/jest/jest-cli.js ReactFlightClientConfigBundlerWebpackBrowser (dev and --prod) — pass; correctly gated out (@gate __DEV__) under --prod.
  • Full ReactFlightDOMBrowser (60 tests) and react-server-dom-webpack suites — same pass/fail counts before and after this change (remaining failures are pre-existing, environment-specific: Windows path separators in a snapshot, and an unrelated AbortSignal.any realm mismatch — confirmed identical on unmodified main).
  • Also ran the new test under www-classic and www-modern release channels — pass.

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.
@meta-cla meta-cla Bot added the CLA Signed label Aug 25, 2026
@github-actions

Copy link
Copy Markdown

A size report will appear here when the build finishes.

Generated by sizebot against f572f43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

react-server-dom-webpack@19.2.0 and newer calls __webpack_get_script_filename__ in resolveModuleChunk, which breaks RSC on Expo/Metro

1 participant