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
Re-use an existing browser tab with with the same URL when launching frontity dev
#374
Conversation
It has a wrong index.d.ts and thus breaking frontity build
… one if it is already open
🦋 Changeset is good to goLatest commit: 2df3446 We got this. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I think this is the kind of change that is a great candidate for e2e testing, but I'm happy to hear other ideas on how you'd test it. |
frontity dev
You should not have used a single PR for two different things because now I can't approve the |
Sure. What are your ideas? |
Is this ready for review or are you going to add tests first? |
So, I don't think that you can test the actual functionality of this change (that it does not open a new tab but rather switch to the existing tab). Or, at least, it would be a bit absurd to try to test it this way... Could we not try to run the cypress e2e tests against a Right now, we're only building and running frontity serve: frontity/.github/workflows/e2e-tests.yml Line 34 in 4d5bdd4
which is calling: Lines 7 to 9 in 107d354
|
Sure, good idea. Maybe we can even add a write to a file to make sure HMR is working. Should we add a |
Have you tested this in Ubuntu and Windows? |
Have you tested this in Ubuntu and Windows?
I haven't because I only have MacOS and no space for a VM on my machine : (
Do you know a cloud VM service that I could use or are you able to test it
yourself?
Should we add a frontity dev e2e test to the testing roadmap? It doesn't feel like it belongs here, right?
I'm not sure. I think we could just add an extra test to launch the e2e test with `frontity dev` just to make sure "it works". There is already an npm script for it:
https://github.com/frontity/frontity/blob/1c68016be047f890c0ae48a7dd4a5b507e3609bc/e2e/package.json#L9
Can I just do it? :)
|
Maybe with https://crossbrowsertesting.com/ or https://www.browserstack.com/?
Sure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent between args and ENV variables we need to change the browser arg of the dev
command too: https://github.com/frontity/frontity/blob/dev/packages/core/src/scripts/dev.ts#L21
Also, to be consistent with the work of #262 you should rename BROWSER
to FRONTITY_BROWSER
.
case Actions.NONE: | ||
// Special case: BROWSER="none" will prevent opening completely. | ||
return false; | ||
case Actions.SCRIPT: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luisherranz I don't exactly know as this was copied 1:1 from create-react-app.
By just looking at the code, it seems that if the value of the BROWSER
environment variable is a .js
script, it executes this script instead of launching a browser. I'm not sure if this is a workaround for some edge case, etc. so I would just keep this code as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't like to add code to the framework without understanding it so please check it out before we merge.
Also, if this covers some use cases, it needs to go to the documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is just an advanced feature, in case you want to run a js script that eventually launches a browser in order to do some initialization, etc. There are some more details here: https://create-react-app.dev/docs/advanced-configuration/
Maybe this could be useful for automated testing with cypress? 🤔
I'm not sure what you mean, or perhaps it's a misunderstanding. That specific option (
The |
Also, should I wait until I add the |
Looking at the code I see that you can use If we go with
Ok. For consistency with the rest of our ENV variables, what about accepting both |
I don't think it is related so whatever you want. |
Right, I see what you mean. I had a look and the current CLI flag is actually
So, I think it's fine if we just keep the BROWSER env variable as is and then the matrix of options is:
With respect to that I don't really have a strong opinion, but one argument in favour of just using the BROWSER variable is that some users might be already familiar with it. I don't see how anybody would be getting confused even if this one variable is not consistent in naming with the rest of variables in frontity 🙂. I think accepting 2 environmental variables that serve the same purpose would be more confusing, in my opinion! |
@luisherranz Could you please check if this works on windows when running I've signed up for browserstack but as far as I can see I only use a browser to look at websites and I cannot use a full windows environment, unfortunately. I've tested it on MacOS and works as expected. On windows it should fall back to just opening a new tab. Let me know if there's anything else stopping this from merging 🙂 |
I've finally managed to run our monorepo in Windows and try this PR, but it's not working: it opens a new tab each time you run I don't know if I'm missing something. I'm off for today but we can take a look together next week. |
@DAreRodz can you test it in Ubuntu? |
I've just tested it and the Maybe it is because the |
Well, it is. Looking at the code, there is only one specific case when the tab can be reused, and is this one: frontity/packages/core/src/scripts/utils/open-browser.ts Lines 66 to 69 in 35966b4
The rest of the covered cases are these (and use frontity/packages/core/src/scripts/utils/open-browser.ts Lines 108 to 129 in 35966b4
|
I see, thanks @DAreRodz. @michalczaplinski can you confirm that? Is this supposed to only work on OSX? |
That's correct! And I'm sorry -that should have been more clear from the beginning. By "works on windows & linux" I meant that it doesn't break anything, but the actual behaviour of preserving the tab only works on MacOS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @michalczaplinski. I'm really sorry it took me so long to review this. Let's merge it now 🙂
What:
When running
frontity dev
, a new browser tab is reopened every time the command is run.Now,
frontity dev
will attempt to re-use the already open browser tab and switch to it instead of opening a new tab, So, if you already have a tab with http://localhost:3000 open in chrome, we just switch to it. This stops the script from opening many tabs with the same location.The implementation is a slightly modified version of create-react-app implementation https://github.com/facebook/create-react-app/blob/master/packages/react-dev-utils/openBrowser.js therefore I have retained the original MIT license in the file.
Additionally, I have pinned thereact-helmet-async
dependency to1.0.4
because in the latest release they have broken the types inindex.d.ts
and it causes an error onnpm install
in our repository. staylor/react-helmet-async#91Tasks:
Unrelated:
Update starter themesUpdate other packagesCommunity discussionsDocumentationUnit testsEnd to end testsTypeScript tests