Skip to content

Commit 9ab7052

Browse files
committed
feat: bind to 0.0.0.0 in CI
1 parent 9c014a1 commit 9ab7052

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

packages/bundler-metro/src/factory.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,16 @@ export const getMetroInstance = async (
6666
.use('/status', getStatusMiddleware(projectRoot));
6767

6868
const ready = waitForBundler(reporter, abortSignal);
69-
const metroBindHost = harnessConfig.host?.trim();
69+
const metroBindHost =
70+
harnessConfig.host?.trim() ??
71+
(process.env.CI ? '0.0.0.0' : undefined);
72+
73+
// In CI, bind to all interfaces to avoid connectivity issues on macOS runners
74+
// where Metro is intermittently unreachable from the iOS simulator when bound
75+
// to localhost only.
7076
if (metroBindHost) {
71-
logger.debug(`Binding Metro server to host ${metroBindHost}`);
77+
const source = harnessConfig.host?.trim() ? 'config' : 'CI default';
78+
logger.debug(`Binding Metro server to host ${metroBindHost} (${source})`);
7279
}
7380

7481
const maybeServer = await Metro.runServer(config, {

website/src/docs/getting-started/configuration.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ For Expo projects, the `entryPoint` should be set to the path specified in the `
8484
| `appRegistryComponentName` | **Required.** Name of the component registered with AppRegistry. |
8585
| `runners` | **Required.** Array of test runners (at least one required). |
8686
| `defaultRunner` | Default runner to use when none specified. |
87-
| `host` | Hostname or IP address to bind the Metro server to (default: Metro default). |
87+
| `host` | Hostname or IP address to bind the Metro server to. Defaults to `0.0.0.0` in CI (`process.env.CI` is set) to avoid connectivity issues on macOS runners where Metro may be unreachable from the iOS simulator when bound to `localhost`. |
8888
| `bridgeTimeout` | Bridge timeout in milliseconds (default: `60000`). |
8989
| `bundleStartTimeout` | Bundle start timeout in milliseconds (default: `15000`). |
9090
| `maxAppRestarts` | Maximum number of app restarts when app fails to report ready (default: `2`). |

website/src/docs/guides/ci-cd.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,18 @@ If you're using frameworks like **Expo** or **Rock**, you'll benefit from sophis
225225

226226
This makes caching much more reliable and reduces the need for manual cache management.
227227

228+
## Metro Networking in CI
229+
230+
When running in CI (i.e. the `CI` environment variable is set), React Native Harness automatically binds the Metro server to `0.0.0.0` (all network interfaces) instead of the default `localhost`. This works around intermittent connectivity issues on macOS runners where the iOS Simulator cannot reach Metro when it is bound to `localhost` only.
231+
232+
If you need Metro to bind to a specific interface, set the `host` option in your config — it always takes precedence over the CI default:
233+
234+
```js
235+
const config = {
236+
host: '192.168.1.100',
237+
};
238+
```
239+
228240
## Adapting for Your Project
229241

230242
### React Native Community CLI Projects

0 commit comments

Comments
 (0)