diff --git a/flow-server/src/main/java/com/vaadin/flow/component/UI.java b/flow-server/src/main/java/com/vaadin/flow/component/UI.java index b7e29d02f28..27fb13370fc 100644 --- a/flow-server/src/main/java/com/vaadin/flow/component/UI.java +++ b/flow-server/src/main/java/com/vaadin/flow/component/UI.java @@ -2056,7 +2056,8 @@ private void handleNavigation(Location location, } catch (Exception exception) { handleExceptionNavigation(location, exception); } finally { - if (getInternals().getSession().getConfiguration().isReactEnabled() + if (getInternals().getSession().getService() + .getDeploymentConfiguration().isReactEnabled() && getInternals().getContinueNavigationAction() != null) { getInternals().clearLastHandledNavigation(); } else { diff --git a/flow-server/src/main/java/com/vaadin/flow/component/internal/JavaScriptNavigationStateRenderer.java b/flow-server/src/main/java/com/vaadin/flow/component/internal/JavaScriptNavigationStateRenderer.java index 8fd804060cc..8bcfcc8f828 100644 --- a/flow-server/src/main/java/com/vaadin/flow/component/internal/JavaScriptNavigationStateRenderer.java +++ b/flow-server/src/main/java/com/vaadin/flow/component/internal/JavaScriptNavigationStateRenderer.java @@ -101,8 +101,8 @@ protected Optional handleTriggeredBeforeEvent( @Override protected boolean shouldPushHistoryState(NavigationEvent event) { - if (event.getUI().getInternals().getSession().getConfiguration() - .isReactEnabled()) { + if (event.getUI().getInternals().getSession().getService() + .getDeploymentConfiguration().isReactEnabled()) { return super.shouldPushHistoryState(event); } if (NavigationTrigger.CLIENT_SIDE.equals(event.getTrigger()) diff --git a/flow-server/src/main/java/com/vaadin/flow/component/internal/UIInternals.java b/flow-server/src/main/java/com/vaadin/flow/component/internal/UIInternals.java index f33939089ea..fb6c0dadc88 100644 --- a/flow-server/src/main/java/com/vaadin/flow/component/internal/UIInternals.java +++ b/flow-server/src/main/java/com/vaadin/flow/component/internal/UIInternals.java @@ -858,7 +858,8 @@ public void showRouteTarget(Location viewLocation, Component target, } previous = current; } - if (getSession().getConfiguration().isReactEnabled() + if (getSession().getService().getDeploymentConfiguration() + .isReactEnabled() && getRouter().getRegistry() .getNavigationTarget(viewLocation.getPath()).isEmpty() && target instanceof RouterLayout) { diff --git a/flow-server/src/main/java/com/vaadin/flow/component/page/History.java b/flow-server/src/main/java/com/vaadin/flow/component/page/History.java index 59b648a037f..9059961d197 100644 --- a/flow-server/src/main/java/com/vaadin/flow/component/page/History.java +++ b/flow-server/src/main/java/com/vaadin/flow/component/page/History.java @@ -227,7 +227,8 @@ public void pushState(JsonValue state, Location location, location); // Second parameter is title which is currently ignored according to // https://developer.mozilla.org/en-US/docs/Web/API/History_API - if (ui.getSession().getConfiguration().isReactEnabled()) { + if (ui.getSession().getService().getDeploymentConfiguration() + .isReactEnabled()) { ui.getPage().executeJs( "window.dispatchEvent(new CustomEvent('vaadin-navigate', { detail: { state: $0, url: $1, replace: false, callback: $2 } }));", state, pathWithQueryParameters, callback); @@ -314,7 +315,8 @@ public void replaceState(JsonValue state, Location location, location); // Second parameter is title which is currently ignored according to // https://developer.mozilla.org/en-US/docs/Web/API/History_API - if (ui.getSession().getConfiguration().isReactEnabled()) { + if (ui.getSession().getService().getDeploymentConfiguration() + .isReactEnabled()) { ui.getPage().executeJs( "window.dispatchEvent(new CustomEvent('vaadin-navigate', { detail: { state: $0, url: $1, replace: true, callback: $2 } }));", state, pathWithQueryParameters, callback); diff --git a/flow-server/src/main/java/com/vaadin/flow/router/BeforeLeaveEvent.java b/flow-server/src/main/java/com/vaadin/flow/router/BeforeLeaveEvent.java index 0849bc25460..6349fceb201 100644 --- a/flow-server/src/main/java/com/vaadin/flow/router/BeforeLeaveEvent.java +++ b/flow-server/src/main/java/com/vaadin/flow/router/BeforeLeaveEvent.java @@ -88,7 +88,8 @@ public void proceed() { // If the server updates the url also we will get 2 history // changes instead of 1. if (NavigationTrigger.ROUTER_LINK.equals(event.getTrigger()) - && !event.getUI().getSession().getConfiguration() + && !event.getUI().getSession().getService() + .getDeploymentConfiguration() .isReactEnabled()) { event = new NavigationEvent(event.getSource(), event.getLocation(), event.getUI(), diff --git a/flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java b/flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java index e9866f9e216..2fd1dae7eb1 100644 --- a/flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java +++ b/flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java @@ -296,8 +296,8 @@ private void pushHistoryStateIfNeeded(NavigationEvent event, UI ui) { } ui.getInternals().setLastHandledNavigation(event.getLocation()); - } else if (ui.getInternals().getSession().getConfiguration() - .isReactEnabled()) { + } else if (ui.getInternals().getSession().getService() + .getDeploymentConfiguration().isReactEnabled()) { if (shouldPushHistoryState(event)) { pushHistoryState(event); } diff --git a/flow-server/src/test/java/com/vaadin/flow/component/internal/JavaScriptBootstrapUITest.java b/flow-server/src/test/java/com/vaadin/flow/component/internal/JavaScriptBootstrapUITest.java index 87cfdfc84b0..e12db65a0fa 100644 --- a/flow-server/src/test/java/com/vaadin/flow/component/internal/JavaScriptBootstrapUITest.java +++ b/flow-server/src/test/java/com/vaadin/flow/component/internal/JavaScriptBootstrapUITest.java @@ -48,6 +48,7 @@ import com.vaadin.flow.server.VaadinSession; import com.vaadin.flow.server.VaadinSessionState; import com.vaadin.flow.server.menu.MenuRegistry; +import com.vaadin.tests.util.MockDeploymentConfiguration; public class JavaScriptBootstrapUITest { @@ -419,7 +420,8 @@ public void should_update_pushState_when_navigationHasBeenAlreadyStarted() { .mock(DeploymentConfiguration.class); Mockito.when(internals.getSession()).thenReturn(session); Mockito.when(session.getConfiguration()).thenReturn(configuration); - Mockito.when(configuration.isReactEnabled()).thenReturn(false); + ((MockDeploymentConfiguration) session.getService() + .getDeploymentConfiguration()).setReactEnabled(false); Mockito.when(internals.hasLastHandledLocation()).thenReturn(true); Location lastLocation = new Location("clean"); diff --git a/flow-server/src/test/java/com/vaadin/flow/component/page/HistoryTest.java b/flow-server/src/test/java/com/vaadin/flow/component/page/HistoryTest.java index 146102775c3..229bb399448 100644 --- a/flow-server/src/test/java/com/vaadin/flow/component/page/HistoryTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/component/page/HistoryTest.java @@ -25,6 +25,7 @@ import com.vaadin.flow.component.UI; import com.vaadin.flow.function.DeploymentConfiguration; +import com.vaadin.flow.server.VaadinService; import com.vaadin.flow.server.VaadinSession; import elemental.json.Json; @@ -67,6 +68,7 @@ public PendingJavaScriptResult executeJs(String expression, private TestPage page = new TestPage(ui); private History history; + private VaadinService service = Mockito.mock(VaadinService.class); private VaadinSession session = Mockito.mock(VaadinSession.class); private DeploymentConfiguration configuration; @@ -80,6 +82,10 @@ public PendingJavaScriptResult executeJs(String expression, public void setup() { history = new History(ui); configuration = Mockito.mock(DeploymentConfiguration.class); + + Mockito.when(session.getService()).thenReturn(service); + Mockito.when(service.getDeploymentConfiguration()) + .thenReturn(configuration); Mockito.when(session.getConfiguration()).thenReturn(configuration); Mockito.when(configuration.isReactEnabled()).thenReturn(false); } diff --git a/flow-server/src/test/java/com/vaadin/flow/router/RouterTest.java b/flow-server/src/test/java/com/vaadin/flow/router/RouterTest.java index 86934099013..cabb25afbe4 100644 --- a/flow-server/src/test/java/com/vaadin/flow/router/RouterTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/router/RouterTest.java @@ -64,6 +64,7 @@ import com.vaadin.flow.server.VaadinService; import com.vaadin.flow.server.startup.ApplicationRouteRegistry; import com.vaadin.flow.shared.Registration; +import com.vaadin.tests.util.MockDeploymentConfiguration; import elemental.json.Json; import elemental.json.JsonObject; @@ -2934,6 +2935,9 @@ public void repeatedly_navigating_to_same_ur_through_ui_navigate_should_not_loop @Test public void ui_navigate_should_only_have_one_history_marking_on_loop() throws InvalidRouteConfigurationException { + ((MockDeploymentConfiguration) ui.getSession().getService() + .getDeploymentConfiguration()).setReactEnabled(false); + setNavigationTargets(LoopByUINavigate.class); ui.navigate("loop"); diff --git a/flow-server/src/test/java/com/vaadin/flow/router/internal/NavigationStateRendererTest.java b/flow-server/src/test/java/com/vaadin/flow/router/internal/NavigationStateRendererTest.java index 4691bb7098a..96a615920f1 100644 --- a/flow-server/src/test/java/com/vaadin/flow/router/internal/NavigationStateRendererTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/router/internal/NavigationStateRendererTest.java @@ -848,7 +848,8 @@ private NavigationState navigationStateFromTarget( public void handle_variousInputs_checkPushStateShouldBeCalledOrNot() { // given a service with instantiator MockVaadinServletService service = createMockServiceWithInstantiator(); - + ((MockDeploymentConfiguration) service.getDeploymentConfiguration()) + .setReactEnabled(false); // given a locked session MockVaadinSession session = new AlwaysLockedVaadinSession(service); MockDeploymentConfiguration configuration = new MockDeploymentConfiguration(); diff --git a/flow-tests/test-react-router/src/main/java/com/vaadin/flow/StateView.java b/flow-tests/test-react-router/src/main/java/com/vaadin/flow/StateView.java index 87a4759e387..a9721ecf70b 100644 --- a/flow-tests/test-react-router/src/main/java/com/vaadin/flow/StateView.java +++ b/flow-tests/test-react-router/src/main/java/com/vaadin/flow/StateView.java @@ -29,7 +29,7 @@ public void StateView() { @Override protected void onAttach(AttachEvent attachEvent) { Span enabled = new Span("React enabled: " + getUI().get().getSession() - .getConfiguration().isReactEnabled()); + .getService().getDeploymentConfiguration().isReactEnabled()); enabled.setId(ENABLED_SPAN); File baseDir = attachEvent.getSession().getConfiguration() diff --git a/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/PopStateHandlerView.java b/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/PopStateHandlerView.java index 1e35bbf3bfe..329a39a3a25 100644 --- a/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/PopStateHandlerView.java +++ b/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/PopStateHandlerView.java @@ -30,7 +30,8 @@ protected Element createPushStateButtons(String target) { Element button = ElementFactory.createButton(target).setAttribute("id", target); String historyPush = "window.history.pushState(null, null, event.target.textContent)"; - if (VaadinSession.getCurrent().getConfiguration().isReactEnabled()) { + if (VaadinSession.getCurrent().getService().getDeploymentConfiguration() + .isReactEnabled()) { historyPush = "window.dispatchEvent(new CustomEvent('vaadin-navigate', { detail: { url: event.target.textContent, replace: false } }))"; } button.addEventListener("click", e -> {