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

Document how to preserve beans with @RouteScope when migrating from v7/v8 #6395

Closed
Tracked by #4379
denis-anisimov opened this issue Sep 4, 2019 · 5 comments · Fixed by vaadin/docs#2902
Closed
Tracked by #4379

Comments

@denis-anisimov
Copy link
Contributor

Prerequisites:
we have ticket vaadin/spring#473 and vaadin/cdi#293 which are about not preserving UIScopes beans on refresh.

The tickets are in fact consequence of confusion.
But the main idea is still valid: the developer want to preserve on refresh the whole UI instance (instead of specific components) and expects that UIScoped beans are preserved.

@PreserveOnRefresh doesn't fit the expectations and there is a reason for this: it's attached not the a UI instance but rather for a specific route target/component. So it may not work preserving UI beans since one route target may be preserved and another may be not.

What we need is: a way (most likely not via an annotation since we don't recommend to use your own UI instances) to make UI to be preserved on refresh. It may be a (deployment) config parameter or something else.
The way how it works: the whole UI is preserved on refresh (the instance doesn't have to be preserved but all ui scoped beans should be preserved): the ui scope should stay the same when UI is refreshed.

@TatuLund
Copy link
Contributor

TatuLund commented Sep 7, 2019

This is related to #6287

@pleku pleku removed this from P3 - Low Priority in OLD Vaadin Flow bugs & maintenance (Vaadin 10+) Sep 10, 2019
@pleku pleku added this to Inbox - needs triage in OLD Vaadin Flow ongoing work (Vaadin 10+) Dec 16, 2019
@mkn1988
Copy link

mkn1988 commented Jan 29, 2020

Hi,
I'm currently running into this exact issue. Any idea yet, when you'll start working on it?
Greetings,
Max

@thigg
Copy link

thigg commented Apr 16, 2020

One usecase is to store data per tab, for example having seperate login sessions for each tab.
In Vaadin 8 this was commonly done via the UI class.

https://vaadin.com/forum/thread/17810577/17812148 presents a hack, which has several problems.
For one, you need to have an additional root layout for all your views (which is incompatible with AppLayout, because it doesnt like to be a nested layout).
A way to store data which corresponds to a tab without binding it to a specific component would be nice.

@pleku pleku moved this from Inbox - needs triage to Parking lot - under consideration in OLD Vaadin Flow ongoing work (Vaadin 10+) Aug 19, 2020
@caalador caalador removed this from Parking lot - under consideration in OLD Vaadin Flow ongoing work (Vaadin 10+) Oct 9, 2020
@caalador caalador added this to Parking lot - under consideration in OLD Vaadin Flow ongoing work (Vaadin 10+) Oct 9, 2020
@pleku pleku moved this from Parking lot - under consideration to Product backlog in OLD Vaadin Flow ongoing work (Vaadin 10+) May 5, 2021
@pleku pleku moved this from Product backlog to Ready To Go in OLD Vaadin Flow ongoing work (Vaadin 10+) May 5, 2021
@pleku pleku moved this from Ready To Go to Product backlog in OLD Vaadin Flow ongoing work (Vaadin 10+) May 5, 2021
@pleku
Copy link
Contributor

pleku commented Jun 3, 2021

We've decided that this is not worth it - it would be tricky to implement technically which would make the ROI very low.
And we don't want to start to encourage using a custom UI anyway.

Instead you should use other means of storing data to be preserved in the UI - like in case of using CDI/Spring DI - use a @RouteScope bean that is tied with @RouteScopeOwner to the root layout that has the @PreserveOnRefresh.

Acceptance Criteria

  • For now the idea is to just update the migrating from v7/v8 documentation (latest, v14 branches) to highlight that storing data needs to happen elsewhere than in the UI.
  • Add a section to CDI scopes documentation on how to retain beans with @NormalRouteScope + @PreserveOnRefresh https://vaadin.com/docs/latest/flow/integrations/cdi/contexts
    (The Spring Scopes documentation already highlights this)

@pleku pleku moved this from Product backlog to Ready To Go in OLD Vaadin Flow ongoing work (Vaadin 10+) Jun 3, 2021
@pleku pleku changed the title There should be a way to make UI instance "preserved" on refresh Document how to preserve beans with @RouteScope when migrating from v7/v8 Jun 3, 2021
@joheriks joheriks moved this from Ready To Go to Parking lot - under consideration in OLD Vaadin Flow ongoing work (Vaadin 10+) Jan 26, 2022
@Frettman
Copy link

Frettman commented Mar 4, 2022

It's still unfortunate if not downright detrimental that @PreserveOnRefresh and @UIScope are effectively mutually exclusive now. If any library or add-on wants to be usable with @PreserveOnRefresh it cannot use @UIScope (or just store stuff in the UI object). But the combination of @RouteScope and @RouteScopeOwner (or any other shared location) is application-specific and therefore not usable in libraries or add-ons. E.g. I have an add-on that provides an event bus for session and UI scopes. It simply will not work with @PreserveOnRefresh.
As @UIScope seems much more valuable to me, I have pretty much given up on @PreserveOnRefresh. At least for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
OLD Vaadin Flow ongoing work (Vaadin ...
  
Done - pending release
Vaadin Flow enhancements backlog (Vaa...
  
Done / Pending Release
Development

Successfully merging a pull request may close this issue.

9 participants