diff --git a/kernel/tests/it/browser_cases.rs b/kernel/tests/it/browser_cases.rs index 55728c092..4d147da3a 100644 --- a/kernel/tests/it/browser_cases.rs +++ b/kernel/tests/it/browser_cases.rs @@ -284,6 +284,61 @@ fn patterned_border_widths_follow_chrome_layout() { assert!(failures.is_empty(), "{}", failures.join("\n")); } +/// Chrome 156, 2026-12-01: a grid with no items is as big as its explicit +/// tracks, gaps and padding (CSS Grid 1 §7.1), in a block, in a shrinking +/// flex column and as a flex item beside a sibling. A display: none child +/// (an item the grid keeps in its tree) is the control that already matched. +#[test] +fn a_grid_with_no_items_keeps_its_explicit_tracks() { + let mut failures = Vec::new(); + let mut case = |name: &str, root: &str, nodes: Vec<(u32, u32, Rows)>, want: &[_]| { + failures.extend(mismatches( + name, + &lay_out(props(&css_rows(root)), nodes, &[]), + want, + )); + }; + let rows = "display:grid;grid-template-rows:22px 30px;gap:4px"; + case( + "rows in a block", + "width:300px;height:200px", + vec![(2, 1, css_rows(rows))], + &[(2, [0.0, 0.0, 300.0, 56.0])], + ); + case( + "rows in a block, a display: none child", + "width:300px;height:200px", + vec![(2, 1, css_rows(rows)), (3, 2, css_rows("display:none"))], + &[(2, [0.0, 0.0, 300.0, 56.0])], + ); + case( + "both axes in a shrinking column", + "width:300px;height:200px;display:flex;flex-direction:column;align-items:flex-start", + vec![( + 2, + 1, + css_rows( + "display:grid;grid-template-rows:22px;grid-template-columns:40px 10px;gap:6px;padding:3px", + ), + )], + &[(2, [0.0, 0.0, 62.0, 28.0])], + ); + case( + "columns beside a flex sibling", + "width:300px;height:200px;display:flex", + vec![ + ( + 2, + 1, + css_rows("display:grid;grid-template-columns:1fr 50px"), + ), + (3, 1, css_rows("width:20px;height:20px")), + ], + &[(2, [0.0, 0.0, 50.0, 200.0]), (3, [50.0, 0.0, 20.0, 20.0])], + ); + assert!(failures.is_empty(), "{}", failures.join("\n")); +} + /// A 400px-wide `display: grid` with these rows and track lists. fn grid(rows: Rows, columns: &[GridTrack], track_rows: &[GridTrack]) -> StyleProps { let mut p = props(&[vec![(Display, t("grid")), (Width, n(400.0))], rows].concat()); diff --git a/vendor/taffy/EXACT-PATCHES.md b/vendor/taffy/EXACT-PATCHES.md index 43c33981d..741c72fe1 100644 --- a/vendor/taffy/EXACT-PATCHES.md +++ b/vendor/taffy/EXACT-PATCHES.md @@ -2638,3 +2638,16 @@ algorithm and, where it applies, Chrome 159) and `kernel/tests/it/fixtures/browser_intrinsic.tsv` against Chrome 159: a percentage height under the column's height that reaches a ratio, and a nested wrapping column. + +## Patch 85: a grid with no items keeps its explicit tracks + +`TaffyView::compute_child_layout` dispatched a `display: grid` node without +children as a leaf, so a grid with `grid-template-rows: 22px 30px` and no +items was 0 tall, and one with `grid-template-columns: 40px 10px` in a +shrinking flex column was as narrow as its padding. CSS Grid 1 §7.1: the +explicit grid's tracks exist whether or not items fill them, and Chrome sizes +an empty grid to its tracks and gaps. A childless grid without a measure +context now runs the grid algorithm; a measured leaf (a text) keeps its +measure. + +**Held by** `kernel/tests/it/browser_cases.rs::a_grid_with_no_items_keeps_its_explicit_tracks`. diff --git a/vendor/taffy/src/tree/taffy_tree.rs b/vendor/taffy/src/tree/taffy_tree.rs index e60367afd..6767a10fb 100644 --- a/vendor/taffy/src/tree/taffy_tree.rs +++ b/vendor/taffy/src/tree/taffy_tree.rs @@ -690,6 +690,12 @@ where (Display::Flex, true) => compute_flexbox_layout(tree, node_id, inputs), #[cfg(feature = "grid")] (Display::Grid, true) => tree.grid(node_id, inputs), + // EXACT PATCH 85: a grid with no items still has its explicit tracks and + // gaps (CSS Grid 1 §7.1); a measured leaf stays its measure's + #[cfg(feature = "grid")] + (Display::Grid, false) if !tree.taffy.nodes[node_id.into()].has_context => { + tree.grid(node_id, inputs) + } (_, false) => { let node_key = node_id.into(); // EXACT PATCH 30: a multi-column leaf (a paragraph) reports its height