Skip to content

fix: force server to always start in a new window on macOS#2628

Merged
thymikee merged 1 commit into
react-native-community:mainfrom
Kamefrede:main
Jun 16, 2025
Merged

fix: force server to always start in a new window on macOS#2628
thymikee merged 1 commit into
react-native-community:mainfrom
Kamefrede:main

Conversation

@Kamefrede

Copy link
Copy Markdown
Contributor

Summary

This PR fixes an issue on macOS where the server wasn't reliably being launched in a new terminal window. The solution involves using the -na flag combination with the open command instead of just -a, which ensures that a new instance of the terminal application is always created.

As per the man entry for open:

DESCRIPTION
     The open command opens a file (or a directory or URL), just as if you had double-clicked the file's icon. If no application name is specified, the default application as determined
     via LaunchServices is used to open the specified files.

     [...]

     -n  Open a new instance of the application(s) even if one is already running.

The issue was identified in a Ghostty discussion which pointed out that some terminals work around the fact that open -a does not inherit the current environment it's being run in by explicitly injecting the environment variables, the standard and reliable way to ensure a new window is created and the environment variables are correctly set is to use the -n flag explicitly with the macOS open command.

This change ensures consistent behavior across all terminal emulators on macOS.

Test Plan

I've verified this change by:

  1. Testing on macOS with multiple terminal emulators (Terminal.app, iTerm2, Ghostty)
  2. Ensuring that running the server now consistently opens in a new terminal window
  3. Checking that the server starts correctly in all cases

To test this yourself:

  • Clone the repo and make this change
  • Launch a React Native project using npx react-native start
  • Verify that a new terminal window opens with the Metro server
  • Try multiple times to confirm consistent behavior, especially with different terminal applications already running

Checklist

  • Documentation is up to date.
  • Follows commit message convention described in CONTRIBUTING.md.
  • For functional changes, my test plan has linked these CLI changes into a local react-native checkout (instructions).

@szymonrybczak szymonrybczak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Thank you for fixing this! I'm also Ghostty user btw :D

@szymonrybczak

Copy link
Copy Markdown
Collaborator

cc @huntie

@huntie

huntie commented Mar 10, 2025

Copy link
Copy Markdown
Collaborator

LGTM :)

@github-actions

github-actions Bot commented Jun 9, 2025

Copy link
Copy Markdown

There hasn't been any activity on this pull request in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

@github-actions github-actions Bot added the stale label Jun 9, 2025
@github-actions github-actions Bot closed this Jun 16, 2025
@thymikee thymikee reopened this Jun 16, 2025
@thymikee thymikee merged commit cb66124 into react-native-community:main Jun 16, 2025
1 check passed
thymikee pushed a commit that referenced this pull request Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4 participants