CLI: Reuse existing chromium tab if possible #10329
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue: #10328
What I did
This PR moves from the library open to better-opn. What it does is basically tries to use the well known solution started at CRA, with an applescript to check if there is an existing tab on chrome and if so, reuses it. As a fallback, it uses the
open
lib.This feature is unfortunately available on OSX Chrome only.
better-opn
is entirely based in the solution from facebook, and actually they recently added support for chromium based browsers here. I might add a PR onbetter-opn
to update that as well.The alternatives to support reusing tabs are:
instead of using:
import open from 'better-opn'
use:
import open from 'react-dev-utils/openBrowser'
However they do not recommend to use their internal tools directly because they can always change it without notice. In this particular case, I guess the chances are small though.
How to test
On OSX, checkout the branch and run
yarn start
, then kill the process and run it again.You should see the tab being reused.
I couldn't test on windows, but as the lib falls back to
open
, it should behave the same as before, but of course if someone could test it out would be great.closes #10328