From 0f9f507b46ec416b4e05c876a329df33d3d7a48f Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Fri, 5 Sep 2025 16:49:21 +0200 Subject: [PATCH] layout: Fix `scrollParent` to skip ancestors with `display: contents` (#39153) When encountering such an ancestor, we were returning null instead of skipping it. Testing: Adding new subtest for this. And while I'm at it, another one for the root element, unrelated to this fix. Signed-off-by: Oriol Brufau --- components/layout/query.rs | 7 +++++-- tests/wpt/meta/MANIFEST.json | 2 +- tests/wpt/tests/css/cssom-view/scrollParent.html | 9 ++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/components/layout/query.rs b/components/layout/query.rs index 0a35c24e344..c4630f90f9a 100644 --- a/components/layout/query.rs +++ b/components/layout/query.rs @@ -701,10 +701,13 @@ pub(crate) fn process_scroll_parent_query( continue; }; - let (ancestor_style, ancestor_flags) = ancestor_layout_box + let Some((ancestor_style, ancestor_flags)) = ancestor_layout_box .with_base_flat(|base| vec![(base.style.clone(), base.base_fragment_info.flags)]) .first() - .cloned()?; + .cloned() + else { + continue; + }; let is_containing_block = match current_position_value { Position::Static | Position::Relative | Position::Sticky => { diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json index 08490dc7f0a..1edd12daeed 100644 --- a/tests/wpt/meta/MANIFEST.json +++ b/tests/wpt/meta/MANIFEST.json @@ -630047,7 +630047,7 @@ ] ], "scrollParent.html": [ - "344ee522ef2664e0b963e79812074f08f343f5bf", + "b1c6898af349691d357a3d39cc8fd8e578612d94", [ null, {} diff --git a/tests/wpt/tests/css/cssom-view/scrollParent.html b/tests/wpt/tests/css/cssom-view/scrollParent.html index 344ee522ef2..b1c6898af34 100644 --- a/tests/wpt/tests/css/cssom-view/scrollParent.html +++ b/tests/wpt/tests/css/cssom-view/scrollParent.html @@ -57,6 +57,10 @@ + +
+
+
@@ -82,6 +86,9 @@ test(() => { assert_equals(fixedContainedByRoot.scrollParent, document.scrolling "scrollParent of fixed element contained within root is document scrolling element."); test(() => { assert_equals(document.body.scrollParent, null); }, "scrollParent of body is null."); - +test(() => { assert_equals(document.documentElement.scrollParent, null); }, + "scrollParent of root is null."); +test(() => { assert_equals(childOfDisplayContents.scrollParent, scroller1); }, + "scrollParent skips ancestors with `display: contents`.");