Skip to content

Truly independent web browser

LibWeb: Don't replay resolved anchor insets after a style change

Andreas Kling3053de969b3e
diff --git a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs
index dbc56f6eebb..3f7aa281ae5 100644
--- a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs
+++ b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs
@@ -450,6 +450,10 @@ impl LayoutNodeArena {
if inputs.containing_block_info.derives_from_own_computed_values {
return false;
}
+ // What the box's anchor functions resolved to last time says nothing of the style it has now.
+ if inputs.resolved_anchor_insets.is_some() {
+ return false;
+ }
let Some(style) = node_facts::node_style_view(data) else {
return false;
diff --git a/Tests/LibWeb/Text/expected/css/anchor-function-replaced-by-a-length.txt b/Tests/LibWeb/Text/expected/css/anchor-function-replaced-by-a-length.txt
new file mode 100644
index 00000000000..307ff7d57de
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/anchor-function-replaced-by-a-length.txt
@@ -0,0 +1,6 @@
+top before: left 0, top 0, width 5
+top from anchor(--none bottom, 7px) to 1px: left 0, top 1, width 5
+left before: left 0, top 0, width 5
+left from anchor(--none right, 7px) to 1px: left 1, top 0, width 5
+width before: left 0, top 0, width 5
+width from anchor-size(--none width, 7px) to 1px: left 0, top 0, width 1
diff --git a/Tests/LibWeb/Text/input/css/anchor-function-replaced-by-a-length.html b/Tests/LibWeb/Text/input/css/anchor-function-replaced-by-a-length.html
new file mode 100644
index 00000000000..8d65b893a58
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/anchor-function-replaced-by-a-length.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<div style="position: relative; width: 100px; height: 100px"><div id="target" style="position: absolute; width: 5px; height: 5px"></div></div>
+<script>
+ test(() => {
+ const container = target.parentElement.getBoundingClientRect();
+ const report = label => {
+ const { left, top, width } = target.getBoundingClientRect();
+ println(`${label}: left ${left - container.left}, top ${top - container.top}, width ${width}`);
+ };
+
+ // What an anchor function resolved to, here its fallback, holds for the layout it ran in, and no longer once a
+ // length replaces it. The layout before each change gives the box inputs that a later layout may replay.
+ const change = (property, anchored, length) => {
+ report(`${property} before`);
+ target.style[property] = anchored;
+ document.body.offsetWidth;
+ target.style[property] = length;
+ report(`${property} from ${anchored} to ${length}`);
+ target.style[property] = "";
+ };
+ change("top", "anchor(--none bottom, 7px)", "1px");
+ change("left", "anchor(--none right, 7px)", "1px");
+ change("width", "anchor-size(--none width, 7px)", "1px");
+ });
+</script>