diff --git a/advanced-api/dynamic-remotes-runtime-environment-variables/host/src/components/Main.js b/advanced-api/dynamic-remotes-runtime-environment-variables/host/src/components/Main.js index 4fe18d07987..59bf7d156e9 100644 --- a/advanced-api/dynamic-remotes-runtime-environment-variables/host/src/components/Main.js +++ b/advanced-api/dynamic-remotes-runtime-environment-variables/host/src/components/Main.js @@ -29,7 +29,7 @@ const Main = () => {

my env is {ENV.API_URL}

The Dynamic System will take advantage Module Federation remotes and{' '} - exposes. It will no load components that have been loaded already. + exposes. It will not load components that have been loaded already.

diff --git a/advanced-api/dynamic-remotes/app1/src/App.js b/advanced-api/dynamic-remotes/app1/src/App.js index 0ab1c9ad759..63e6ee7a079 100644 --- a/advanced-api/dynamic-remotes/app1/src/App.js +++ b/advanced-api/dynamic-remotes/app1/src/App.js @@ -1,56 +1,59 @@ import React, { useState, useEffect, Suspense } from 'react'; - -import { init,loadRemote } from '@module-federation/runtime' +import { init, loadRemote } from '@module-federation/runtime'; init({ name: 'app1', remotes: [ { - name:'app2', - entry: 'http://localhost:3002/remoteEntry.js' + name: 'app2', + entry: 'http://localhost:3002/remoteEntry.js', }, { - name:'app3', - entry: 'http://localhost:3003/remoteEntry.js' + name: 'app3', + entry: 'http://localhost:3003/remoteEntry.js', }, - ] -}) - + ], +}); -function useDynamicImport({module,scope}) { - console.log(module,scope) +function useDynamicImport({ module, scope }) { const [component, setComponent] = useState(null); useEffect(() => { - if(!module && !scope) return + if (!module || !scope) return; + const loadComponent = async () => { - const { default: component } = await loadRemote(`${scope}/${module}`); - setComponent(() => component); + try { + const { default: Component } = await loadRemote(`${scope}/${module}`); + setComponent(() => Component); + } catch (error) { + console.error(`Error loading remote module ${scope}/${module}:`, error); + } }; + loadComponent(); - }, [module,scope]); - const fallback = ()=> null - return component || fallback + }, [module, scope]); + + return component; } function App() { - const [{ module, scope }, setSystem] = React.useState({}); + const [{ module, scope }, setSystem] = useState({}); - function setApp2() { + const setApp2 = () => { setSystem({ scope: 'app2', module: 'Widget', }); - } + }; - function setApp3() { + const setApp3 = () => { setSystem({ scope: 'app3', module: 'Widget', }); - } + }; - const Component = useDynamicImport({module,scope}); + const Component = useDynamicImport({ module, scope }); return (
Dynamic System Host

App 1

- The Dynamic System will take advantage Module Federation remotes and{' '} - exposes. It will no load components that have been loaded already. + The Dynamic System will take advantage of Module Federation remotes and{' '} + exposes. It will not load components that have already been loaded.

- - - + + {Component ? : null} +
); diff --git a/advanced-api/dynamic-remotes/package.json b/advanced-api/dynamic-remotes/package.json index ebf30e19a67..caa57f06501 100644 --- a/advanced-api/dynamic-remotes/package.json +++ b/advanced-api/dynamic-remotes/package.json @@ -14,8 +14,8 @@ "build": "pnpm --filter dynamic-remotes_app* --parallel build", "serve": "pnpm --filter dynamic-remotes_app* --parallel serve", "clean": "pnpm --filter dynamic-remotes_app* --parallel clean", - "e2e:ci": "pnpm start & wait-on http-get://localhost:3001/ && npx cypress run --config-file ../../cypress-e2e/config/cypress.config.ts --config '{\"supportFile\": \"../../cypress-e2e/support/e2e.ts\"}' --spec \"./e2e/*.cy.ts\" --browser=chrome", - "legacy:e2e:ci": "pnpm legacy:start & wait-on http-get://localhost:3001/ && npx cypress run --config-file ../../cypress-e2e/config/cypress.config.ts --config '{\"supportFile\": \"../../cypress-e2e/support/e2e.ts\"}' --spec \"./e2e/*.cy.ts\" --browser=chrome" + "e2e:ci": "pnpm start & sleep 1 && wait-on tcp:3001 && wait-on tcp:3002 && wait-on tcp:3003 && npx cypress run --config-file ../../cypress-e2e/config/cypress.config.ts --config '{\"supportFile\": \"../../cypress-e2e/support/e2e.ts\"}' --spec \"./e2e/*.cy.ts\" --browser=chrome", + "legacy:e2e:ci": "pnpm legacy:start & sleep 1 && wait-on tcp:3001 && wait-on tcp:3002 && wait-on tcp:3003 && npx cypress run --config-file ../../cypress-e2e/config/cypress.config.ts --config '{\"supportFile\": \"../../cypress-e2e/support/e2e.ts\"}' --spec \"./e2e/*.cy.ts\" --browser=chrome" }, "devDependencies": { "wait-on": "7.2.0" diff --git a/cypress-e2e/fixtures/constants.ts b/cypress-e2e/fixtures/constants.ts index cc4331b18d3..34dcb612fae 100644 --- a/cypress-e2e/fixtures/constants.ts +++ b/cypress-e2e/fixtures/constants.ts @@ -579,7 +579,7 @@ export class Constants { hostH3: 'my env is https://host.api.com', button: 'Load Remote Widget' }, - paragraph: 'The Dynamic System will take advantage Module Federation remotes and exposes. It will no load components that have been loaded already.', + paragraph: 'The Dynamic System will take advantage Module Federation remotes and exposes. It will not load components that have been loaded already.', buttonHeader: 'Remote Widget', buttonH2: 'My env is ', buttonParagraph: 'Using momentjs for format the date' @@ -849,7 +849,7 @@ export class Constants { } }, dynamicRemotesApp: { - paragraphText: 'The Dynamic System will take advantage Module Federation remotes and exposes. It will no load components that have been loaded already.', + paragraphText: 'The Dynamic System will take advantage of Module Federation remotes and exposes. It will not load components that have already been loaded.', widgetParagraphText: [ 'Moment shouldn\'t download twice, the host has no moment.js', 'Using momentjs for format the date'