-
-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(bridge-plugin): support disable default alias setting in bridge #3130
Conversation
🦋 Changeset detectedLatest commit: 76427c2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 25 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 |
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary
The pull request introduces a new feature that allows users to disable the default alias setting in the bridge for the ModuleFederationPlugin. This is achieved by adding a new option disableAlias
to the bridge configuration.
When disableAlias
is set, the ReactBridgePlugin will not be applied, allowing users to obtain the basename
through the root component props and manually set the router's basename
. This can be helpful in complex scenarios where the default alias might cause problems.
The changes are made across three files:
packages/enhanced/src/wrapper/ModuleFederationPlugin.ts
: The code changes introduce thedisableAlias
option and use it to conditionally apply the ReactBridgePlugin.packages/rspack/src/ModuleFederationPlugin.ts
: Similar to the changes in the enhanced package, the code changes introduce thedisableAlias
option and use it to conditionally apply the ReactBridgePlugin.packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
: The code changes introduce thedisableAlias
option in theModuleFederationPluginOptions
type definition.
These changes provide users with more flexibility in configuring the ModuleFederationPlugin, allowing them to disable the default alias setting in the bridge when necessary.
File Summaries
File | Summary |
---|---|
packages/enhanced/src/wrapper/ModuleFederationPlugin.ts | The code changes introduce a new feature to the ModuleFederationPlugin that allows users to disable the default alias setting in the bridge. This is done by adding a new option disableAlias to the bridge configuration, which, when set, will prevent the ReactBridgePlugin from being applied, allowing users to obtain the basename through the root component props and set the router's basename themselves. |
packages/rspack/src/ModuleFederationPlugin.ts | The code changes introduce a new feature to the ModuleFederationPlugin that allows users to disable the default alias setting in the bridge. This is done by adding a new option disableAlias to the bridge configuration, which is then used to conditionally apply the ReactBridgePlugin. |
packages/sdk/src/types/plugins/ModuleFederationPlugin.ts | The code changes introduce a new option disableAlias in the bridge configuration of the ModuleFederationPluginOptions . This feature allows users to disable the default alias setting in the bridge, which can be helpful in complex scenarios where the default alias might cause problems. After disabling the alias, users can obtain the basename through the root component props and manually set the router's basename . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incremental Review
Comments posted: 7
Configuration
Squadron Mode: essential
Commits Reviewed
ad605d2c9c1ebd0626ac62af2428485e67779a21...a6859988f0ae2f76502bff04d3471680f439f71d
Files Reviewed
- packages/enhanced/src/wrapper/ModuleFederationPlugin.ts
- packages/rspack/src/ModuleFederationPlugin.ts
- packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
Files Ignored
These files were ignored due to the filter in the squadron.yaml file.
- apps/router-demo/router-host-2000/rsbuild.config.ts
'@module-federation/bridge-react', | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a comment explaining what the '@module-federation/bridge-react' path represents and why it's being checked. This would improve code maintainability and make the purpose clearer:
'@module-federation/bridge-react', | |
); | |
'@module-federation/bridge-react', // Path to React bridge package for module federation |
@@ -127,7 +127,10 @@ | |||
); | |||
|
|||
// Check whether react exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment "Check whether react exists" is not fully accurate as it's checking for both React existence and bridge configuration. A more descriptive comment would be:
// Check whether react exists | |
// Check for React bridge availability and alias configuration |
Co-authored-by: squadronai[bot] <170149692+squadronai[bot]@users.noreply.github.com>
Co-authored-by: squadronai[bot] <170149692+squadronai[bot]@users.noreply.github.com>
Co-authored-by: squadronai[bot] <170149692+squadronai[bot]@users.noreply.github.com>
Co-authored-by: squadronai[bot] <170149692+squadronai[bot]@users.noreply.github.com>
Co-authored-by: squadronai[bot] <170149692+squadronai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incremental Review
Comments posted: 2
Configuration
Squadron Mode: essential
Commits Reviewed
f7791881772a7e7dfd21508a13fcb9190e21b6c3...03968535b3c0a29004954207adc1d9829a958f7a
Files Reviewed
- packages/enhanced/src/wrapper/ModuleFederationPlugin.ts
- packages/rspack/src/ModuleFederationPlugin.ts
- packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
Files Ignored
These files were ignored due to the filter in the squadron.yaml file.
- .changeset/mean-squids-repair.md
- apps/router-demo/router-host-2000/rsbuild.config.ts
new ReactBridgePlugin({ | ||
moduleFederationOptions: this._options, | ||
}).apply(compiler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ReactBridgePlugin configuration is hardcoded without any validation of the moduleFederationOptions. Consider validating the options before passing them to ensure they meet the expected format:
new ReactBridgePlugin({ | |
moduleFederationOptions: this._options, | |
}).apply(compiler); | |
const bridgeConfig = { | |
moduleFederationOptions: this._options, | |
}; | |
if (!bridgeConfig.moduleFederationOptions) { | |
throw new Error('ModuleFederationOptions are required for ReactBridgePlugin'); | |
} | |
new ReactBridgePlugin(bridgeConfig).apply(compiler); |
This adds a basic validation layer to prevent potential runtime issues from invalid configurations.
new ReactBridgePlugin({ | ||
moduleFederationOptions: this._options, | ||
}).apply(compiler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ReactBridgePlugin instantiation is done directly without storing the instance. For better plugin lifecycle management and potential cleanup, consider storing the plugin instance:
new ReactBridgePlugin({ | |
moduleFederationOptions: this._options, | |
}).apply(compiler); | |
const bridgePlugin = new ReactBridgePlugin({ | |
moduleFederationOptions: this._options, | |
}); | |
bridgePlugin.apply(compiler); |
This approach provides better control over the plugin instance and makes it easier to manage its lifecycle if needed in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incremental Review
Comments posted: 2
Configuration
Squadron Mode: essential
Commits Reviewed
03968535b3c0a29004954207adc1d9829a958f7a...918c636e0837ba5236d4ba5ad275b11bae3daccf
Files Reviewed
- packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
Files Ignored
These files were ignored due to the filter in the squadron.yaml file.
- .changeset/mean-squids-repair.md
- apps/router-demo/router-host-2000/rsbuild.config.ts
* Disables the default alias setting in the bridge. | ||
* When true, users must manually handle basename through root component props. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSDoc comment is incomplete and cut off mid-sentence. Complete the documentation to properly explain the functionality:
* Disables the default alias setting in the bridge. | |
* When true, users must manually handle basename through root component props. | |
* Disables the default alias setting in the bridge. | |
* When true, users must manually handle basename through root component props. | |
* @default false | |
*/ |
experiments?: { | ||
federationRuntime?: false | 'hoisted'; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The experiments.federationRuntime
property would benefit from JSDoc documentation explaining its purpose and valid values:
experiments?: { | |
federationRuntime?: false | 'hoisted'; | |
}; | |
/** | |
* Configuration for experimental features | |
*/ | |
experiments?: { | |
/** | |
* Controls the federation runtime mode | |
* @default undefined | |
*/ | |
federationRuntime?: false | 'hoisted'; | |
}; |
Description
feat(bridge-plugin): support disable default alias setting in bridge with
disableAlias
.In order to avoid problems caused by default alias in some complex scenarios, we support users to disable default alias setting in bridge. After this setting, users can obtain the
basename
through root component props and display it in the project to set the router'sbasename
.if you any router issues which is caused by the default alias behavior, try to set
disableAlias
to not allow the default alias, just config like this:Related Issue
Types of changes
Checklist