From bc174915272f22a34cc3dc9824d0adda9ac6f5ab Mon Sep 17 00:00:00 2001 From: Floyd Wang Date: Tue, 9 Dec 2025 00:38:10 +0800 Subject: [PATCH] gpui: Revert grid template columns default behavior to align with Tailwind (#44368) When using the latest version of `GPUI`, I found some grid layout issues. I discovered #43555 modified the default behavior of grid template columns. I checked the implementation at https://tailwindcss.com/docs/grid-template-columns, and it seems our previous implementation was correct. If a grid layout is placed inside a flexbox, the layout becomes unpredictable. ```rust impl Render for HelloWorld { fn render(&mut self, _window: &mut Window, _cx: &mut Context) -> impl IntoElement { div() .flex() .size(px(500.0)) .bg(rgb(0x505050)) .text_xl() .text_color(rgb(0xffffff)) .child( div() .size_full() .gap_1() .grid() .grid_cols(2) .border_1() .border_color(gpui::red()) .children((0..10).map(|ix| { div() .w_full() .border_1() .border_color(gpui::green()) .child(ix.to_string()) })), ) } } ``` | Before | After | | - | - | | After1 | Before1 | I also placed the grid layout example inside a flexbox too. | Before | After | | - | - | | After | Before | I tested the changes from the previous PR, and it seems that setting the table's parent to `v_flex` is sufficient to achieve a non-full table width without modifying the grid layout. This was already done in the previous PR. I reverted the grid changes, the blue border represents the table width. cc @RemcoSmitsDev table So, I believe we should revert to this implementation to align with tailwindcss behavior and avoid potential future problems, especially since the cause of this issue is difficult to pinpoint. Release Notes: - N/A --- crates/gpui/src/taffy.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/gpui/src/taffy.rs b/crates/gpui/src/taffy.rs index c3113ad2cb91ad8c9e29360812716114a7427052..11cb0872861321c3c06c3f8a5bf79fdd30eb2275 100644 --- a/crates/gpui/src/taffy.rs +++ b/crates/gpui/src/taffy.rs @@ -8,7 +8,6 @@ use std::{fmt::Debug, ops::Range}; use taffy::{ TaffyTree, TraversePartialTree as _, geometry::{Point as TaffyPoint, Rect as TaffyRect, Size as TaffySize}, - prelude::min_content, style::AvailableSpace as TaffyAvailableSpace, tree::NodeId, }; @@ -296,7 +295,7 @@ trait ToTaffy { impl ToTaffy for Style { fn to_taffy(&self, rem_size: Pixels, scale_factor: f32) -> taffy::style::Style { - use taffy::style_helpers::{length, minmax, repeat}; + use taffy::style_helpers::{fr, length, minmax, repeat}; fn to_grid_line( placement: &Range, @@ -310,8 +309,8 @@ impl ToTaffy for Style { fn to_grid_repeat( unit: &Option, ) -> Vec> { - // grid-template-columns: repeat(, minmax(0, min-content)); - unit.map(|count| vec![repeat(count, vec![minmax(length(0.0), min_content())])]) + // grid-template-columns: repeat(, minmax(0, 1fr)); + unit.map(|count| vec![repeat(count, vec![minmax(length(0.0), fr(1.0))])]) .unwrap_or_default() }