fix(metro): reload the app's own dev server instead of assuming port 8081

Merged
TH
16h ago
+2564-75

Summary

A flagless metro reload resolved localhost:8081 whenever the session had bound no dev server. That port is another project's, so reload acted on the wrong app or failed as fetch failed.

Reload now resolves in order: the binding (--metro-host/--metro-port/--bundle-url, or what metro prepare or open bound); what the app reports (RCT_jsLocation, iOS simulator only, confirmed by one bounded /status read); then a sweep of ports a local process listens on, for a dev server whose X-React-Native-Project-Root is this directory or a parent or child of it. A server naming another project is never used. With no signal it fails typed: metro_dev_server_unresolved.

Both lookups are gated on one trait open records: the daemon answers on loopback and named the device from its own inventory. Any device attached to this machine, a physical device included, gets the port sweep; only the preferences read is iOS-simulator only. A provider or inherited device, or an app-less session, keeps the old default.

Before / after

Metro on 8096, no flags: fetch failed → reloadUrl: http://127.0.0.1:8096/reload.
No server for this project: localhost:8081 → typed failure.

Validation

Head c7290dc596; CI owns the gate. Live two-server transcript: stand-in servers on 8083/projA and 8082/projB; flagless reload from each directory reloaded only its own, on iPhone Air and an Android emulator, server logs as evidence. Also live: the typed failure from an unserved project; an app-reported address refused from one project and accepted from the other, loopback and LAN; a [::1]-only server.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.