Skip to content

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

@samulivaadin

Description

@samulivaadin

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    🔖 Normal Priority (P2)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions