Skip to content

fix(native): provide SourceCode.scriptURL so getDevServer resolves#65

Merged
danfry1 merged 1 commit into
mainfrom
feat/native-sourcecode-scripturl
Jul 1, 2026
Merged

fix(native): provide SourceCode.scriptURL so getDevServer resolves#65
danfry1 merged 1 commit into
mainfrom
feat/native-sourcecode-scripturl

Conversation

@danfry1

@danfry1 danfry1 commented Jul 1, 2026

Copy link
Copy Markdown
Owner

What

RN's getDevServer (Libraries/Core/Devtools/getDevServer.js) reads SourceCode.getConstants().scriptURL and calls .match() on it. Under the native engine scriptURL was undefined, so getDevServer threw Cannot 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 the SourceCode native module.

Why file:// and not http://

getDevServer derives bundleLoadedFromServer from whether scriptURL matches ^https?://. A file:// 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 truthy bundleLoadedFromServer makes RN internals (AssetSourceResolver building live asset fetch URLs, symbolicateStackTrace fetching, setUpReactDevTools opening a WebSocket) and third-party SDKs that read SourceCode directly believe they're connected to a packager and attempt real network I/O against localhost:8081 — which hangs or ECONNREFUSEDs 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. getDevServer is foundational RN dev plumbing reached by symbolication, DevTools, Expo's async-require, and crash-reporting SDKs; an undefined scriptURL crashes any file that touches those paths.

Scope / honest note

This is a foundational correctness fix (prevents the undefined.match crash and keeps bundleLoadedFromServer false), not a bake-off pass-count mover on its own. In the obytes bake-off it does not unblock the login-form file: with bundleLoadedFromServer correctly false, Expo's messageSocket (under __DEV__) throws Cannot create devtools websocket connections in embedded environments — a separate, deeper Expo-init wall tracked independently. (The earlier http:// value masked this only by letting Expo open a real dev-server WebSocket, which is precisely the network-I/O this PR avoids.)

Validation

  • New fixture tests-native/dev-server.test.ts: asserts getDevServer() resolves without crashing and reports bundleLoadedFromServer === false (no network I/O).
  • Full gate green locally: native suite 129, mock suite 1277, typecheck/lint/format clean.
  • Independent adversarial review flagged the original http:// value's network-I/O risk; this PR is the corrected file:// version.

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.
@danfry1 danfry1 force-pushed the feat/native-sourcecode-scripturl branch from c5feaa1 to aa8c158 Compare July 1, 2026 18:46
@danfry1 danfry1 merged commit f6c4c5b into main Jul 1, 2026
17 checks passed
@danfry1 danfry1 deleted the feat/native-sourcecode-scripturl branch July 1, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant