UI Text nodes behave weirdly when they have children
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version
0.15.1
## \[Optional\] Relevant system information
`SystemInfo { os: "Windows 10 Pro", kernel: "19045", cpu: "AMD Ryzen 7 5800X 8-Core Processor", core_count: "4", memory: "15.9 GiB" }`
`cargo 1.86.0-nightly (0e3d73849 2025-02-01)`
## What you did
Create what's essentially an HBox node and add two Text nodes as children to it. Everything is fine, both nodes are visible and have their position calculated correctly.
```rs
fn spawn_text_input_child(parent: &mut ChildBuilder, name: &'static str, text: &str) {
parent
.spawn((Name::new(name), Text::new(text)));
// .with_child((
// Name::new("cursor"),
// Node {
// min_height: Val::Px(20.0),
// min_width: Val::Px(1.0),
// ..default()
// },
// BackgroundColor(bevy::color::Color::Srgba(WHITE)),
// ));
}
```

Now add a child `Node::default()` to each of Text node. Both Text nodes suddenly disappear and their ComputedNode components have `.size == Vec2::ZERO`.
```rs
fn spawn_text_input_child(parent: &mut ChildBuilder, name: &'static str, text: &str) {
parent
.spawn((Name::new(name), Text::new(text)))
.with_child((
Name::new("cursor"),
Node {
// min_height: Val::Px(20.0),
// min_width: Val::Px(1.0),
..default()
},
// BackgroundColor(bevy::color::Color::Srgba(WHITE)),
));
}
```

Now add a BackgroundColor component to these newly-added default nodes and give them some size so that they're visible. Text nodes are now visible again alongside their children, but are heavily distorted and squeezed into one space.
```rs
fn spawn_text_input_child(parent: &mut ChildBuilder, name: &'static str, text: &str) {
parent
.spawn((Name::new(name), Text::new(text)))
.with_child((
Name::new("cursor"),
Node {
min_height: Val::Px(20.0),
min_width: Val::Px(1.0),
..default()
},
BackgroundColor(bevy::color::Color::Srgba(WHITE)),
));
}
```

## What went wrong
I expected children of Text nodes to simply be drawn over them. Instead, even simply adding an empty Node to a Text caused it to completely break apart
## Additional information
Other information that can be used to further reproduce or isolate the problem.
This commonly includes:
- screenshots: provided above
- logs: irrelevant
- theories about what might be going wrong: none
- workarounds that you used: couldn't find any
- links to related bugs, PRs or discussions: couldn't find anything similar
MRP: [zerosizebug.zip](https://github.com/user-attachments/files/18948828/zerosizebug.zip) (ignore the name, i've encountered this bug while trying to pinpoint another one)
Contributor guide
Research direction
Start by reproducing the behavior from the provided zerosizebug.zip MRP, comparing a Text node with and without a child Node. Trace the UI layout and text sizing path involved in child sizing. Done means Text nodes retain their expected nonzero size and layout while their children are present, including the demonstrated cursor case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- frontend, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100