Skip to content

Commit

Permalink
fix: Layout should be collected as entyrpoint (#20076)
Browse files Browse the repository at this point in the history
Layout annotated classes should be
collected as entrypoints for
production builds.

Fixes #20074
  • Loading branch information
caalador authored and vaadin-bot committed Sep 27, 2024
1 parent 5fcb0c6 commit 6c47542
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.vaadin.flow.internal.ReflectTools;
import com.vaadin.flow.router.DefaultRoutePathProvider;
import com.vaadin.flow.router.HasErrorParameter;
import com.vaadin.flow.router.Layout;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.internal.DependencyTrigger;
import com.vaadin.flow.server.LoadDependenciesOnStartup;
Expand Down Expand Up @@ -465,6 +466,11 @@ private void collectEntryPoints(boolean generateEmbeddableWebComponents)
addInternalEntryPoint(initListener);
}

for (Class<?> layout : getFinder().getAnnotatedClasses(
getFinder().loadClass(Layout.class.getName()))) {
addInternalEntryPoint(layout);
}

for (Class<?> appShell : getFinder().getSubTypesOf(
getFinder().loadClass(AppShellConfigurator.class.getName()))) {
addInternalEntryPoint(appShell);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.ErrorParameter;
import com.vaadin.flow.router.HasErrorParameter;
import com.vaadin.flow.router.Layout;
import com.vaadin.flow.router.NotFoundException;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouterLayout;
import com.vaadin.flow.server.UIInitListener;
import com.vaadin.flow.server.VaadinServiceInitListener;
import com.vaadin.flow.server.frontend.scanner.samples.ErrorComponent;
Expand Down Expand Up @@ -280,6 +282,24 @@ public void classInMultipleEntryPoints_collectEntryPointsNotOverrideInitial() {
"@vaadin/common-frontend/ConnectionIndicator.js");
}

@Test // 20074
public void layoutClasses_collectedAsEntrypoint() {
Mockito.when(classFinder.getAnnotatedClasses(Layout.class))
.thenReturn(Collections.singleton(MainLayout.class));

FrontendDependencies dependencies = new FrontendDependencies(
classFinder, false);

Optional<EntryPointData> layoutEndpointData = dependencies
.getEntryPoints().stream().filter(entryPoint -> entryPoint
.getName().equals(MainLayout.class.getName()))
.findAny();
Assert.assertTrue("MainLayout should be visited",
layoutEndpointData.isPresent());
DepsTests.assertImports(dependencies.getModules(), "reference.js",
"@vaadin/common-frontend/ConnectionIndicator.js");
}

@Test // #9861
public void visitedExporter_previousEntryPointsNotOverridden()
throws InstantiationException, IllegalAccessException {
Expand Down Expand Up @@ -504,4 +524,9 @@ public static class ChildRoute extends ParentRoute {
public static class GrandChildRoute extends ChildRoute {
}

@Tag("div")
@Layout
@JsModule("reference.js")
public static class MainLayout extends Component implements RouterLayout {
}
}

0 comments on commit 6c47542

Please sign in to comment.