Skip to content

Commit

Permalink
Only check for conflicts in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tepi committed Oct 14, 2024
1 parent 594b470 commit 3033834
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -596,29 +596,27 @@ 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
* if a collision is detected
*/
public static void checkForClientRouteCollisions(List<RouteData> 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
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -83,6 +84,8 @@ public class MenuRegistryTest {

private AutoCloseable closeable;

private MockedStatic<FrontendUtils> frontendUtils;

@Before
public void init() {
closeable = MockitoAnnotations.openMocks(this);
Expand All @@ -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) {
Expand All @@ -119,6 +126,7 @@ public VaadinService getService() {

@After
public void cleanup() throws Exception {
frontendUtils.close();
closeable.close();
CurrentInstance.clearAll();
}
Expand Down

0 comments on commit 3033834

Please sign in to comment.