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

Reuse the existing tab in browser when Vaadin app is started in dev mode #18393

Closed
mshabarov opened this issue Jan 3, 2024 · 3 comments · Fixed by #19270
Closed

Reuse the existing tab in browser when Vaadin app is started in dev mode #18393

mshabarov opened this issue Jan 3, 2024 · 3 comments · Fixed by #19270

Comments

@mshabarov
Copy link
Contributor

mshabarov commented Jan 3, 2024

Describe your motivation

When Vaadin application is started in dev mode, it always opens a new tab in browser.
This quickly leads to many tabs opened in browser, which is annoying.
Would be good, if Vaadin reused the existing tab in the browser, if it exists.

Additional context

See BrowserLauncher (Flow repo) and Open library (Separate Vaadin repo).

@tepi
Copy link
Contributor

tepi commented Apr 22, 2024

After some investigation a suitable and reliable enough approach was not found. Via the Open library it is not possible to detect if a certain tab/window is open, or reuse/refresh it.

One idea was to use a marker file which would be written when the browser window is opened for the first time, and on subsequent server starts check if this file exists, and if so, prevent opening another window. Drawbacks here is that we can't really detect if the user has closed the window at some point. A related issue is that it's unclear when and based on what criteria the file should be removed.

One potential option for detecting open tab is the development mode web socket connection. When the server is shut down, the client will keep trying to reconnect every 5000ms. So, when the server is restarted and we get one of these pings, we know that there is an open window for the application and it is enough to refresh that window, which could probably be done with a reload command as a reply to the first ping.

Downside of the last idea is that we would need to have some delayed mechanism on the server side, which would wait for the possible ping, and if it does not arrive, then opens a new window. For the cases when the window is not there, this would of course postpone opening the window, making the application start appear slower. To mitigate this, we could consider making the development mode web socket connection reconnect interval shorter, e.g. 500ms or 1000ms.

@tepi tepi removed their assignment Apr 22, 2024
@caalador
Copy link
Contributor

I have not come up with any better ideas on this either.
Perhaps as there is no way to query for open tabs and waiting for a callback is not that good either we could use the file and check it for the timestamp and after a set time just open a new tab when starting the server. At least it would lessen the opening tabs if the server is restarted often for any reason.

The developer should be able to change the timeout.

@tepi
Copy link
Contributor

tepi commented Apr 26, 2024

I agree, that's pretty much the only reliable thing that can be done here.

@caalador caalador self-assigned this Apr 26, 2024
caalador added a commit that referenced this issue Apr 26, 2024
As we can not know if a tab
for the application is open
we add a file that is checked
for modification time and after
default 30 min we open a new tab on
server restart.

If server is restarted again before
timeout file timestamp is updated.

Clearing build folder will also
cause new tab to open on next restart.

Closes #18393
mshabarov pushed a commit that referenced this issue Apr 29, 2024
* feat: Open tab in dev mode less often

As we can not know if a tab
for the application is open
we add a file that is checked
for modification time and after
default 30 min we open a new tab on
server restart.

If server is restarted again before
timeout file timestamp is updated.

Clearing build folder will also
cause new tab to open on next restart.

Closes #18393

* Unify duplicate code

* Add configuration property and update parameter to launch-browser-delay
mcollovati added a commit to vaadin/docs that referenced this issue Apr 29, 2024
russelljtdyer added a commit to vaadin/docs that referenced this issue May 1, 2024
* chore: document launch-browser-delay property

Refs vaadin/flow#18393

* Initial edits -- just the new text.

* Edited whole document touched.

* Third round of editing whole document touched.

---------

Co-authored-by: Russell JT Dyer <russelljtdyer@users.noreply.github.com>
Co-authored-by: Russell J.T. Dyer <6652767+russelljtdyer@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: September 2024 (24.5)
Development

Successfully merging a pull request may close this issue.

3 participants