react / react/yoga

Unexpected zero width for 100% width node

Open
#1,827 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Here the 50% width node has zero width - I would expect it here to be 50% width of its parent node so 250 / 2 . Perhaps this is something I don't understand about containing blocks, is this a bug or my misunderstanding?
Note if root node has default auto width/height, the 50% node is always the full width of the parent (regardless of the %age value); Only when root node has default alignItems:'stretch' does it show at expected 50%

<Layout config={{useWebDefaults: false}}>
  <Node style={{width:350, height:150, alignItems:'center'}}>
    <Node style={{padding: 10,width:'auto'}}>
      <Node style={{width: 250, height: 60}} />
      <Node style={{width: "50%", height:30 }}/>
    </Node>
  </Node>
</Layout>

result:

Image

https://www.yogalayout.dev/playground?code=DwGQhgng9grgLgAgMZQHYDMCWBzAvAb3xgGcBTAdVICMARU9MGAGzmIC4EGmyBfHgPgBQCBMAByUACakExOBCakC+AO6ZJcABZsAzAFYADABoEm0jk1w2ARkMmwTHKgCScUgFt2AciSlUbgCcvPiEREXEpGTkFJUIABzBJSUxUbA5rYzUNbS9GOChggWEw8IlpWXlFZSytDgAmO1NzbEsOADYDPgQAelCS0TKoytjVdVqEACJDAFIJkzMLKx0DBD5e4vDuwb7gLcihXfBoeCEgA

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 with the linked Yoga playground reproduction and compare the 50% child inside the auto-width parent against the case where the root uses the default alignItems:'stretch'. Trace how percentage width is resolved when the containing parent has auto width, and consider the issue done when the reproduction gives the child the expected 50% width without changing the documented containing-block behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.