Fix cpp-lib example: dedupe react-native-windows in Metro config - #1291
Open
anuagragith wants to merge 1 commit into
Open
Fix cpp-lib example: dedupe react-native-windows in Metro config#1291anuagragith wants to merge 1 commit into
anuagragith wants to merge 1 commit into
Conversation
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>
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.
Problem
The
NativeModuleSample/cpp-libexample renders a blank screen at runtime. Thered box (with JS debugging / dev bundle) reveals:
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.jsloads two copies ofreact-native-windows— onefrom the library root's
node_modulesand one fromexample/node_modules. Each copyhas 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:
blacklistREkey (Metro 0.84 / RN 0.85 usesblockList).forward-slash-normalized module paths.
Fix
blacklistRE→blockListand normalize path separators so the rootnode_modulesduplicate ofreact-native-windowsis actually blocked.resolveRequesthook redirectingreact-native(and deep imports) toreact-native-windowson thewindowsplatform, ensuring a single renderer /view-config registry instance.
Verification
ReactNativeViewConfigRegistry(bundle size 10.1 MB → 5.09 MB).
CircleMasknative component (teal circle).After fix - cpp-lib example rendering (CircleMask native component visible)

Microsoft Reviewers: Open in CodeFlow