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
UI
being initialized (instantiated perhaps) repeatedly in default Vaadin 14.0.1 app
#6321
Comments
Regarding the UI being re-instantiated with |
When you use When you remove the You can get rid of these requests by manually removing the Service Worker in the browser. In Chrome, this is done through the Application tab in the developer tools. In Firefox, it's done through the Vaadin handles the 404 errors by showing the error view. By default, this is The Service Worker will trigger multiple additional requests that all cause 404 responses which explains why there are a total of 7 UI instances created. The reason you get multiple UIs with Then we finally get to the last open questions about new UI instances when routing. The way this works is that by default, there will be a new UI instance every time the browser loads a new page, i.e. whenever the browser requests a new HTML document to show. If you are navigating using One difference compared to Vaadin 7/8 is how I assume that the log examples you showed where a new UI instance was created through routing were triggered by one of the navigation methods that makes the browser request a new HTML document. Based on that, I would say that all parts are working as they should, even though I also understand that some of the details are not quite obvious. This in turn means that there isn't really anything to fix in Vaadin (except for the separately tracked #6394). The only thing that could potentially be done would be to improve documentation to make it easier to understand what goes on. On the other hand, I don't have any good idea on exactly what parts of the documentation to tweak in a meaningful way. Based on this, I will close this issue but I would be fine with opening it again if there's some detail that still seems fishy or if there are any concrete ideas on how to improve the documentation. |
For reference, there's also #6395 about the possibility that |
In previous verions of Vaadin, the
UI
object represented the entire content space of a web browser’s window/tab. So a Vaadin app would have one, and only one,UI
object per window/tab for as long as that browser window/tab was open. We should seeUI
objects come and go only when a browser window/tab was opened or closed.➥ Yet in Vaadin 14.0.1 I am seeing the
UI
object being re-instantiated (or re-initialized?) over and over again for a single opened browser window. Is this a bug?Use the Get started with Vaadin page to create a new Vaadin 14 app, of the "Plain Java Servlet" flavor. Make the fewest possible changes needed to show the problem, as discussed next.
Add the
frontend-maven-plugin
via the Maven POM as discribed on Stack Overflow.Edit the
MainView.java
to add this line:…and disable the
@PWA
line (as we do not need Progressive Web App features).Add another view, so we can practice routing.
Implement a
VaadinServiceInitListener
as described in the manual. In that code, add aUIInitListener
to react to aUI
object being initialized, as discussed in the manual.Create a text file, to active the service listener:
…contining the name of our listener class:
Run Maven
clean
&install
. Then run the Vaadin app via the bundled Jetty server via Maven plugin, from within IntelliJ (in my case).Open a web browser pointing to
localhost:8080
. Click the "Click me" button a few times. Watch the console spew several notices. And manually change the URL to try routing:localhost:8080/other
.When run with only a single web browser loading the app:
➥ What is going on with the
UI
class? Why is it not stable?➥ Why is the
UI
id number incrementing? Are newUI
objects being instantiated?➥ Why on #0 is the listener running more than once? As the same
UI
object being re-initialized? Why, and to what effects?Enabling that
@PWA
annotation line has a calming effect onUI
.➥ Why does
@PWA
affectUI
behavior? Is that another bug or a feature?➥ But we seem to still be getting new
UI
instances when routing. Why?None of this fits my previous understanding of
UI
class.For more discussion with many examples and variations enabling/disabling
@PWA
&@PreserveOnRefresh
, see this thread on the Vaadin Forums:UI
being instantiated over and over again in default Vaadin 14.0.1 app.The text was updated successfully, but these errors were encountered: