Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/bundler-metro/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,16 @@ export const getMetroInstance = async (
.use('/status', getStatusMiddleware(projectRoot));

const ready = waitForBundler(reporter, abortSignal);
const metroBindHost = harnessConfig.host?.trim();
const metroBindHost =
harnessConfig.host?.trim() ??
(process.env.CI ? '0.0.0.0' : undefined);

// In CI, bind to all interfaces to avoid connectivity issues on macOS runners
// where Metro is intermittently unreachable from the iOS simulator when bound
// to localhost only.
if (metroBindHost) {
logger.debug(`Binding Metro server to host ${metroBindHost}`);
const source = harnessConfig.host?.trim() ? 'config' : 'CI default';
logger.debug(`Binding Metro server to host ${metroBindHost} (${source})`);
}

const maybeServer = await Metro.runServer(config, {
Expand Down
2 changes: 1 addition & 1 deletion website/src/docs/getting-started/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ For Expo projects, the `entryPoint` should be set to the path specified in the `
| `appRegistryComponentName` | **Required.** Name of the component registered with AppRegistry. |
| `runners` | **Required.** Array of test runners (at least one required). |
| `defaultRunner` | Default runner to use when none specified. |
| `host` | Hostname or IP address to bind the Metro server to (default: Metro default). |
| `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`. |
| `bridgeTimeout` | Bridge timeout in milliseconds (default: `60000`). |
| `bundleStartTimeout` | Bundle start timeout in milliseconds (default: `15000`). |
| `maxAppRestarts` | Maximum number of app restarts when app fails to report ready (default: `2`). |
Expand Down
12 changes: 12 additions & 0 deletions website/src/docs/guides/ci-cd.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,18 @@ If you're using frameworks like **Expo** or **Rock**, you'll benefit from sophis

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

## Metro Networking in CI

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.

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:

```js
const config = {
host: '192.168.1.100',
};
```

## Adapting for Your Project

### React Native Community CLI Projects
Expand Down
Loading