Skip to content

Add YogaLayoutableShadowNode::enableBaseline() - #60571

Open
YevheniiKotyrlo wants to merge 1 commit into
react:mainfrom
YevheniiKotyrlo:feature/enable-baseline-after-construction
Open

YevheniiKotyrlo wants to merge 1 commit into
react:mainfrom
YevheniiKotyrlo:feature/enable-baseline-after-construction

Conversation

@YevheniiKotyrlo

@YevheniiKotyrlo YevheniiKotyrlo commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

YogaLayoutableShadowNode connects Yoga's baseline function only in the constructor that builds a node from its first props, when BaselineYogaNode is among the traits it is given (YogaLayoutableShadowNode.cpp#L82-L86). A clone takes its source's traits and a copy of its source's Yoga node, and the function that calls baseline(), yogaNodeBaselineCallbackConnector, is private, and no header declares the layout context it passes (YogaLayoutableShadowNode.cpp#L1011-L1012). So no member connects that function after construction, and without a function of its own, Yoga aligns a leaf whose new props ask it to answer baseline() at its bottom edge in a row with alignItems: 'baseline' (#60560).

Setting BaselineYogaNode in the component's BaseTraits() instead connects the function on every node of the component, and Yoga asks a node with a baseline function for its baseline before it looks at its children (Baseline.cpp#L18-L33), so the component's nodes that lay out children would answer the component's own baseline() in place of the baseline Yoga takes from their children (Baseline.cpp#L35-L62).

This adds enableBaseline() beside enableMeasurement(). A clone of a laid-out node copies its source's clean Yoga node, so enableBaseline() dirties the node when it connects the function; on a node already connected it changes nothing.

Related: #60572 adds getLayoutMargins(), and both add their tests at the end of ViewTest.cpp, so the second to merge keeps both; #60578 corrects enableMeasurement()'s comment; #60581 passes the source revision to shouldNewRevisionDirtyMeasurement() in completeClone(); #60583 dirties a node connected by enableMeasurement() when its props or the font scale change. #60578, #60581 and #60583 merge with this without conflict. #59048 and #59139 add tests to ViewTest.cpp too, apart from this one's.

Changelog:

[GENERAL] [ADDED] - Add YogaLayoutableShadowNode::enableBaseline() to connect a shadow node's baseline function after construction, such as on a clone whose new props ask for a baseline

Test Plan:

Added ViewTest.enableBaselineAlignsACloneOnItsBaseline: a measured leaf, 10x40 with a baseline of 10, whose clone constructor calls enableBaseline() and whose new revisions keep their measurement, beside a 10x20 box in a row aligned on baselines. Laid out first, the box sits at y 20 and the leaf at y 0; cloned with new props and laid out again, the box sits at y 0 and the leaf at y 10; cloned once more, the tree needs no layout. The test fails without the setDirty(true) and without the connection, where the first clone keeps the first layout, and without the early return, where the second clone lays the tree out again:

[…]
2/2 Test #833: react/renderer/components/view/tests/ViewTest.enableBaselineAlignsACloneOnItsBaseline ...***Failed    0.01 sec
50% tests passed, 1 tests failed out of 2
[…]

In reactnativecommunity/react-native-android:latest:

  • CC=clang-18 CXX=clang++-18 ./gradlew :private:react-native-fantom:testReactCommon, as test_react_common_cxx runs it: 100% tests passed, 0 tests failed out of 1655
  • yarn format-cpp, then git diff --exit-code -- . ':(exclude)packages/react-native/package.json' ':(exclude)yarn.lock', as Format checks its formatters' patch: leaves the tree unchanged
  • yarn cxx-api-validate with Doxygen 1.16.1, the step of Validate C++ API Snapshots: All snapshot validations passed

Not run here: the Android, iOS and Fantom builds.

@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 4, 2026
The baseline function is connected only by the constructor, when the
`BaselineYogaNode` trait is among the traits it is given, and a clone
takes its source's Yoga node. No member connects the function that
calls `baseline()` with the layout context, which is private, after
construction, so without a function of its own, Yoga aligns a leaf
whose new props ask it to answer its own baseline at its bottom edge.

`enableBaseline()` connects `yogaNodeBaselineCallbackConnector`, as
`enableMeasurement()` connects the measure function, and dirties the
node when the function was not connected yet, since a clone of a
laid-out node copies its source's clean Yoga node.

Signed-off-by: YevheniiKotyrlo <44449990+YevheniiKotyrlo@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant