fix: read react-native shared config from array form of shared - #1454
Open
giaBaoJS wants to merge 1 commit into
Open
fix: read react-native shared config from array form of shared#1454giaBaoJS wants to merge 1 commit into
giaBaoJS wants to merge 1 commit into
Conversation
ModuleFederationPlugin adds `react-native/` and `@react-native/` deep imports and copies `eager`, `import` and `version` from the user's `react-native` shared config. When `shared` is given as an array, findSharedDependency returned the array item itself, which is an object keyed by the dependency name, so reading `.eager` / `.import` / `.requiredVersion` off it always yielded undefined and the deep imports silently fell back to `eager: true` with no `import: false`. The object form of `shared` returns the config itself and behaves correctly. Applies to both ModuleFederationPluginV1 and ModuleFederationPluginV2.
🦋 Changeset detectedLatest commit: 2faf061 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@giaBaoJS is attempting to deploy a commit to the Callstack Team on Vercel. A member of the Team first needs to authorize it. |
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.
Summary
ModuleFederationPluginaddsreact-native/and@react-native/tosharedso deep imports resolve through the shared scope, and it copieseager,import(andversionin V1) from the user'sreact-nativeentry. That copy only works whensharedis an object. With the array form, the deep imports always end up aseager: trueand withoutimport: false.Reproduction
Config handed to the underlying
ModuleFederationPlugin:The equivalent object form is handled correctly, which is the sibling path that shows the intended behaviour:
For a remote container this means the React Native deep imports get eagerly bundled into the container instead of being consumed from the host, which is the opposite of what
eager: false, import: falseasks for.Root cause
In the array branch,
findSharedDependencyreturned the array item, which is an object keyed by the dependency name ({ 'react-native': {...} }), rather than the config stored under that key. Reading.eager/.import/.requiredVersionoff the wrapper therefore always producedundefined, andsharedDependencyConfigfell back to its defaults. The object branch on the next line returns the config itself, so it never had the problem.What the tests assert
Four new cases, mirroring the existing object-form tests, two per plugin:
shared: [{ react: ... }, { 'react-native': { eager: false, ... } }]producesreact-native/and@react-native/witheager: false(and, for V1,requiredVersion: '0.76.0'rather than'*').shared: [{ 'react-native': { import: false } }]produces both deep imports withimport: false.Without the source change all four fail on the value itself (
eageristrueinstead offalse,importisundefinedinstead offalse).packages/repackjest suite: 312 passing before, 316 after, plustsc --noEmitandbiome checkclean.