Skip to content

React Portal children gets overriden in Fabric #36273

@intergalacticspacehighway

Description

Description

Portals are not officially documented in RN. But I think it can be a very useful feature and it almost works!

Why do we need Portals?

Modal component cannot be used as a general-purpose overlay solution as multiple modals on iOS are tricky and Modal also prevents behind view touches. Userland solution loses React context when children are mounted.

Issue

I got createPortal working on Paper architecture by removing this assertion. However I ran into an issue on Fabric. After some digging, I found that the issue is in the React Fabric JS renderer, not native side. The Portal gets mounted momentarily but gets overridden by the HostRoot children.

Here is the repro. In the repro, two calls are made to updateHostContainer. 1 and 2. The second call from HostRoot overrides the children mounted by Portal. These findings are with some console.logs, I have no clue how it works. I'll try to dig more and update. I think @rickhanlonii can help 🙏

React Native Version

0.71.3

Output of npx react-native info

System:
    OS: macOS 13.2.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 417.80 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.22.15 - ~/.nvm/versions/node/v16.13.1/bin/yarn
    npm: 8.12.1 - ~/.nvm/versions/node/v16.13.1/bin/npm
    Watchman: 2022.03.14.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
    Android SDK: Not Found
  IDEs:
    Android Studio: 2022.1 AI-221.6008.13.2211.9514443
    Xcode: 14.2/14C18 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.13 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: 10.0.0 => 10.0.0 
    react: 18.2.0 => 18.2.0 
    react-native: Not Found
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  • Run the RN Tester Repro, portal gets mounted and unmounted (not visible, it happens fast). It only stays mounted if you comment this line
  • Make sure you're on Fabric
  • If you change arch to Paper, it'll work as expected.

Snack, code example, screenshot, or link to a repository

RNTester Repro

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions