A grid that hugs its content along an axis took its percent tracks
there as percentages of its current size, which the hug then changed,
so the grid settled only over several reflows, in both engines. Along an
axis the grid hugs, percent tracks are now sized by their content, as
CSS does for a container without a definite size, and the grid settles
in one reflow.
Benchmark (lower quantile, ms):
| world | baseline | now | mean | ratio |
|------------------------------------+----------+---------+---------+-------|
| deepest-edit-through-three-levels | 35.215 | 22.420 | 23.267 | 0.64 |
| edit-through-a-chain-of-dependents | 68.931 | 42.715 | 52.079 | 0.62 |
| library-update-into-copies | 83.083 | 59.152 | 66.682 | 0.71 |
| main-edit-among-many-shapes | 4.837 | 3.469 | 3.887 | 0.72 |
| main-edit-into-10-copies | 1.79 | 1.119 | 1.416 | 0.63 |
| main-edit-into-100-copies | 15.415 | 10.790 | 12.449 | 0.70 |
| main-edit-into-1000-copies | 153.086 | 108.911 | 129.565 | 0.71 |
| variant-switch-into-copies | 32.052 | 23.968 | 26.842 | 0.75 |
AI-assisted-by: claude-opus-5-5
The CLJS grid centered a child horizontally with half its margins, as
CSS and the flex layout do, but vertically it shifted the child by the
whole top and bottom margins. Both axes now center the margin box.
Found by laying out random grid boards in a WASM workspace and reflowing
the same objects with the CLJS engine.
Benchmark (lower quantile, ms):
| world | baseline | now | mean | ratio |
|------------------------------------+----------+---------+---------+-------|
| deepest-edit-through-three-levels | 35.215 | 21.021 | 21.658 | 0.60 |
| edit-through-a-chain-of-dependents | 68.931 | 41.085 | 42.996 | 0.60 |
| library-update-into-copies | 83.083 | 51.898 | 52.585 | 0.62 |
| main-edit-among-many-shapes | 4.837 | 2.255 | 2.395 | 0.47 |
| main-edit-into-10-copies | 1.79 | 1.031 | 1.069 | 0.58 |
| main-edit-into-100-copies | 15.415 | 9.877 | 10.192 | 0.64 |
| main-edit-into-1000-copies | 153.086 | 100.151 | 105.021 | 0.65 |
| variant-switch-into-copies | 32.052 | 22.340 | 23.371 | 0.70 |
AI-assisted-by: claude-opus-5-5
The track editor stores an auto track as {:type :auto :value nil}. The
grid layout summed the flex fractions with (max 1 value) over every track,
which throws on the JVM for a nil value; JavaScript's Math.max(1, null) is
1, so only the frontend laid such a grid out. Only a flex track counts its
value now, at least one fraction.
Test: grid-layout-data-takes-an-auto-track-without-a-value (found by the
new grid gate, which adds an auto row).
Focused: geom-grid-layout-test, 21 tests, 0 failures; the full common
suite runs at the end of this series.
Benchmark (scripts/bench-components, ms, lower 2.5% quantile), measured
with the other production changes of this series in the tree; none of
them is on a measured path:
| :world | :baseline | :now | :mean | :ratio |
|------------------------------------+-----------+---------+---------+--------|
| deepest-edit-through-three-levels | 35.215 | 22.167 | 22.682 | 0.63 |
| edit-through-a-chain-of-dependents | 68.931 | 43.218 | 44.696 | 0.63 |
| library-update-into-copies | 83.083 | 47.824 | 50.506 | 0.58 |
| main-edit-among-many-shapes | 4.837 | 2.216 | 2.34 | 0.46 |
| main-edit-into-10-copies | 1.79 | 1.067 | 1.133 | 0.6 |
| main-edit-into-100-copies | 15.415 | 10.604 | 10.813 | 0.69 |
| main-edit-into-1000-copies | 153.086 | 106.085 | 108.631 | 0.69 |
| variant-switch-into-copies | 32.052 | 22.556 | 23.137 | 0.7 |
AI-assisted-by: claude-opus-5-5
Adding a flex or grid layout derives its direction, gaps and paddings
from the board's children, leaving out the hidden ones, but it checked
for children before leaving them out. A board whose children were all
hidden then failed: flex reduced an empty list of points and grid read
the bounds of no shapes. Making a variant of a hidden main reaches it,
since the new variant board gets a flex layout around the main. Hidden
children are now left out first; with none left, the layout gets the
parameters of a board with no children.
Benchmark (scripts/bench-components, ms, lower 2.5% quantile):
| world | baseline | now | ratio |
|------------------------------------+----------+---------+-------|
| deepest-edit-through-three-levels | 35.215 | 20.267 | 0.58 |
| edit-through-a-chain-of-dependents | 68.931 | 39.871 | 0.58 |
| library-update-into-copies | 83.083 | 45.985 | 0.55 |
| main-edit-among-many-shapes | 4.837 | 1.943 | 0.40 |
| main-edit-into-10-copies | 1.790 | 1.036 | 0.58 |
| main-edit-into-100-copies | 15.415 | 9.998 | 0.65 |
| main-edit-into-1000-copies | 153.086 | 97.836 | 0.64 |
| variant-switch-into-copies | 32.052 | 19.658 | 0.61 |
AI-assisted-by: claude-opus-5-5
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
Adding a flex or grid layout to a board with children derives the
paddings from the distance between the board and its children. A child
that overflows the board, or floating point noise after "Resize board
to fit content", gave negative paddings. The shape schema rejects them
since paddings must be non-negative, so update-file failed and autosave
stopped. Clamp the derived paddings to 0, as the derived gaps already
are.
Closes#12107
AI-assisted-by: claude-opus-5-5
Three critical fixes for app.common.geom.shapes.grid-layout.layout-data:
1. case dispatch on runtime booleans in get-cell-data (case→cond fix)
In get-cell-data, column-gap and row-gap were computed with (case ...)
using boolean locals auto-width? and auto-height? as dispatch values.
In Clojure/ClojureScript, case compares against compile-time constants,
so those branches never matched at runtime. Replaced both case forms
with cond, using explicit equality tests for keyword branches.
2. divide-by-zero guards in fr/auto/span calc (JVM ArithmeticException fix)
Guard against JVM ArithmeticException when all grid tracks are fixed
(no flex or auto tracks):
- (get allocated %1) → (get allocated %1 0) in set-auto-multi-span
- (get allocate-fr-tracks %1) → (get allocate-fr-tracks %1 0) in set-flex-multi-span
- (/ fr-column/row-space column/row-frs) guarded with (zero?) check
- (/ auto-column/row-space column/row-autos) guarded with (zero?) check
In JS, integer division by zero produces Infinity (caught by mth/finite),
but on the JVM it throws before mth/finite can intercept.
3. Exhaustive tests for set-auto-multi-span behavior
Cover all code paths and edge cases:
- span=1 cells filtered out (unchanged track-list)
- empty shape-cells no-op
- even split across multiple auto tracks
- gap deduction per extra span step
- fixed track reducing budget; only auto tracks grow
- smaller children not shrinking existing track sizes (max semantics)
- flex tracks causing cell exclusion (handled by set-flex-multi-span)
- non-spanned tracks preserved via (get allocated %1 0) default
- :row type symmetry with :column type
- row-gap correctly deducted in :row mode
- documents that (sort-by span -) yields ascending order (smaller spans
first), correcting the misleading code comment
All tests pass on both JS (Node.js) and JVM environments.
Signed-off-by: Andrey Antukh <niwi@niwi.nz>