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

Registering routes dynamically doesn't work in V24 as V22 #17219

Open
jruizj74 opened this issue Jul 14, 2023 · 3 comments
Open

Registering routes dynamically doesn't work in V24 as V22 #17219

jruizj74 opened this issue Jul 14, 2023 · 3 comments

Comments

@jruizj74
Copy link

Description of the bug

We register our routes dinamically using the RouteConfiguration like this:
RouteConfiguration.forSessionScope()
.setRoute(
"home", //path
HomeView.class, //navigation target
MainLayout.class //one or more parents
);

The MainLayout.class view extends AppLayout.class.
When we start the application the components used in HomeView.class and not used in MainLayout.class are not displayed.
For example in HomeView.class we have a combo-box component but in MainLayout.class there is no combo-box. Then the combo-box is not displayed.
We managed to display all components properly with two differents workarounds:

  • Adding @uses annotations to MainLayout.class with all components.
    or
  • With the option optimizeBundle=false the components

Is this behaviour normal? Which is the best solution? Is there another better solution?
I am not sure if this is the expected behaviour or is a bug. In any case, I think this should be explained in Vaadin documention, at least in "Registering Routes Dynamically" and the "Upgrading Guide"

Thanks in advance.

Expected behavior

When we use Vaadin 22 everything works fine, but we have upgraded v24 and now all components that are not used in parent view are not displayed as we expected.

Minimal reproducible example

The application should have this requirements:

  • Register routers dinamically
  • The views should use the AppLayout
  • There should be components used in children components and not used in the parent view.

Versions

  • Vaadin / Flow version: 24.1.2
  • Java version: 17
  • OS version: Windows 10
  • Browser version (if applicable): any browser
  • Application Server (if applicable): Spring Boot embedded Tomcat
  • IDE (if applicable): any IDE
  • Spring Boot: 3.1.1
@mcollovati mcollovati added this to Needs triage in OLD Vaadin Flow bugs & maintenance (Vaadin 10+) via automation Jul 14, 2023
@mcollovati
Copy link
Collaborator

@jruizj74 could you please provide an example project reproducing the issue?
I tried the steps you posted, but I was unable to reproduce the problem.
The components used only in the runtime registered view were correctly loaded.

Where are you registering the routes? In a VaadinServiceInitListener? or in a view?

@jruizj74
Copy link
Author

We have a View that extends RouteNotFoundError so when initally an user logins and a NotFoundException is thrown this view is loaded. In this view we do the following actions:

  1. We get from Spring Security context a list of routes
  2. We load this routes in route configuration
  3. We forward to a default view

This code snippet shows this actions:

@permitAll
@slf4j
public class ApplicationAccess extends RouteNotFoundError {
...
@OverRide
public int setErrorParameter(BeforeEnterEvent event, ErrorParameter parameter) {

        try {
             ...
	AbstractAuthenticationToken auth = (AbstractAuthenticationToken) SecurityContextHolder.getContext()
				.getAuthentication();
	DatosMenu datosMenu = (DatosMenu) auth.getDetails();
            ...
           for (AccionDTO cadaAccion : datosMenu.getUserActions()) {
                    ....
		Class<? extends Component> act = (Class<? extends Component>) Class.forName(cadaAccion.getClase());
		routeConfiguration.setRoute(cadaAccion.getAccion(), act, MainView.class);
                    ...
           }

           event.forwardTo(defaultClase);
     } catch (Exception ex) {
       log.error("Error configurando las acciones", ex);
}
return HttpServletResponse.SC_NOT_FOUND;

With regard to 'The components used only in the runtime registered view were correctly loaded.', when we watch the source code in the browser the components tags are empty, for example:

I hope this information helps you.

@mcollovati
Copy link
Collaborator

@jruizj74 you are loading the view by reflection, so it is expected that either @Uses or optimizeBundle=false are used,
because the byte code scanner cannot collect information about that class.

Here's the relevant documentation https://vaadin.com/docs/latest/production/production-build#bundle-component-loading-optimizations

Anyway, as you reported, this should be mentioned both in the upgrading guide and Registering Routes Dynamically

@mcollovati mcollovati moved this from Needs triage to Normal Priority (P2) in OLD Vaadin Flow bugs & maintenance (Vaadin 10+) Jul 27, 2023
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

3 participants