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

UIScope and RouteScope does not follow lifecycle of UI instance but actually the attach/detach #1045

Open
samulivaadin opened this issue Nov 23, 2022 · 3 comments

Comments

@samulivaadin
Copy link

samulivaadin commented Nov 23, 2022

Consider scenario where a proxy server breaks a websocket connection and then the "Resynchronizing UI by client’s request" happens. Internally ui.getInternals().getStateTree().prepareForResync() gets called.

What happens next is that the same existing UI instance will receive a detach event and then attach event. This will cause all UIScope and RouteScope beans to be cleaned on detach event and then re-created. So UIScope is not bound to actual UI instance lifecycle, but attach/detach lifecycle.

Documentation (https://vaadin.com/docs/latest/integrations/spring/scopes) talks only about UI lifecycle and nothing about attaching or detaching so either the documentation or implementation has to change.

Also javadoc of UI.onDetach says "Called before the UI is removed from the session. A UI instance is detached exactly once, either..." which is incorrect in this case. UI is not removed from session and onDetach can be called multiple times on same instance because of resync causes detach & attach without creating a new instance.

Observed with Vaadin 23.2.6.

@mvysny
Copy link
Member

mvysny commented Nov 23, 2022

The Vaadin-Spring documentation at https://vaadin.com/docs/latest/integrations/spring/scopes states that:

  • UIScope to target beans to a browser window or tab opened by the user
  • The UIService bean instance is the same inside the same UI

Which is not the case as this ticket shows. Resync in a single tab should keep UI-scoped Spring bean instances, since the UI instance stays the same during the resync.

However, this feels like a bug in Vaadin:

  • UI Javadoc states that UI instance is detached exactly once, however
  • ui.getInternals().getStateTree().prepareForResync() clearly is capable of detaching the UI multiple times on resync.

A ticket should also be filed at https://github.com/vaadin/flow/issues to not to detach/attach UI in case of resync; fixing that ticket will then fix this ticket in turn.

@samulivaadin
Copy link
Author

Here's a simple application to demonstrate this. Without a proxy breaking the websocket is not exactly the same, but the app calls same internals as in real case and the symptoms are reproducible.

scopes.zip

@mvysny
Copy link
Member

mvysny commented Nov 23, 2022

This is related: it's very hard to implement Tab scope in Vaadin atm: vaadin/flow#13468

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🔖 Normal Priority (P2)
Development

No branches or pull requests

4 participants