-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make inactive nodes mark their children as dirty on setInactive (#4397)
* Make inactive nodes mark their children as dirty on setInactive This moves the setting of dirty nodes out of the collectChanges method. When using long-polling push, the client keeps asking for changes from the server. The server then collects all the changes and sends to the client. The problem is: a child node is always considered `dirty`, if its parent is invisible, and the node is always included in the changes sent to the client. Since there's not a single moment where there's nothing to send, the server keeps sending the changes, and the client keeps asking for the changes. This creates a busy loop between client and server, which only ends when the parent node is made visible again. To prevent this, this patch changes this logic to make the children nodes only dirty when the parent visibility changes. Fix #4353
- Loading branch information
1 parent
eaa5551
commit 6d44f77
Showing
4 changed files
with
137 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/LongPollingPushView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2000-2018 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.uitest.ui; | ||
|
||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.component.html.NativeButton; | ||
import com.vaadin.flow.component.html.Span; | ||
import com.vaadin.flow.component.page.Push; | ||
import com.vaadin.flow.router.Route; | ||
import com.vaadin.flow.shared.ui.Transport; | ||
|
||
/** | ||
* Class for reproducing the bug https://github.com/vaadin/flow/issues/4353 | ||
*/ | ||
@Route("com.vaadin.flow.uitest.ui.LongPollingPushView") | ||
@Push(transport = Transport.LONG_POLLING) | ||
public class LongPollingPushView extends AbstractDivView { | ||
|
||
public LongPollingPushView() { | ||
Div parent = new Div(); | ||
Span child = new Span("Some text"); | ||
child.setId("child"); | ||
parent.add(child); | ||
add(parent); | ||
parent.setVisible(false); | ||
|
||
NativeButton visibility = new NativeButton("Toggle visibility", | ||
e -> parent.setVisible(!parent.isVisible())); | ||
visibility.setId("visibility"); | ||
add(visibility); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/LongPollingPushIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2000-2018 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.uitest.ui; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import com.vaadin.flow.testutil.ChromeBrowserTest; | ||
|
||
public class LongPollingPushIT extends ChromeBrowserTest { | ||
|
||
@Test | ||
public void openPage_thereAreNoErrorsInTheConsole() { | ||
open(); | ||
checkLogsForErrors(); | ||
|
||
waitForElementNotPresent(By.id("child")); | ||
|
||
WebElement button = findElement(By.id("visibility")); | ||
button.click(); | ||
|
||
waitForElementPresent(By.id("child")); | ||
|
||
WebElement span = findElement(By.id("child")); | ||
Assert.assertEquals("Some text", span.getText()); | ||
checkLogsForErrors(); | ||
} | ||
|
||
} |