From b5804addae4d5c03c1bc35b89342eea2df9e0800 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 4 Nov 2026 00:49:54 +0100 Subject: [PATCH] :ambulance: Keep the gap of a space-around grid without tracks A grid layout with space-around content alignment divides its free space by its number of tracks to find the gap. A grid with no columns or no rows divided by zero, which throws on the JVM and gives an infinite gap in JS. Without tracks there is no space to distribute, so the gap stays the configured one. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 18.284 | 0.52 | | edit-through-a-chain-of-dependents | 68.931 | 36.15 | 0.52 | | library-update-into-copies | 83.083 | 45.659 | 0.55 | | main-edit-among-many-shapes | 4.837 | 2.184 | 0.45 | | main-edit-into-10-copies | 1.79 | 0.925 | 0.52 | | main-edit-into-100-copies | 15.415 | 8.865 | 0.58 | | main-edit-into-1000-copies | 153.086 | 88.254 | 0.58 | | variant-switch-into-copies | 32.052 | 20.181 | 0.63 | AI-assisted-by: claude-opus-5-5 --- .../common/geom/shapes/grid_layout/layout_data.cljc | 4 ++-- common/test/common_tests/geom_grid_layout_test.cljc | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc b/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc index 756eb2924e..1dd7524f40 100644 --- a/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc +++ b/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc @@ -513,7 +513,7 @@ (max column-gap (/ (- bound-width column-total-size) (inc num-columns))) (= :space-around (:layout-justify-content parent)) - (max column-gap (/ (- bound-width column-total-size) num-columns)) + (max column-gap (if (zero? num-columns) column-gap (/ (- bound-width column-total-size) num-columns))) (= :space-between (:layout-justify-content parent)) (max column-gap (if (= num-columns 1) column-gap (/ (- bound-width column-total-size) (dec num-columns)))) @@ -531,7 +531,7 @@ (max row-gap (/ (- bound-height row-total-size) (inc num-rows))) (= :space-around (:layout-align-content parent)) - (max row-gap (/ (- bound-height row-total-size) num-rows)) + (max row-gap (if (zero? num-rows) row-gap (/ (- bound-height row-total-size) num-rows))) (= :space-between (:layout-align-content parent)) (max row-gap (if (= num-rows 1) row-gap (/ (- bound-height row-total-size) (dec num-rows)))) diff --git a/common/test/common_tests/geom_grid_layout_test.cljc b/common/test/common_tests/geom_grid_layout_test.cljc index ac642b2d43..68a9ffaa5b 100644 --- a/common/test/common_tests/geom_grid_layout_test.cljc +++ b/common/test/common_tests/geom_grid_layout_test.cljc @@ -156,6 +156,16 @@ col-gap (:column-gap result)] (t/is (mth/close? 50.0 col-gap 0.01))))) +(t/deftest grid-gap-space-around-without-tracks-keeps-the-gap + (let [frame (make-grid-frame :layout-justify-content :space-around + :layout-align-content :space-around + :layout-grid-columns [] + :layout-grid-rows [] + :layout-gap {:column-gap 5 :row-gap 7}) + result (gld/calc-layout-data frame (bounds-for frame) [] {} {})] + (t/is (mth/close? 5 (:column-gap result))) + (t/is (mth/close? 7 (:row-gap result))))) + (t/deftest grid-column-gap-space-between (t/testing "justify-content :space-between increases column-gap correctly" ;; free = 100; num-cols = 2; formula: 100 / (2-1) = 100