Measured nodes in a cached subtree grow by a rounding step on every layout pass

オープン
#2,053 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@salmanmkc がすでに取り組んでいます。

2026年10月30日 から。

  • #2054 @salmanmkc による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp, javascript, node.js
領域
frontend

調査の方向性

Start by running the provided Node.js reproduction with Yoga 3.2.1 and compare it with the point-scale-factor-zero result. Trace how calculateLayout handles cached subtrees and pixel-grid rounding for measured nodes; the payload does not name source files or tests. Done when repeated layout passes leave unchanged measured-node heights at 28.8 and a regression test covers this cached-subtree case.

索引モデルが issue の本文から書いたものです。

説明

With a point scale factor set, measured nodes inside a subtree that comes from the layout cache grow by a rounding step on many calculateLayout calls, and keep growing. In a UI where one node changes size every frame (a progress bar), text boxes grow until the text, centered in its box, drifts onto the next line.

Repro with yoga-layout 3.2.1 on Node 26 (macOS arm64):

// yoga-layout 3.2.1: measured nodes in a cached subtree grow on every layout pass.
import Yoga, {Edge, FlexDirection, PositionType} from 'yoga-layout';

const config = Yoga.Config.create();
config.setPointScaleFactor(100); // round to 0.01 layout units

const root = Yoga.Node.create(config);
root.setWidth(620);
root.setPadding(Edge.All, 24.3);

// Changing this sibling's width relays out the root, while the list
// below is served from the layout cache.
const bar = Yoga.Node.create(config);
bar.setHeight(8);
bar.setWidth(10);
root.insertChild(bar, 0);

const spacer = Yoga.Node.create(config);
spacer.setHeight(517.37);
root.insertChild(spacer, 1);

const anchor = Yoga.Node.create(config);
anchor.setHeight(50.8);
root.insertChild(anchor, 2);

const list = Yoga.Node.create(config);
list.setPositionType(PositionType.Absolute);
list.setPosition(Edge.Bottom, '110%');
anchor.insertChild(list, 0);

const labels = [];
for (let i = 0; i < 30; i++) {
  const row = Yoga.Node.create(config);
  row.setFlexDirection(FlexDirection.Row);
  row.setPadding(Edge.Vertical, 10);
  const label = Yoga.Node.create(config);
  label.setMeasureFunc(() => ({width: 70.37, height: 28.8}));
  row.insertChild(label, 0);
  list.insertChild(row, i);
  labels.push(label);
}

// Each label measures 28.8 tall; print the ones whose layout height grew.
const grown = () =>
  labels
    .map((label, i) => [i + 1, label.getComputedHeight()])
    .filter(([, h]) => h > 28.8 + 0.005)
    .map(([i, h]) => `#${i}=${h.toFixed(2)}`)
    .join(' ') || '(none)';

root.calculateLayout(undefined, undefined);
console.log('pass 0   ', grown());
for (let pass = 1; pass <= 600; pass++) {
  bar.setWidth(10 + (pass % 50));
  root.calculateLayout(undefined, undefined);
  if ([1, 10, 100, 600].includes(pass))
    console.log(`pass ${pass}`.padEnd(9), grown());
}

Output:

pass 0    (none)
pass 1    #1=28.81 #2=28.81 #3=28.81 #4=28.81 #5=28.81 #6=28.81 #7=28.81 #8=28.81 #9=28.81 #10=28.81 #11=28.81 #12=28.81 #13=28.81 #14=28.81 #15=28.81 #16=28.81 #17=28.81 #19=28.81 #20=28.81 #21=28.81 #22=28.81 #23=28.81 #24=28.81 #25=28.81 #26=28.81 #27=28.81 #28=28.81 #29=28.81 #30=28.81
pass 10   #1=28.82 #2=28.83 #3=28.85 #4=28.90 #5=28.90 #6=28.82 #7=28.83 #8=28.90 #9=28.90 #10=28.90 #11=28.90 #12=28.82 #13=28.81 #14=28.90 #15=28.86 #16=28.86 #17=28.82 #19=28.81 #20=28.82 #21=28.86 #22=28.86 #23=28.81 #24=28.86 #25=28.90 #26=28.90 #27=28.90 #28=28.81 #29=28.90 #30=28.92
pass 100  #1=28.82 #2=28.83 #3=28.85 #4=29.00 #5=29.00 #6=28.82 #7=28.83 #8=29.00 #9=29.00 #10=29.00 #11=29.00 #12=28.82 #13=28.81 #14=29.80 #15=28.86 #16=28.86 #17=28.82 #19=28.81 #20=28.82 #21=28.86 #22=28.86 #23=28.81 #24=28.86 #25=29.00 #26=29.00 #27=29.00 #28=28.81 #29=29.00 #30=29.99
pass 600  #1=28.82 #2=28.83 #3=28.85 #4=29.00 #5=29.00 #6=28.82 #7=28.83 #8=29.00 #9=29.00 #10=29.00 #11=29.00 #12=28.82 #13=28.81 #14=34.80 #15=28.86 #16=28.86 #17=28.82 #19=28.81 #20=28.82 #21=28.86 #22=28.86 #23=28.81 #24=28.86 #25=29.00 #26=29.00 #27=29.00 #28=28.81 #29=29.00 #30=35.95

Every label measures 28.8 tall and nothing in the list changes between passes. With setPointScaleFactor(0) all heights stay at 28.8.

My guess is that the pixel-grid rounding runs again over the cached subtree, which still holds the previous pass's rounded values. For measured nodes the top edge is floored and the bottom edge ceiled, so where float32 storage leaves a small residue in the absolute position, the height goes up one more step each time. Nodes without a measure function keep their size.

Found through @pmndrs/uikit, which sets a point scale factor of 100 (layout rounded to 0.01 units).

主要言語
C++
スター
18.9k
フォーク
1.6k
平均マージ
1日 31分
マージ済み PR(30日)
14

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

react/yoga のほかの issue

react/yoga の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。