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

RFC: Improve flow starting Metro #613

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
Binary file added assets/improve-flow-starting-metro.mp4
Binary file not shown.
35 changes: 35 additions & 0 deletions proposals/0000-improve-flow-starting-metro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Improve flow starting Metro.
author:
- Szymon Rybczak
date: 2022.03.13
---

# RFC0000: Improve flow starting Metro

## Summary

Right now when starting metro and the port is already in use, we'll get an error `Error: listen EADDRINUSE: address already in use :::8081`, which is not very helpful. We should improve this flow, when the port is already in use, we should ask the users if they want to start Metro on another port, or when the bundler for the project is already running, we should inform user about it.

## Basic example

<https://user-images.githubusercontent.com/63900941/224777083-91066d8a-0922-4b96-b7ac-c210f2c2d7e5.mp4>

## Motivation

This change will improve the developer experience, and will make it easier to start the bundler. All of we know what pain is to search through the terminal windows, and find the window with the running bundler.

## Detailed design

### Changes to the Core

1. Running app from Xcode / Android Studio. During the building process we're starting Metro bundler, and it would be very handy to ask user via prompt to change port if the port is already in use or inform user that bundler is already running for the project.

### Changes to the CLI

1. First part of running commands `run-ios` / `run-android` will be to check if bundler is running for the project, if it is, we should inform the user about it. Or if the port is already in use, we should ask the users if they want to start Metro on another port. It would be in the first part because we need to pass `RCT_METRO_PORT` or `-PreactNativeDevServerPort` to the build command.

## Unresolved questions

- How we should properly handle the case when running app from Xcode / Android Studio? Is it doable to ask via prompt?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently, coordinating Metro start from a native IDE is done only with Xcode (AFAIK), and this is not terminated when the iOS process ends.

  • A prompt on start (or better, detection of a modified RCT_METRO_PORT) might be useful but small UX improvement.
  • However, I don't think we want to invest more in automatically starting/stopping Metro when run from an IDE (and should perhaps remove the iOS project integration! cc @cortinico). We intend for (and are continuing to invest in) Metro to be run as a continuous dev server that serves multiple devices without a restart.

Copy link
Member

Choose a reason for hiding this comment

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

However, I don't think we want to invest more in automatically starting/stopping Metro when run from an IDE (and should perhaps remove the iOS project integration! cc @cortinico)

Yup we should probably remove them.
IDE integration is delegated to 3rd party plugins. Today is totally doable to just create an IntelliJ plugin that starts/stops Metro or just invoke a command before the "Run" step of the app is triggered.

Ideally we should keep our tools agnostic from the IDE they will end up running into

- How could we better handle this on the simulator / emulator side? Right now until we don't type properly port inside DevMenu in simulator / emulator, we won't be able to connect to the bundler.