Repository navigation
Mount child visuals above a View's background visual - #16652
Open
Collin Schneide (FaithfulAudio) wants to merge 2 commits into
Open
Collin Schneide (FaithfulAudio) wants to merge 2 commits into
Collin Schneide (FaithfulAudio) wants to merge 2 commits into
Conversation
A View's backgroundColor is painted by m_backgroundVisual, a separate SpriteVisual at index 0 of Visual(). ViewComponentView::MountChildComponentView offset a child's visual index past the border and outline visuals (indexOffsetForBorder) but not past the background visual, unlike every other insertion into Visual(): the outline primitive, m_childrenContainer and borderInsertAtIndex() all count it. So a child mounted at index 0 after its parent's background visual exists was inserted underneath the background and never painted. Initial mounts usually avoid it because children go in before the background is created, but content mounted into an already-coloured container in a later commit is hidden completely (layout is correct; nothing paints). Giving the container a border hides the bug, because borders route children into m_childrenContainer. - Add the background visual to the child visual offset when children mount directly into Visual() (not m_childrenContainer, not a builder-provided mount target). - Keep that offset separate from `index`, which is also used as a child index by the m_hasNonVisualChildren walk (m_children.GetAt(i) for i <= index). It used to receive the border-adjusted value there, which could over-count or read past the end of m_children. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collin Schneide (FaithfulAudio)
requested a review
from a team
as a code owner
November 23, 2026 12:32
Contributor
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the Fabric child-stacking fix.
No open issues 🎉
What changed in this PR
This PR fixes Fabric visual stacking so children mounted after a parent’s background is created appear above it rather than being hidden.
Changes:
- Include the background visual in the insertion offset when mounting children directly into the parent visual.
- Keep visual offsets separate from logical child indices used to count non-visual children.
- Add a prerelease changelog entry for the fix.
| File | Description |
|---|---|
vnext/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp |
Corrects child visual insertion offsets while preserving logical child indices. |
change/react-native-windows-fix-mount-children-above-background-visual.json |
Records the Fabric rendering fix for release notes. |
Review effort: Balanced
|
|
||
| // When children are in Visual() directly, offset past border visuals. | ||
| // When children are in m_childrenContainer, no offset needed. | ||
| // When children are in Visual() directly, offset past the background visual and the |
There was a problem hiding this comment.
Could you instruct AI to comment code so that it does not describe a bug that it just fixed, but rather what the code does, and only when it is really needed. The comment must not duplicate the code itself. The bug description and the fix should go to the PR description. We do not want to get in a situation when the code is overwhelmed by comments like this.
Member
|
/azp run |
Contributor
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Type of Change
Why
A View's
backgroundColoris painted bym_backgroundVisual, a separate SpriteVisual inserted at index 0 ofVisual()(see the visual-tree comment at the top ofCompositionViewComponentView.cpp).ViewComponentView::MountChildComponentViewoffsets the child's visual index past the border and outline visuals (indexOffsetForBorder) but not past the background visual. Every other insertion intoVisual()already counts it: the outline primitive,m_childrenContainerandborderInsertAtIndex().As a result, a child mounted at index 0 after its parent's background visual exists is inserted underneath the background and never paints. Initial mounts usually avoid it, because children are inserted before the background visual is created. But content mounted into an already-coloured container in a later commit is hidden completely. We hit this with Expo Router 58, which mounts screen content into the coloured screen container one commit later: the whole app rendered as a flat background colour. Layout was correct (
onLayoutsizes were right), and giving the container a border made everything appear, because borders route children intom_childrenContainer.No existing issue that I could find.
What
Visual()(notm_childrenContainer, and not a builder-providedVisualToMountChildrenIntotarget), add the background visual to the child visual offset.index.indexis also used as a child index by them_hasNonVisualChildrenwalk (m_children.GetAt(i)fori <= index). Before, it received the border-adjusted value there, which could over-count or read past the end ofm_children.Screenshots
None attached.
Testing
backgroundColorand whose content mounts in a later commit (Expo Router 58 native stack), on a Surface Pro (x64 Release, 200% scale). That build had this change on top ofmainat aedf6c5, plus an RN 0.88.1 alignment.<View style={{backgroundColor: 'grey', flex: 1}}>that renders{show && <View style={{backgroundColor: 'red', width: 100, height: 100}} />}, withshowset totruein an effect after the first mount.Changelog
Should this change be included in the release notes: yes
Fixed child views that mount after their parent's background color is set being drawn underneath the background.
🤖 Generated with Claude Code
Microsoft Reviewers: Open in CodeFlow