Same UI used in different browser tabs for CDI app

I have a Vaadin 24 CDI app running in Wildfly.

In a route view I create a resource during onAttach, and then release it during onDetach. But if a user opens the app in a second browser, this browser shares the same session, UI and the same route CDI bean instance. So when the route is detached in one browser tab, the resource is released, and then an error gets thrown in the other tab where the resource has now been destroyed but the component is still actively attached.

I have tried using the cdi lifecycle postConstruct and preDestroy instead, but the route bean is never destroyed by vaadin, and cannot be explicitly destroyed because the route bean is a dependent scoped cdi bean.

Is there some way that each browser tab can get their own UI/component instance, or some way that an app can determine if the route is open in another tab? Or some general best practice on how to handle such situations?f

Each browser tab is its own UI - so it sounds more like a bug in your implementation / usage. You might checkout Issues · vaadin/cdi · GitHub for an appropriate bug but I don’t think there is one

It might be helpful to post your configuration / annotation usage, otherwise it’s impossible for other CDI users to help you.

I have written one demo application that is have typical examples of how to use Vaadin’s CDI scopes and features. You could review that for the reference.

Thanks for the pointers.

It was indeed a bug that was causing this, but I didn’t know that each tab gets its own UI and so wasn’t looking in the right place.

@Tatu: your app also helped me a lot. I had assumed that each @Route would get the RouteScope as default but it was created with the dependent scope. That meant that I was not able to get conditional CDI events working. With the @RouteScope annotation that is now also working.

Once again, thanks for the help.