aboutsummaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorMartin Vysny <martin@vysny.me>2019-06-13 15:03:00 +0300
committerZhe Sun <31067185+ZheSun88@users.noreply.github.com>2019-06-13 15:02:59 +0300
commitd18f8ddbaab2d192dacf7d7485d87b51fe1e7cb9 (patch)
treeaa78b0bfe5a059c6ebca31616020c77b1880a3f6 /server/src
parent4665d366472055c2eeb74dc444346b99b3729ecf (diff)
downloadvaadin-framework-d18f8ddbaab2d192dacf7d7485d87b51fe1e7cb9.tar.gz
vaadin-framework-d18f8ddbaab2d192dacf7d7485d87b51fe1e7cb9.zip
Improved fix for #11614 (#11618)
* #11614: Added test which demonstrates that the fix is incomplete * #11614: UI.doRefresh() only calls navigator when the navigation state actually changes * Added javadoc to Navigator.getCurrentNavigationState() * Minor: Removed accidental star imports
Diffstat (limited to 'server/src')
-rw-r--r--server/src/main/java/com/vaadin/navigator/Navigator.java13
-rw-r--r--server/src/main/java/com/vaadin/ui/UI.java17
2 files changed, 18 insertions, 12 deletions
diff --git a/server/src/main/java/com/vaadin/navigator/Navigator.java b/server/src/main/java/com/vaadin/navigator/Navigator.java
index 7107f7451d..fc22b19c3b 100644
--- a/server/src/main/java/com/vaadin/navigator/Navigator.java
+++ b/server/src/main/java/com/vaadin/navigator/Navigator.java
@@ -1272,4 +1272,17 @@ public class Navigator implements Serializable {
ui.setNavigator(null);
}
+ /**
+ * Returns the current navigation state for which the
+ * {@link #getCurrentView()} has been constructed. This may differ to
+ * {@link #getState()} in case the URL has been changed on the browser and
+ * the navigator wasn't yet given an opportunity to construct new view. The
+ * state is in the form of
+ * <code>current-view-name/optional/parameters</code>
+ *
+ * @return the current navigation state, may be {@code null}.
+ */
+ public String getCurrentNavigationState() {
+ return currentNavigationState;
+ }
}
diff --git a/server/src/main/java/com/vaadin/ui/UI.java b/server/src/main/java/com/vaadin/ui/UI.java
index 2a3b913e16..e48390666e 100644
--- a/server/src/main/java/com/vaadin/ui/UI.java
+++ b/server/src/main/java/com/vaadin/ui/UI.java
@@ -31,6 +31,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -162,12 +163,6 @@ public abstract class UI extends AbstractSingleComponentContainer
this);
/**
- * Holder for old navigation state, needed in doRefresh in order not to call
- * navigateTo too often
- */
- private String oldNavigationState;
-
- /**
* Scroll Y position.
*/
private int scrollTop = 0;
@@ -880,12 +875,10 @@ public abstract class UI extends AbstractSingleComponentContainer
// PushStateNavigation. Call navigateTo only if state have
// truly changed
Navigator navigator = getNavigator();
- if (navigator != null) {
- if (oldNavigationState == null) oldNavigationState = getNavigator().getState();
- if (!navigator.getState().equals(oldNavigationState)) {
- navigator.navigateTo(navigator.getState());
- oldNavigationState = navigator.getState();
- }
+ if (navigator != null
+ && !Objects.equals(navigator.getCurrentNavigationState(),
+ navigator.getState())) {
+ navigator.navigateTo(navigator.getState());
}
}