summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMatti Tahvonen <matti@vaadin.com>2018-03-20 14:31:56 +0200
committerTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2018-03-20 14:31:56 +0200
commit803a453a28c00a38e69e9beabe3efe6590486b3f (patch)
treed8927215c035163814cb429ac53584b5c6a06017 /client
parent31eba3b64bdeab39d5fcf666535a1441e2ff6b1b (diff)
downloadvaadin-framework-803a453a28c00a38e69e9beabe3efe6590486b3f.tar.gz
vaadin-framework-803a453a28c00a38e69e9beabe3efe6590486b3f.zip
Prevent reporting browser window resizing too often (#10675)
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java23
1 files changed, 19 insertions, 4 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java b/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java
index ad7a192d14..fc230c2425 100644
--- a/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java
@@ -142,6 +142,8 @@ public class UIConnector extends AbstractSingleComponentContainerConnector
}
};
+ private boolean firstSizeReported;
+
@Override
protected void init() {
super.init();
@@ -200,11 +202,25 @@ public class UIConnector extends AbstractSingleComponentContainerConnector
}-*/;
});
+ // Used to avoid choking server with hundreds of resize events when user
+ // changes the window size
+ Timer lazyFlusher = new Timer() {
+ @Override
+ public void run() {
+ getConnection().getServerRpcQueue().flush();
+ }
+ };
+
getWidget().addResizeHandler(event -> {
getRpcProxy(UIServerRpc.class).resize(event.getWidth(),
event.getHeight(), Window.getClientWidth(),
Window.getClientHeight());
- getConnection().getServerRpcQueue().flush();
+ if(!firstSizeReported) {
+ firstSizeReported = true;
+ getConnection().getServerRpcQueue().flush();
+ } else {
+ lazyFlusher.schedule(100);
+ }
});
getWidget().addScrollHandler(new ScrollHandler() {
private int lastSentScrollTop = Integer.MAX_VALUE;
@@ -415,8 +431,7 @@ public class UIConnector extends AbstractSingleComponentContainerConnector
if (firstPaint) {
// Queue the initial window size to be sent with the following
// request.
- Scheduler.get()
- .scheduleDeferred(() -> ui.sendClientResized());
+ Scheduler.get().scheduleDeferred(() -> ui.sendClientResized());
}
}
@@ -1189,4 +1204,4 @@ public class UIConnector extends AbstractSingleComponentContainerConnector
conf['dragImageCenterOnTouch'] = true;
$wnd.DragDropPolyfill.Initialize(conf);
}-*/;
-} \ No newline at end of file
+}