Skip to content

fix(macos): show React menu on right-click of Fabric root views#2757

Draft
Saadnajmi wants to merge 1 commit intomicrosoft:trunkfrom
Saadnajmi:fix/macos-dev-menu-new-arch
Draft

fix(macos): show React menu on right-click of Fabric root views#2757
Saadnajmi wants to merge 1 commit intomicrosoft:trunkfrom
Saadnajmi:fix/macos-dev-menu-new-arch

Conversation

@Saadnajmi
Copy link
Copy Markdown
Collaborator

@Saadnajmi Saadnajmi commented Apr 28, 2026

Summary

On the new architecture, right-clicking inside the React content of the macOS test app shows nothing. On the old architecture, RCTRootView.menuForEvent: returns the dev menu, but the Fabric root view (RCTSurfaceHostingProxyRootView) does not override menuForEvent:, so the menu never appears.

This adds a small HostingViewController that overrides mouseDown / rightMouseDown to pop up the React menu, and:

  • Uses it as the wrapper view controller in AppDelegate.present() (multi-app mode, after a component is presented).
  • Ungates the existing handlers on ViewController so they also fire in ENABLE_SINGLE_APP_MODE, where the storyboard-instantiated ViewController is in the responder chain above the React root view.

The popUpReactMenu helper is moved out of the #if !ENABLE_SINGLE_APP_MODE guard so it is available in single-app mode too.

Relationship to microsoft/rnx-kit#4114

This is the self-contained workaround of a pair. The underlying root cause — that consumers of host.viewWithModuleName: bypass RCTRootViewFactory and so the upstream devMenu wiring on RCTSurfaceHostingView (react-native-macos 0.81+) never runs — is fixed properly in microsoft/rnx-kit#4114. That PR makes @rnx-kit/react-native-host set devMenu on 0.81+ and installs a fallback gesture recognizer on older versions, so the upstream React Native dev menu (Reload, Open Debugger, …) shows on secondary-click without the test app needing to do anything.

The two PRs differ in what menu they show:

Once microsoft/rnx-kit#4114 lands, is published, and the test app bumps @rnx-kit/react-native-host, this workaround can be removed in favor of the upstream behavior — or kept if we prefer the test app's richer React menu over the bare RN dev menu. They will conflict if both are active, since the rnx-kit gesture recognizer fires before the responder chain reaches HostingViewController, so this should be removed at the same commit that picks up the new rnx-kit version.

Test plan

  • Right-click the React content on macOS, new architecture, single-app mode → React menu pops up.
  • Right-click the React content on macOS, new architecture, multi-app mode (after a component is presented) → React menu pops up.
  • Empty initial state in multi-app mode still shows the React menu on click as before.
  • Old architecture continues to work unchanged.

🤖 Generated with Claude Code

The Fabric root view (`RCTSurfaceHostingProxyRootView`) does not override
`menuForEvent:` like the old-architecture `RCTRootView` does, so secondary
clicks on the React content do nothing on the new architecture. Add a
`HostingViewController` whose `rightMouseDown` shows the React menu, and
use it for the React content view in multi-app mode. Also ungate the
existing `ViewController` handlers so single-app mode picks them up via
the responder chain.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant