Skip to content

Commit 59bf5c5

Browse files
vaadin-botcaalador
andauthored
fix: Layout should be collected as entyrpoint (#20076) (#20079)
Layout annotated classes should be collected as entrypoints for production builds. Fixes #20074 Co-authored-by: caalador <mikael.grankvist@vaadin.com>
1 parent 5fcb0c6 commit 59bf5c5

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎flow-server/src/main/java/com/vaadin/flow/server/frontend/scanner/FrontendDependencies.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.vaadin.flow.internal.ReflectTools;
5252
import com.vaadin.flow.router.DefaultRoutePathProvider;
5353
import com.vaadin.flow.router.HasErrorParameter;
54+
import com.vaadin.flow.router.Layout;
5455
import com.vaadin.flow.router.Route;
5556
import com.vaadin.flow.router.internal.DependencyTrigger;
5657
import com.vaadin.flow.server.LoadDependenciesOnStartup;
@@ -465,6 +466,11 @@ private void collectEntryPoints(boolean generateEmbeddableWebComponents)
465466
addInternalEntryPoint(initListener);
466467
}
467468

469+
for (Class<?> layout : getFinder().getAnnotatedClasses(
470+
getFinder().loadClass(Layout.class.getName()))) {
471+
addInternalEntryPoint(layout);
472+
}
473+
468474
for (Class<?> appShell : getFinder().getSubTypesOf(
469475
getFinder().loadClass(AppShellConfigurator.class.getName()))) {
470476
addInternalEntryPoint(appShell);

‎flow-server/src/test/java/com/vaadin/flow/server/frontend/scanner/FrontendDependenciesTest.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
import com.vaadin.flow.router.BeforeEnterEvent;
3838
import com.vaadin.flow.router.ErrorParameter;
3939
import com.vaadin.flow.router.HasErrorParameter;
40+
import com.vaadin.flow.router.Layout;
4041
import com.vaadin.flow.router.NotFoundException;
4142
import com.vaadin.flow.router.Route;
43+
import com.vaadin.flow.router.RouterLayout;
4244
import com.vaadin.flow.server.UIInitListener;
4345
import com.vaadin.flow.server.VaadinServiceInitListener;
4446
import com.vaadin.flow.server.frontend.scanner.samples.ErrorComponent;
@@ -280,6 +282,24 @@ public void classInMultipleEntryPoints_collectEntryPointsNotOverrideInitial() {
280282
"@vaadin/common-frontend/ConnectionIndicator.js");
281283
}
282284

285+
@Test // 20074
286+
public void layoutClasses_collectedAsEntrypoint() {
287+
Mockito.when(classFinder.getAnnotatedClasses(Layout.class))
288+
.thenReturn(Collections.singleton(MainLayout.class));
289+
290+
FrontendDependencies dependencies = new FrontendDependencies(
291+
classFinder, false);
292+
293+
Optional<EntryPointData> layoutEndpointData = dependencies
294+
.getEntryPoints().stream().filter(entryPoint -> entryPoint
295+
.getName().equals(MainLayout.class.getName()))
296+
.findAny();
297+
Assert.assertTrue("MainLayout should be visited",
298+
layoutEndpointData.isPresent());
299+
DepsTests.assertImports(dependencies.getModules(), "reference.js",
300+
"@vaadin/common-frontend/ConnectionIndicator.js");
301+
}
302+
283303
@Test // #9861
284304
public void visitedExporter_previousEntryPointsNotOverridden()
285305
throws InstantiationException, IllegalAccessException {
@@ -504,4 +524,9 @@ public static class ChildRoute extends ParentRoute {
504524
public static class GrandChildRoute extends ChildRoute {
505525
}
506526

527+
@Tag("div")
528+
@Layout
529+
@JsModule("reference.js")
530+
public static class MainLayout extends Component implements RouterLayout {
531+
}
507532
}

0 commit comments

Comments
 (0)