🚑 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
This commit is contained in:
alonso.torres 2026-11-04 00:49:54 +01:00
parent 0436156e27
commit b5804addae
2 changed files with 12 additions and 2 deletions

View File

@ -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))))

View File

@ -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