react / react/yoga

Incorrect cached child size is used because YGNodeCanUseCachedMeasurement() does not respect min/max dimensions

Open
#1,003 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Algorithm
Dominant language
C++
Stars
18.9k
Forks
1.6k
Avg merge
1m
Merged PRs (30d)
1

Description

Report

Issues and Steps to Reproduce

See the attached example.

Child node has height = 10, minHeight = 40%, maxHeight = 60%.

When parent is measured against height = NaN, child height is computed to be 10, which is correct.

But then parent is laid out against height = 30.
Now child height should be max(40% * 30, min(10, 60% * 30)) = max(12, min(10, 18)) = 12.
But YGNodeCanUseCachedMeasurement() returns true and cached height of 10 is used instead.

Expected Behavior

In all the cases, final layout should have child height of 12.

Actual Behavior

In some of the scenarios incorrect cached height is used.

Link to Code

https://pastebin.com/x5e6ZL2b

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting YGNodeCanUseCachedMeasurement() and the attached example at the pastebin link. Reproduce the case where the parent is first measured with an unspecified height and then laid out at height 30. Done means the final child height is 12 and incorrect cached measurements are no longer used in the affected scenarios.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.