.foo) [10,10 780x19.4375] overflow: [11,11 778x17.46875]
+ TextPaintable (TextNode<#text>)
+ PaintableWithLines (BlockContainer
.bar) [10,29.4375 780x19.46875]
+ TextPaintable (TextNode<#text>)
diff --git a/Tests/LibWeb/Layout/input/grid/should-not-cause-infinite-spinning-in-space-distribution.html b/Tests/LibWeb/Layout/input/grid/should-not-cause-infinite-spinning-in-space-distribution.html
new file mode 100644
index 0000000000..869d1bd3b6
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/grid/should-not-cause-infinite-spinning-in-space-distribution.html
@@ -0,0 +1,15 @@
+
foo
bar
\ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
index ca0634789a..96fa2cea95 100644
--- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
@@ -797,9 +797,7 @@ void GridFormattingContext::distribute_extra_space_across_spanned_tracks_base_si
auto extra_space = max(CSSPixels(0), item_size_contribution - spanned_tracks_sizes_sum);
// 2. Distribute space up to limits:
- // FIXME: If a fixed-point type were used to represent CSS pixels, it would be possible to compare with 0
- // instead of epsilon.
- while (extra_space > CSSPixels::epsilon()) {
+ while (true) {
auto all_frozen = all_of(affected_tracks, [](auto const& track) { return track.base_size_frozen; });
if (all_frozen)
break;
@@ -808,6 +806,8 @@ void GridFormattingContext::distribute_extra_space_across_spanned_tracks_base_si
// equally among such tracks, freezing a track’s item-incurred increase as its affected size + item-incurred
// increase reaches its limit
CSSPixels increase_per_track = extra_space / affected_tracks.size();
+ if (increase_per_track == 0)
+ break;
for (auto& track : affected_tracks) {
if (track.base_size_frozen)
continue;
@@ -887,9 +887,7 @@ void GridFormattingContext::distribute_extra_space_across_spanned_tracks_growth_
auto extra_space = max(CSSPixels(0), item_size_contribution - spanned_tracks_sizes_sum);
// 2. Distribute space up to limits:
- // FIXME: If a fixed-point type were used to represent CSS pixels, it would be possible to compare with 0
- // instead of epsilon.
- while (extra_space > CSSPixels::epsilon()) {
+ while (true) {
auto all_frozen = all_of(affected_tracks, [](auto const& track) { return track.growth_limit_frozen; });
if (all_frozen)
break;
@@ -898,6 +896,8 @@ void GridFormattingContext::distribute_extra_space_across_spanned_tracks_growth_
// equally among such tracks, freezing a track’s item-incurred increase as its affected size + item-incurred
// increase reaches its limit
CSSPixels increase_per_track = extra_space / affected_tracks.size();
+ if (increase_per_track == 0)
+ break;
for (auto& track : affected_tracks) {
if (track.growth_limit_frozen)
continue;