diff --git a/flow-server/src/main/java/com/vaadin/flow/router/internal/RouteUtil.java b/flow-server/src/main/java/com/vaadin/flow/router/internal/RouteUtil.java index 9cc6dbc0f56..d94b47fa148 100644 --- a/flow-server/src/main/java/com/vaadin/flow/router/internal/RouteUtil.java +++ b/flow-server/src/main/java/com/vaadin/flow/router/internal/RouteUtil.java @@ -596,6 +596,9 @@ public static boolean isAutolayoutEnabled(Class target, String path) { * Checks the given list of Flow routes for potential collisions with Hilla * routes. * + * Note: Routes will only be checked in development mode, when Hilla is in + * use. + * * @param flowRoutes * Flow routes to check against * @throws InvalidRouteConfigurationException @@ -603,22 +606,17 @@ public static boolean isAutolayoutEnabled(Class target, String path) { */ public static void checkForClientRouteCollisions(List flowRoutes) throws InvalidRouteConfigurationException { - VaadinService service = VaadinService.getCurrent(); - if (service == null) { - return; - } - - if (FrontendUtils.isHillaUsed( - service.getDeploymentConfiguration().getFrontendFolder())) { - checkForClientRouteCollisions(flowRoutes.stream() - .map(RouteData::getTemplate).toArray(String[]::new)); - } + checkForClientRouteCollisions(flowRoutes.stream() + .map(RouteData::getTemplate).toArray(String[]::new)); } /** * Checks the given array of Flow route templates for potential collisions * with Hilla routes. * + * Note: Routes will only be checked in development mode, when Hilla is in + * use. + * * @param flowRouteTemplates * Flow routes to check against * @throws InvalidRouteConfigurationException @@ -628,7 +626,10 @@ public static void checkForClientRouteCollisions( String... flowRouteTemplates) throws InvalidRouteConfigurationException { VaadinService service = VaadinService.getCurrent(); - if (service == null) { + if (service == null + || service.getDeploymentConfiguration().isProductionMode() + || !FrontendUtils.isHillaUsed(service + .getDeploymentConfiguration().getFrontendFolder())) { return; } diff --git a/flow-server/src/test/java/com/vaadin/flow/server/menu/MenuRegistryTest.java b/flow-server/src/test/java/com/vaadin/flow/server/menu/MenuRegistryTest.java index 7e8e2149e16..0f46a6655bc 100644 --- a/flow-server/src/test/java/com/vaadin/flow/server/menu/MenuRegistryTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/server/menu/MenuRegistryTest.java @@ -59,6 +59,7 @@ import com.vaadin.flow.server.VaadinServletContext; import com.vaadin.flow.server.VaadinServletService; import com.vaadin.flow.server.VaadinSession; +import com.vaadin.flow.server.frontend.FrontendUtils; import com.vaadin.flow.server.startup.ApplicationRouteRegistry; import static com.vaadin.flow.server.frontend.FrontendUtils.GENERATED; @@ -83,6 +84,8 @@ public class MenuRegistryTest { private AutoCloseable closeable; + private MockedStatic frontendUtils; + @Before public void init() { closeable = MockitoAnnotations.openMocks(this); @@ -102,6 +105,10 @@ public void init() { Mockito.when(deploymentConfiguration.getFrontendFolder()) .thenReturn(tmpDir.getRoot()); + frontendUtils = Mockito.mockStatic(FrontendUtils.class); + frontendUtils.when(() -> FrontendUtils.isHillaUsed(Mockito.any())) + .thenReturn(true); + VaadinService.setCurrent(vaadinService); session = new MockVaadinSession(vaadinService) { @@ -119,6 +126,7 @@ public VaadinService getService() { @After public void cleanup() throws Exception { + frontendUtils.close(); closeable.close(); CurrentInstance.clearAll(); }