fix(native): provide SourceCode.scriptURL so getDevServer resolves#65
Merged
Conversation
RN's getDevServer (Libraries/Core/Devtools/getDevServer.js) reads SourceCode.getConstants().scriptURL and calls .match() on it. Under the native engine the value was undefined, so getDevServer threw and took down any test whose module graph reached it. Return a file:// (bundled) URL for the SourceCode native module in the boundary's device constants. It is deliberately NOT an http(s) URL: getDevServer only treats http(s) script URLs as a live dev server, so a file:// value keeps bundleLoadedFromServer false — tests run as if loaded from a bundle, not a Metro dev server. That prevents RN internals (AssetSourceResolver, symbolicateStackTrace, DevTools) and third-party SDKs from believing they're connected to a packager and attempting real network I/O against localhost:8081, mirroring the intent of RN's own jest mock.
c5feaa1 to
aa8c158
Compare
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.
What
RN's
getDevServer(Libraries/Core/Devtools/getDevServer.js) readsSourceCode.getConstants().scriptURLand calls.match()on it. Under the native enginescriptURLwasundefined, sogetDevServerthrewCannot read properties of undefined (reading 'match')and took down any test whose module graph reached it.The boundary's device constants now return a
file://(bundled) URL for theSourceCodenative module.Why
file://and nothttp://getDevServerderivesbundleLoadedFromServerfrom whetherscriptURLmatches^https?://. Afile://value keeps that flag false, so tests behave as if the bundle was loaded from disk (a release/embedded build) rather than a live Metro dev server. That matters because a truthybundleLoadedFromServermakes RN internals (AssetSourceResolverbuilding live asset fetch URLs,symbolicateStackTracefetching,setUpReactDevToolsopening a WebSocket) and third-party SDKs that readSourceCodedirectly believe they're connected to a packager and attempt real network I/O againstlocalhost:8081— which hangs orECONNREFUSEDs in CI. RN's own Jest mock deliberately keeps this flag off; this mirrors that intent while still returning a defined string so.match()doesn't crash.Why
Surfaced by a Jest→vitest-native migration friction audit.
getDevServeris foundational RN dev plumbing reached by symbolication, DevTools, Expo's async-require, and crash-reporting SDKs; anundefinedscriptURLcrashes any file that touches those paths.Scope / honest note
This is a foundational correctness fix (prevents the
undefined.matchcrash and keepsbundleLoadedFromServerfalse), not a bake-off pass-count mover on its own. In the obytes bake-off it does not unblock thelogin-formfile: withbundleLoadedFromServercorrectly false, Expo'smessageSocket(under__DEV__) throwsCannot create devtools websocket connections in embedded environments— a separate, deeper Expo-init wall tracked independently. (The earlierhttp://value masked this only by letting Expo open a real dev-server WebSocket, which is precisely the network-I/O this PR avoids.)Validation
tests-native/dev-server.test.ts: assertsgetDevServer()resolves without crashing and reportsbundleLoadedFromServer === false(no network I/O).http://value's network-I/O risk; this PR is the correctedfile://version.