Skip to content

Mount child visuals above a View's background visual - #16652

Open
Collin Schneide (FaithfulAudio) wants to merge 2 commits into
microsoft:mainfrom
FacilitronWorks:fix/mount-children-above-background-visual
Open

Collin Schneide (FaithfulAudio) wants to merge 2 commits into
microsoft:mainfrom
FacilitronWorks:fix/mount-children-above-background-visual

Conversation

@FaithfulAudio

@FaithfulAudio Collin Schneide (FaithfulAudio) commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Why

A View's backgroundColor is painted by m_backgroundVisual, a separate SpriteVisual inserted at index 0 of Visual() (see the visual-tree comment at the top of CompositionViewComponentView.cpp). ViewComponentView::MountChildComponentView offsets the child's visual index past the border and outline visuals (indexOffsetForBorder) but not past the background visual. Every other insertion into Visual() already counts it: the outline primitive, m_childrenContainer and borderInsertAtIndex().

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 (onLayout sizes were right), and giving the container a border made everything appear, because borders route children into m_childrenContainer.

No existing issue that I could find.

What

  • When children mount directly into Visual() (not m_childrenContainer, and not a builder-provided VisualToMountChildrenInto target), add the background visual to the child visual offset.
  • Keep that offset separate from index. index is also used as a child index by the m_hasNonVisualChildren walk (m_children.GetAt(i) for i <= index). Before, it received the border-adjusted value there, which could over-count or read past the end of m_children.

Screenshots

None attached.

Testing

  • Checked in an app whose screen container has a backgroundColor and 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 of main at aedf6c5, plus an RN 0.88.1 alignment.
    • Before: only the container's background was visible.
    • After: the screens render fully.
  • Minimal repro of the same mechanism, without any navigation library: a <View style={{backgroundColor: 'grey', flex: 1}}> that renders {show && <View style={{backgroundColor: 'red', width: 100, height: 100}} />}, with show set to true in an effect after the first mount.
    • Without the fix, the red box should be hidden under the grey background.
    • With it, the box should be visible.
  • Unmount is unchanged. Children are removed by identity, so mount and unmount stay symmetric.

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

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>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 12:32
@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vmoroz

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines:
Successfully started running 1 pipeline(s).

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants