Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Kamefrede
Copy link

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).

Copy link
Collaborator

@szymonrybczak szymonrybczak left a comment

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
Collaborator

cc @huntie

@huntie
Copy link
Collaborator

huntie commented Mar 10, 2025

LGTM :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants