From 2b31f887973b11804b0d18bbb29195062c193ed7 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 23 Oct 2026 08:46:25 +0200 Subject: [PATCH] :bug: Initialize flex line arithmetic before placing the first child The first layout line starts as nil. JavaScript arithmetic treated its missing count and bounds as zero, while the JVM threw. Give those three values zero defaults before calculating gaps and the next line bounds. A regression failed on the JVM before the fix. Six combinations of row and column layout with start, around and even spacing now pass. Existing flex tests pass too; the layout oracle fixtures pass on the JVM. AI-assisted-by: GPT-6 --- .../geom/shapes/flex_layout/layout_data.cljc | 3 ++- .../test/common_tests/geom_flex_layout_test.cljc | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/geom/shapes/flex_layout/layout_data.cljc b/common/src/app/common/geom/shapes/flex_layout/layout_data.cljc index dfdd8cd094..da81f5b876 100644 --- a/common/src/app/common/geom/shapes/flex_layout/layout_data.cljc +++ b/common/src/app/common/geom/shapes/flex_layout/layout_data.cljc @@ -63,7 +63,8 @@ {:keys [line-min-width line-min-height line-max-width line-max-height num-children - children-data]} line-data + children-data] + :or {line-min-width 0 line-min-height 0 num-children 0}} line-data child-width (gpo/width-points child-bounds) child-height (gpo/height-points child-bounds) diff --git a/common/test/common_tests/geom_flex_layout_test.cljc b/common/test/common_tests/geom_flex_layout_test.cljc index 4e6f6a149c..746b2cbef1 100644 --- a/common/test/common_tests/geom_flex_layout_test.cljc +++ b/common/test/common_tests/geom_flex_layout_test.cljc @@ -6,7 +6,9 @@ (ns common-tests.geom-flex-layout-test (:require + [app.common.geom.modifiers] [app.common.geom.rect :as grc] + [app.common.geom.shapes.flex-layout.layout-data :as fld] [app.common.geom.shapes.flex-layout.params :as flparams] [app.common.geom.shapes.flex-layout.positions :as flp] [app.common.math :as mth] @@ -135,3 +137,16 @@ :y -2.1457672119140625E-6 :width 100 :height 100}))] (t/is (every? #(not (neg? %)) (vals padding))))) + +(t/deftest first-child-starts-a-flex-line-on-both-runtimes + (doseq [direction [:row :column] + justify [:start :space-around :space-evenly]] + (let [frame (make-col-frame :layout-flex-dir direction :layout-justify-content justify) + child (cts/setup-shape {:type :rect :x 0 :y 0 :width 40 :height 30}) + bounds (rect->bounds (grc/make-rect 0 0 200 200)) + child-bounds (rect->bounds (grc/make-rect 0 0 40 30)) + objects {(:id frame) frame (:id child) child} + lines (fld/init-layout-lines frame [[child-bounds child]] bounds + {(:id frame) bounds (:id child) child-bounds} objects false)] + (t/is (= 1 (count lines))) + (t/is (= 1 (:num-children (first lines)))))))