From 76adaf86b13b0b3f32d88a01e0d913f4aee8036b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Albeza?= Date: Wed, 18 Nov 2026 12:55:02 +0100 Subject: [PATCH] :bug: Count hidden children in render-wasm grid auto-size A grid takes its size from its tracks, so, like CLJS, it skips auto-size only when every child is absolute. Flex still skips hidden children, since its line building leaves them out. Refs #12763 AI-assisted-by: claude-opus-5-5 --- render-wasm/src/shapes.rs | 5 +++++ render-wasm/src/shapes/modifiers.rs | 3 ++- render-wasm/src/shapes/modifiers/common.rs | 14 +++++++++++--- render-wasm/src/shapes/modifiers/flex_layout.rs | 6 +++--- render-wasm/src/shapes/modifiers/grid_layout.rs | 8 ++++---- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/render-wasm/src/shapes.rs b/render-wasm/src/shapes.rs index c8d218dd9b..97703096ef 100644 --- a/render-wasm/src/shapes.rs +++ b/render-wasm/src/shapes.rs @@ -1785,6 +1785,11 @@ impl Shape { } } + /// Whether flex layout places this shape: neither absolute nor hidden. + pub fn is_in_flow(&self) -> bool { + !self.is_absolute() && !self.hidden() + } + pub fn z_index(&self) -> i32 { match &self.layout_item { Some(LayoutItem { diff --git a/render-wasm/src/shapes/modifiers.rs b/render-wasm/src/shapes/modifiers.rs index c46cce21a9..52e8c488cb 100644 --- a/render-wasm/src/shapes/modifiers.rs +++ b/render-wasm/src/shapes/modifiers.rs @@ -1261,6 +1261,7 @@ mod tests { use Child::*; assert_size(auto_frame_size(TestLayout::Grid, InFlow), (200.0, 50.0)); assert_size(auto_frame_size(TestLayout::Grid, Absolute), (500.0, 300.0)); - assert_size(auto_frame_size(TestLayout::Grid, Hidden), (500.0, 300.0)); + // Grid takes its size from its tracks; hidden children still count. + assert_size(auto_frame_size(TestLayout::Grid, Hidden), (200.0, 50.0)); } } diff --git a/render-wasm/src/shapes/modifiers/common.rs b/render-wasm/src/shapes/modifiers/common.rs index b622b94672..fa12ec5e20 100644 --- a/render-wasm/src/shapes/modifiers/common.rs +++ b/render-wasm/src/shapes/modifiers/common.rs @@ -15,11 +15,19 @@ impl GetBounds for HashMap { } } -/// Whether a layout has a child that takes part in the flow (neither absolute -/// nor hidden). Without one there is no content to auto-size the layout to. +/// Whether a flex layout has a child it places (see `Shape::is_in_flow`). pub fn has_in_flow_children(shape: &Shape, shapes: ShapesPoolRef) -> bool { shape .children_ids_iter(true) .filter_map(|id| shapes.get(id)) - .any(|child| !child.is_absolute() && !child.hidden()) + .any(Shape::is_in_flow) +} + +/// Whether a layout has a child that is not absolute. Hidden children count, +/// as in the CLJS layout. +pub fn has_non_absolute_children(shape: &Shape, shapes: ShapesPoolRef) -> bool { + shape + .children_ids_iter(true) + .filter_map(|id| shapes.get(id)) + .any(|child| !child.is_absolute()) } diff --git a/render-wasm/src/shapes/modifiers/flex_layout.rs b/render-wasm/src/shapes/modifiers/flex_layout.rs index af0862e785..6209a5c4c6 100644 --- a/render-wasm/src/shapes/modifiers/flex_layout.rs +++ b/render-wasm/src/shapes/modifiers/flex_layout.rs @@ -202,7 +202,7 @@ fn initialize_tracks( continue; }; - if child.is_absolute() || child.hidden() { + if !child.is_in_flow() { continue; } @@ -686,8 +686,8 @@ pub fn reflow_flex_layout( } } - // Like the CLJS layout, keep the size when there is no content to fit: - // auto-sizing to padding only would collapse the frame. + // With nothing to place, keep the size instead of collapsing to padding. + // CLJS would also size to hidden children; flex here leaves them out. if (layout_axis.is_auto_across || layout_axis.is_auto_main) && has_in_flow_children(shape, shapes) { diff --git a/render-wasm/src/shapes/modifiers/grid_layout.rs b/render-wasm/src/shapes/modifiers/grid_layout.rs index 62d8604e24..24604f19bb 100644 --- a/render-wasm/src/shapes/modifiers/grid_layout.rs +++ b/render-wasm/src/shapes/modifiers/grid_layout.rs @@ -10,7 +10,7 @@ use crate::uuid::Uuid; use std::collections::{HashMap, HashSet, VecDeque}; -use super::common::{has_in_flow_children, GetBounds}; +use super::common::{has_non_absolute_children, GetBounds}; const MIN_SIZE: f32 = 0.01; const MAX_SIZE: f32 = f32::INFINITY; @@ -890,10 +890,10 @@ pub fn reflow_grid_layout( } } - // Like the CLJS layout, keep the size when there is no content to fit: - // auto-sizing to empty tracks would collapse the frame. + // Like the CLJS layout, skip auto-size when every child is absolute: the + // size comes from the tracks, and hidden children still count. if (shape.is_layout_horizontal_auto() || shape.is_layout_vertical_auto()) - && has_in_flow_children(shape, shapes) + && has_non_absolute_children(shape, shapes) { let width = layout_bounds.width(); let height = layout_bounds.height();