Skip to content

Commit

Permalink
fix: Store layout packages (#20075) (#20085)
Browse files Browse the repository at this point in the history
Store layout packages
in development mode reload
cache as layouts may not be
in same packages as routes.

Fixes #20066

Co-authored-by: caalador <[email protected]>
  • Loading branch information
vaadin-bot and caalador authored Sep 27, 2024
1 parent 59bf5c5 commit 14ee806
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ReloadCache implements Serializable {
static Set<String> skippedResources = new HashSet<>();
static Set<String> dynamicWhiteList;
static Set<String> routePackages;
static Set<String> layoutPackages;
static Set<String> jarClassNames = new HashSet<>();
static Set<Class<?>> jarClasses = new HashSet<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> routePackages = null;
Collection<String> routePackages;
if (devModeCachingEnabled
&& ReloadCache.routePackages != null) {
routePackages = ReloadCache.routePackages;
Expand Down Expand Up @@ -356,11 +356,27 @@ public void failFastContextInitialized(ServletContextEvent event) {
"There are {} navigation targets after filtering route classes: {}",
navigationTargets.size(), navigationTargets);

Collection<String> layoutPackages;
if (devModeCachingEnabled
&& ReloadCache.layoutPackages != null) {
layoutPackages = ReloadCache.layoutPackages;
} else {
layoutPackages = getDefaultPackages();
}

Set<Class<?>> 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))
Expand Down

0 comments on commit 14ee806

Please sign in to comment.