From ab051f2e12151ea174f05328b8bf9b849c0c56ac Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 19 May 2025 13:18:10 +0200 Subject: [PATCH] LibWeb: Maintain tree order inside LayoutState Before this change, we were at the mercy of hashed pointer addresses when processing fragment relocation in LayoutState::commit(). This made inline fragment order non-deterministic, causing layouts to shift around seemingly randomly on page reload. By simply using OrderedHashMap, we automatically get tree order processing here. This fixes a bunch of flaky tests on WPT. --- Libraries/LibWeb/Layout/LayoutState.h | 2 +- .../inline-fragment-ordering-flakiness.txt | 17 +++++++++++++++++ .../inline-fragment-ordering-flakiness.html | 9 +++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/inline-fragment-ordering-flakiness.txt create mode 100644 Tests/LibWeb/Layout/input/inline-fragment-ordering-flakiness.html diff --git a/Libraries/LibWeb/Layout/LayoutState.h b/Libraries/LibWeb/Layout/LayoutState.h index 7c0243a0554..08b787c4121 100644 --- a/Libraries/LibWeb/Layout/LayoutState.h +++ b/Libraries/LibWeb/Layout/LayoutState.h @@ -205,7 +205,7 @@ struct LayoutState { UsedValues& get_mutable(NodeWithStyle const&); UsedValues const& get(NodeWithStyle const&) const; - HashMap, NonnullOwnPtr> used_values_per_layout_node; + OrderedHashMap, NonnullOwnPtr> used_values_per_layout_node; private: void resolve_relative_positions(); diff --git a/Tests/LibWeb/Layout/expected/inline-fragment-ordering-flakiness.txt b/Tests/LibWeb/Layout/expected/inline-fragment-ordering-flakiness.txt new file mode 100644 index 00000000000..0c654485df3 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/inline-fragment-ordering-flakiness.txt @@ -0,0 +1,17 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x18 [BFC] children: inline + InlineNode + frag 0 from BlockContainer start: 0, length: 0, rect: [8,0 36.84375x18] baseline: 13.796875 + frag 1 from TextNode start: 0, length: 5, rect: [8,0 36.84375x18] baseline: 13.796875 + "hello" + BlockContainer
at (8,0) content-size 36.84375x18 inline-block [BFC] children: not-inline + BlockContainer
at (8,0) content-size 36.84375x18 children: inline + TextNode <#text> + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x18] + PaintableWithLines (InlineNode) + PaintableWithLines (BlockContainer
) [8,0 36.84375x18] + PaintableWithLines (BlockContainer
) [8,0 36.84375x18] + TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/Layout/input/inline-fragment-ordering-flakiness.html b/Tests/LibWeb/Layout/input/inline-fragment-ordering-flakiness.html new file mode 100644 index 00000000000..8d268e34c16 --- /dev/null +++ b/Tests/LibWeb/Layout/input/inline-fragment-ordering-flakiness.html @@ -0,0 +1,9 @@ +
hello