From 4053ea3b38922d568c382580445eb6a8b675fba7 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Wed, 5 Jun 2024 09:10:44 -0700 Subject: [PATCH] Back out "chore(dev-middleware): add `localhost` as default host in `start` command config" (#44800) Summary: This is a revert of https://github.com/facebook/react-native/pull/44244, as we've observed [breaking behaviour](https://github.com/facebook/react-native/pull/44244#issuecomment-2078957734) where Android emulators could not connect to the dev server with default settings. The team doesn't have bandwidth/prio to figure this out with the default `host` value just now, so we are reverting. Changelog: [Internal] (Nullifies c402dcf) Reviewed By: cipolleschi Differential Revision: D58192651 --- packages/community-cli-plugin/src/commands/start/index.js | 2 +- .../community-cli-plugin/src/commands/start/runServer.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/community-cli-plugin/src/commands/start/index.js b/packages/community-cli-plugin/src/commands/start/index.js index 58b957a8cd1e..7cc22efb6618 100644 --- a/packages/community-cli-plugin/src/commands/start/index.js +++ b/packages/community-cli-plugin/src/commands/start/index.js @@ -27,7 +27,7 @@ const startCommand: Command = { }, { name: '--host ', - default: 'localhost', + default: '', }, { name: '--projectRoot ', diff --git a/packages/community-cli-plugin/src/commands/start/runServer.js b/packages/community-cli-plugin/src/commands/start/runServer.js index 18540fa1e2cf..dc8ac0854059 100644 --- a/packages/community-cli-plugin/src/commands/start/runServer.js +++ b/packages/community-cli-plugin/src/commands/start/runServer.js @@ -34,7 +34,7 @@ export type StartCommandArgs = { cert?: string, customLogReporterPath?: string, experimentalDebugger: boolean, - host: string, + host?: string, https?: boolean, maxWorkers?: number, key?: string, @@ -63,13 +63,14 @@ async function runServer( projectRoot: args.projectRoot, sourceExts: args.sourceExts, }); + const hostname = args.host?.length ? args.host : 'localhost'; const { projectRoot, server: {port}, watchFolders, } = metroConfig; const protocol = args.https === true ? 'https' : 'http'; - const devServerUrl = url.format({protocol, hostname: args.host, port}); + const devServerUrl = url.format({protocol, hostname, port}); logger.info(`Welcome to React Native v${ctx.reactNativeVersion}`); @@ -103,7 +104,7 @@ async function runServer( messageSocketEndpoint, eventsSocketEndpoint, } = createDevServerMiddleware({ - host: args.host, + host: hostname, port, watchFolders, });