From cb5a04f82f7e60bb8e87a02a4eb69ec93d120797 Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Fri, 27 Sep 2024 12:35:56 +0300 Subject: [PATCH] fix: Store layout packages Store layout packages in development mode reload cache as layouts may not be in same packages as routes. Fixes #20066 --- .../com/vaadin/flow/spring/ReloadCache.java | 1 + .../VaadinServletContextInitializer.java | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/vaadin-spring/src/main/java/com/vaadin/flow/spring/ReloadCache.java b/vaadin-spring/src/main/java/com/vaadin/flow/spring/ReloadCache.java index 273a0cd0bb3..40446a3ecb8 100644 --- a/vaadin-spring/src/main/java/com/vaadin/flow/spring/ReloadCache.java +++ b/vaadin-spring/src/main/java/com/vaadin/flow/spring/ReloadCache.java @@ -29,6 +29,7 @@ class ReloadCache implements Serializable { static Set skippedResources = new HashSet<>(); static Set dynamicWhiteList; static Set routePackages; + static Set layoutPackages; static Set jarClassNames = new HashSet<>(); static Set> jarClasses = new HashSet<>(); } \ No newline at end of file diff --git a/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinServletContextInitializer.java b/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinServletContextInitializer.java index 52cd193c24a..3983e8bb19c 100644 --- a/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinServletContextInitializer.java +++ b/vaadin-spring/src/main/java/com/vaadin/flow/spring/VaadinServletContextInitializer.java @@ -327,7 +327,7 @@ public void failFastContextInitialized(ServletContextEvent event) { getLogger().debug("There are no discovered routes yet. " + "Start to collect all routes from the classpath..."); try { - Collection routePackages = null; + Collection routePackages; if (devModeCachingEnabled && ReloadCache.routePackages != null) { routePackages = ReloadCache.routePackages; @@ -356,11 +356,27 @@ public void failFastContextInitialized(ServletContextEvent event) { "There are {} navigation targets after filtering route classes: {}", navigationTargets.size(), navigationTargets); + Collection layoutPackages; + if (devModeCachingEnabled + && ReloadCache.layoutPackages != null) { + layoutPackages = ReloadCache.layoutPackages; + } else { + layoutPackages = getDefaultPackages(); + } + Set> layoutClasses = findByAnnotation( - routePackages, Layout.class) + layoutPackages, Layout.class) .collect(Collectors.toSet()); + + if (devModeCachingEnabled) { + ReloadCache.layoutPackages = layoutClasses.stream() + .map(Class::getPackageName) + .collect(Collectors.toSet()); + } + RouteRegistryInitializer .validateLayoutAnnotations(layoutClasses); + // Collect all layouts to use with Hilla as a main layout layoutClasses.stream().filter( clazz -> RouterLayout.class.isAssignableFrom(clazz))