Skip to content

Commit 0c60de8

Browse files
committed
The style cache has to handle all parents of added or deleted nodes
1 parent 9dd4d6c commit 0c60de8

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
<body>
1010
<release version="4.11.0" date="March xx, 2025" description="Chrome/Edge 134, Firefox 136, Rhino RegExp, less dependencies, Bugfixes">
11+
<action type="fix" dev="rbri" issue="#942">
12+
The style cache has to handle all parents of added or deleted nodes.
13+
</action>
1114
<action type="remove" dev="rbri">
1215
Class HiddenFunctionObject removed, this was a leftover from the IE age.
1316
</action>

src/main/java/org/htmlunit/html/HtmlPage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2783,7 +2783,8 @@ private void nodeChanged(final DomNode changedNode, final String attribName) {
27832783
}
27842784

27852785
// Apparently it wasn't a stylesheet that changed; be semi-smart about what we evict and when.
2786-
final boolean clearParents = ATTRIBUTES_AFFECTING_PARENT.contains(attribName);
2786+
// null means that a node was added/removed; we always have to take care of this for the parents
2787+
final boolean clearParents = attribName == null || ATTRIBUTES_AFFECTING_PARENT.contains(attribName);
27872788
if (computedStylesCache_ != null) {
27882789
computedStylesCache_.nodeChanged(changedNode, clearParents);
27892790
}

src/test/java/org/htmlunit/javascript/host/css/CSSStyleSheetTest.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.htmlunit.WebDriverTestCase;
2525
import org.htmlunit.junit.BrowserRunner;
2626
import org.htmlunit.junit.annotation.Alerts;
27+
import org.htmlunit.junit.annotation.HtmlUnitNYI;
2728
import org.htmlunit.util.MimeType;
2829
import org.htmlunit.util.NameValuePair;
2930
import org.junit.Test;
@@ -2056,8 +2057,14 @@ public void widthHeightPercent() throws Exception {
20562057
* @throws Exception if the test fails
20572058
*/
20582059
@Test
2059-
@Alerts({"0 622 / 722", "1 622 / 722", "2 622 / 722", "3 622 / 722",
2060-
"4 622 / 722", "5 622 / 722", "6 622 / 722"})
2060+
@Alerts(CHROME = "break at: 10 660.5833740234375 / 622",
2061+
EDGE = "break at: 10 660.5833740234375 / 631",
2062+
FF = "break at: 11 726.63330078125 / 676",
2063+
FF_ESR = "break at: 11 726.63330078125 / 677")
2064+
@HtmlUnitNYI(CHROME = "break at: 33 620 / 605",
2065+
EDGE = "break at: 33 620 / 605",
2066+
FF = "break at: 33 620 / 605",
2067+
FF_ESR = "break at: 33 620 / 605")
20612068
public void endlessLoop() throws Exception {
20622069
final String html = DOCTYPE_HTML
20632070
+ "<html>\n"
@@ -2069,16 +2076,21 @@ public void endlessLoop() throws Exception {
20692076
+ "<script>\n"
20702077
+ LOG_TITLE_FUNCTION
20712078

2079+
+ " var lastBottom = 0;\n"
20722080
+ " for (let i = 0; i < 70; i++) {\n"
20732081
+ " let windowRelativeBottom = document.documentElement.getBoundingClientRect().bottom;\n"
2074-
+ " let stop = document.documentElement.clientHeight + 100;"
2082+
+ " let stop = document.documentElement.clientHeight;"
20752083
+ " if (windowRelativeBottom > stop) {\n"
20762084
+ " log('break at: ' + i + ' ' + windowRelativeBottom + ' / ' + stop);\n"
20772085
+ " break;\n"
20782086
+ " }\n"
2079-
+ " log(i + ' ' + windowRelativeBottom + ' / ' + stop);\n"
2087+
+ " if (lastBottom >= windowRelativeBottom) {\n"
2088+
+ " log('error at: ' + i + ' ' + windowRelativeBottom + ' / ' + lastBottom);\n"
2089+
+ " break;\n"
2090+
+ " }\n"
2091+
+ " lastBottom = windowRelativeBottom;\n"
20802092

2081-
+ " document.body.insertAdjacentHTML('beforeend', `<p>Date: ${new Date()}</p>`);\n"
2093+
+ " document.body.insertAdjacentHTML('beforeend', '<h1>H 1</h1>');\n"
20822094
+ " }\n"
20832095
+ "</script>\n"
20842096

0 commit comments

Comments
 (0)