-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
docs: enhance dynamic-remotes example documentation and modernization guide #4360
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
Merged
ScriptedAlchemy
merged 15 commits into
master
from
review-dynamic-remotes-best-practices
Aug 3, 2025
Merged
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9563613
docs: enhance dynamic-remotes example documentation
ScriptedAlchemy 1cb6629
Merge branch 'master' into review-dynamic-remotes-best-practices
ScriptedAlchemy 839f7a5
fix: modernize dynamic-remotes example implementation
ScriptedAlchemy 4d79e8e
docs: add runtime plugin recommendations to dynamic-remotes README
ScriptedAlchemy 02147ac
feat: replace Cypress with Playwright for E2E testing
ScriptedAlchemy 64bdb58
fix: resolve all Playwright test issues - 100% test success
ScriptedAlchemy ef76b5c
fix: restore Cypress test compatibility for CI while maintaining Play…
ScriptedAlchemy 813592f
feat: replace Cypress with Playwright-only E2E testing
ScriptedAlchemy 0d35c77
feat: update CI to install Playwright for all projects and add root d…
ScriptedAlchemy 6edea24
fix: install Playwright globally in CI without changing lockfile
ScriptedAlchemy 431d2ac
fix: use pnpm filter commands in Playwright webServer for CI compatib…
ScriptedAlchemy 955268b
fix: implement manual server startup for better CI compatibility
ScriptedAlchemy 75a5cc7
Potential fix for code scanning alert no. 280: Unused variable, impor…
ScriptedAlchemy f0ed529
Update advanced-api/dynamic-remotes/app3/webpack.config.js
ScriptedAlchemy ca671d4
Update advanced-api/dynamic-remotes/README.md
ScriptedAlchemy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,39 +1,115 @@ | ||||||||||||||||||
| import React, { useState, useEffect, Suspense } from 'react'; | ||||||||||||||||||
| import { init, loadRemote } from '@module-federation/runtime'; | ||||||||||||||||||
|
|
||||||||||||||||||
| class ErrorBoundary extends React.Component { | ||||||||||||||||||
| constructor(props) { | ||||||||||||||||||
| super(props); | ||||||||||||||||||
| this.state = { hasError: false, error: null }; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| static getDerivedStateFromError(error) { | ||||||||||||||||||
| return { hasError: true, error }; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| componentDidCatch(error, errorInfo) { | ||||||||||||||||||
| console.error('Remote component error:', error, errorInfo); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| render() { | ||||||||||||||||||
| if (this.state.hasError) { | ||||||||||||||||||
| return ( | ||||||||||||||||||
| <div style={{ | ||||||||||||||||||
| padding: '2em', | ||||||||||||||||||
| border: '2px solid #ff6b6b', | ||||||||||||||||||
| borderRadius: '4px', | ||||||||||||||||||
| backgroundColor: '#ffe0e0', | ||||||||||||||||||
| color: '#c92a2a' | ||||||||||||||||||
| }}> | ||||||||||||||||||
| <h3>⚠️ Component Failed to Load</h3> | ||||||||||||||||||
| <p>Unable to load the remote component. Please try again or check the remote application.</p> | ||||||||||||||||||
| <details> | ||||||||||||||||||
| <summary>Error Details</summary> | ||||||||||||||||||
| <pre style={{ fontSize: '12px', overflow: 'auto' }}> | ||||||||||||||||||
| {this.state.error?.toString()} | ||||||||||||||||||
| </pre> | ||||||||||||||||||
| </details> | ||||||||||||||||||
| <button | ||||||||||||||||||
| onClick={() => this.setState({ hasError: false, error: null })} | ||||||||||||||||||
| style={{ | ||||||||||||||||||
| marginTop: '1em', | ||||||||||||||||||
| padding: '0.5em 1em', | ||||||||||||||||||
| backgroundColor: '#c92a2a', | ||||||||||||||||||
| color: 'white', | ||||||||||||||||||
| border: 'none', | ||||||||||||||||||
| borderRadius: '4px', | ||||||||||||||||||
| cursor: 'pointer' | ||||||||||||||||||
| }} | ||||||||||||||||||
| > | ||||||||||||||||||
| Retry | ||||||||||||||||||
| </button> | ||||||||||||||||||
| </div> | ||||||||||||||||||
| ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return this.props.children; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| const getRemoteEntry = (port) => { | ||||||||||||||||||
| const baseUrl = process.env.NODE_ENV === 'production' | ||||||||||||||||||
| ? (process.env.REACT_APP_REMOTE_BASE_URL || window.location.origin) | ||||||||||||||||||
| : 'http://localhost'; | ||||||||||||||||||
| return `${baseUrl}:${port}/remoteEntry.js`; | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| init({ | ||||||||||||||||||
| name: 'app1', | ||||||||||||||||||
| remotes: [ | ||||||||||||||||||
| { | ||||||||||||||||||
| name: 'app2', | ||||||||||||||||||
| entry: 'http://localhost:3002/remoteEntry.js', | ||||||||||||||||||
| entry: getRemoteEntry(3002), | ||||||||||||||||||
| }, | ||||||||||||||||||
| { | ||||||||||||||||||
| name: 'app3', | ||||||||||||||||||
| entry: 'http://localhost:3003/remoteEntry.js', | ||||||||||||||||||
| entry: getRemoteEntry(3003), | ||||||||||||||||||
| }, | ||||||||||||||||||
| ], | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| function useDynamicImport({ module, scope }) { | ||||||||||||||||||
| const [component, setComponent] = useState(null); | ||||||||||||||||||
| const [loading, setLoading] = useState(false); | ||||||||||||||||||
| const [error, setError] = useState(null); | ||||||||||||||||||
|
|
||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||
| if (!module || !scope) return; | ||||||||||||||||||
| if (!module || !scope) { | ||||||||||||||||||
| setComponent(null); | ||||||||||||||||||
| setError(null); | ||||||||||||||||||
| return; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| const loadComponent = async () => { | ||||||||||||||||||
| setLoading(true); | ||||||||||||||||||
| setError(null); | ||||||||||||||||||
| setComponent(null); | ||||||||||||||||||
|
|
||||||||||||||||||
| try { | ||||||||||||||||||
| console.log(`Loading remote module: ${scope}/${module}`); | ||||||||||||||||||
| const { default: Component } = await loadRemote(`${scope}/${module}`); | ||||||||||||||||||
| setComponent(() => Component); | ||||||||||||||||||
| console.log(`Successfully loaded: ${scope}/${module}`); | ||||||||||||||||||
|
||||||||||||||||||
| console.log(`Successfully loaded: ${scope}/${module}`); | |
| if (process.env.NODE_ENV !== 'production') { | |
| console.log(`Loading remote module: ${scope}/${module}`); | |
| } | |
| const { default: Component } = await loadRemote(`${scope}/${module}`); | |
| if (process.env.NODE_ENV !== 'production') { | |
| console.log(`Successfully loaded: ${scope}/${module}`); | |
| } |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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
getRemoteEntryfunction constructs URLs without proper validation, which could lead to URL injection vulnerabilities. Consider validating the port parameter and sanitizing the baseUrl to ensure it's a valid origin.