Skip to content

Commit

Permalink
fix: check parent layouts only if path has a layout (#20214) (#20217)
Browse files Browse the repository at this point in the history
Prevents NPE during hotswap when checking if changed classes
are layouts for current active target.

Co-authored-by: Marco Collovati <[email protected]>
  • Loading branch information
vaadin-bot and mcollovati authored Oct 10, 2024
1 parent 953f6ad commit 2e633e3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ private UIRefreshStrategy computeRefreshStrategy(UI ui,
// applied auto layout changed
RouteUtil.isAutolayoutEnabled(routeTarget.getTarget(),
currentPath)
&& registry.hasLayout(currentPath)
&& RouteUtil
.collectRouteParentLayouts(
registry.getLayout(currentPath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@ public void onHotswap_pushDisabled_routeClassChanged_UINotRefreshedButLiveReload
Mockito.verify(liveReload).refresh(anyBoolean());
}

@Test
public void onHotswap_pushDisabled_autoLayout_classUnrelatedToUIChanged_noReload()
throws ServiceException {
VaadinSession session = createMockVaadinSession();
hotswapper.sessionInit(new SessionInitEvent(service, session, null));
RefreshTestingUI ui = initUIAndNavigateTo(session,
MyAutoLayoutRoute.class);

hotswapper.onHotswap(new String[] { MyRouteWithChild.class.getName() },
true);

ui.assertNotRefreshed();
Mockito.verify(liveReload, never()).refresh(anyBoolean());
Mockito.verify(liveReload, never()).reload();
}

@Test
public void onHotswap_pushDisabled_routeLayoutClassChanged_UINotRefreshedButLiveReloadTriggered()
throws ServiceException {
Expand Down Expand Up @@ -537,6 +553,23 @@ class NewLayout extends Component implements RouterLayout {
Mockito.verify(liveReload, never()).refresh(anyBoolean());
}

@Test
public void onHotswap_pushEnabled_autoLayout_classUnrelatedToUIChanged_noReload()
throws ServiceException {
VaadinSession session = createMockVaadinSession();
hotswapper.sessionInit(new SessionInitEvent(service, session, null));
RefreshTestingUI ui = initUIAndNavigateTo(session,
MyAutoLayoutRoute.class);
ui.enablePush();

hotswapper.onHotswap(new String[] { MyRouteWithChild.class.getName() },
true);

ui.assertNotRefreshed();
Mockito.verify(liveReload, never()).refresh(anyBoolean());
Mockito.verify(liveReload, never()).reload();
}

@Test
public void onHotswap_pushEnabled_routeChildrenClassChanged_routeRefreshed()
throws ServiceException {
Expand Down

0 comments on commit 2e633e3

Please sign in to comment.