Skip to content

Fix cpp-lib example: dedupe react-native-windows in Metro config - #1291

Open
anuagragith wants to merge 1 commit into
mainfrom
user/anuagra/fix-cpp-lib-metro-dedupe
Open

Fix cpp-lib example: dedupe react-native-windows in Metro config#1291
anuagragith wants to merge 1 commit into
mainfrom
user/anuagra/fix-cpp-lib-metro-dedupe

Conversation

@anuagragith

@anuagragith anuagragith commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Problem

The NativeModuleSample/cpp-lib example renders a blank screen at runtime. The
red box (with JS debugging / dev bundle) reveals:

Render Error: View config getter callback for component CircleMask must be a
function (received undefined).

This matches open issue microsoft/react-native-windows#15519 and reproduces on both 0.84 and 0.85.

Root cause

The example's metro.config.js loads two copies of react-native-windows — one
from the library root's node_modules and one from example/node_modules. Each copy
has its own ReactNativeViewConfigRegistry. codegenNativeComponent('CircleMask')
registers the view config into one instance, while the renderer looks it up in the
other → undefined → React throws → the whole tree unmounts (blank window).

The existing dedupe logic was a no-op because it:

  1. Used the deprecated blacklistRE key (Metro 0.84 / RN 0.85 uses blockList).
  2. Built patterns with Windows backslashes, which never match Metro's
    forward-slash-normalized module paths.

Fix

  • Rename blacklistREblockList and normalize path separators so the root
    node_modules duplicate of react-native-windows is actually blocked.
  • Add a resolveRequest hook redirecting react-native (and deep imports) to
    react-native-windows on the windows platform, ensuring a single renderer /
    view-config registry instance.

Verification

  • Dev bundle now contains a single ReactNativeViewConfigRegistry
    (bundle size 10.1 MB → 5.09 MB).
  • The example renders fully: all TurboModule outputs, both buttons, and the
    CircleMask native component (teal circle).

After fix - cpp-lib example rendering (CircleMask native component visible)
cpp-lib-pr-final

Microsoft Reviewers: Open in CodeFlow

The NativeModuleSample/cpp-lib example rendered a blank screen because
its Metro config loaded two copies of react-native-windows (one from the
library root's node_modules and one from example/node_modules). Each copy
had its own ReactNativeViewConfigRegistry, so the CircleMask view config
registered by codegenNativeComponent('CircleMask') in one instance was
looked up from the other, returning undefined and throwing:

  View config getter callback for component 'CircleMask' must be a
  function (received 'undefined').

which unmounted the whole tree (blank window; matches issue #15519).

The existing dedupe used the deprecated 'blacklistRE' key (Metro 0.84
uses 'blockList') and built patterns with Windows backslashes that never
matched Metro's forward-slash-normalized module paths, so it was a no-op.

Fix:
- Rename blacklistRE -> blockList and normalize path separators so the
  root node_modules duplicate of react-native-windows is actually blocked.
- Add a resolveRequest hook that redirects react-native (and deep imports)
  to react-native-windows on the windows platform, ensuring a single
  renderer / view-config registry instance.

Verified: dev bundle now contains a single ReactNativeViewConfigRegistry
(bundle size 10.1 MB -> 5.09 MB) and the example renders fully, including
the CircleMask native component.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@anuagragith
anuagragith requested a review from a team as a code owner July 28, 2026 21:17
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