#2027·yoga

space-around misplaces the first child when children use a measure function

Author: costajohntCreated Sep 20, 2026Updated Sep 21, 2026

justifyContent: space-around places the first child at the wrong position when the children have a measure function. With fixed-size children the layout is correct.

javascript
import Yoga, {FlexDirection, Direction, Justify} from 'yoga-layout';

for (const useMeasure of [false, true]) {
	const root = Yoga.Node.create();
	root.setWidth(5);
	root.setFlexDirection(FlexDirection.Row);
	root.setJustifyContent(Justify.SpaceAround);

	const makeChild = () => {
		const node = Yoga.Node.create();
		if (useMeasure) {
			node.setMeasureFunc(() => ({width: 1, height: 1}));
		} else {
			node.setWidth(1);
			node.setHeight(1);
		}

		return node;
	};

	const a = makeChild();
	const b = makeChild();
	root.insertChild(a, 0);
	root.insertChild(b, 1);
	root.calculateLayout(undefined, undefined, Direction.LTR);
	console.log(`measure=${useMeasure}: a.left=${a.getComputedLeft()} b.left=${b.getComputedLeft()}`);
	root.freeRecursive();
}

Output with yoga-layout 3.2.1 (Node.js 26):

measure=false: a.left=1 b.left=3
measure=true:  a.left=0 b.left=3

Expected a.left=1 in both cases: two 1-wide children in a 5-wide row with space-around get 3 units of free space, so the first child starts at 1 (half of the 1.5 gap, rounded), the second at 3. The second child is placed correctly either way; only the first child loses its leading gap when it is measured rather than sized.

The same happens in a column with justifyContent: space-around and measured children (first child at top 0 instead of 1 in a 5-high column).

Ink (React renderer for the terminal) hits this because every text node is a measured leaf; its two space-around tests for text have been marked as expected failures with a comment pointing at this behavior.