11import React from "react" ;
22
33export const loadModule = ( scope : string , module : string , url : string , preventSingleton = false ) => {
4- if ( ! globalThis . moduleFederationRuntime || ! globalThis . moduleFederationScopes ) {
4+ if ( ! globalThis . moduleFederationScopes ) {
55 throw new Error ( '[chayns-api] moduleFederationSharing has not been initialized. Make sure to call initModuleFederationSharing.' ) ;
66 }
77
8- const { loadRemote, registerRemotes } = globalThis . moduleFederationRuntime ;
9- const { registeredScopes, moduleMap, componentMap } = globalThis . moduleFederationScopes ;
8+ const { registeredScopes, moduleMap, componentMap, getInstance } = globalThis . moduleFederationScopes ;
109 try {
1110 // try simplifying url to avoid force when url is semantically the same, e.g.
1211 // https://example.com/remoteEntry.js and https://example.com/js/../remoteEntry.js
@@ -18,7 +17,7 @@ export const loadModule = (scope: string, module: string, url: string, preventSi
1817 if ( scope in registeredScopes ) {
1918 console . error ( `[chayns-api] call registerRemote with force for scope ${ scope } . url: ${ url } ` ) ;
2019 }
21- registerRemotes ( [
20+ getInstance ( ) . registerRemotes ( [
2221 {
2322 shareScope : url . endsWith ( 'v2.remoteEntry.js' ) || url . endsWith ( 'mf-manifest.json' ) ? 'chayns-api' : 'default' ,
2423 name : scope ,
@@ -35,7 +34,7 @@ export const loadModule = (scope: string, module: string, url: string, preventSi
3534 if ( ! ( module in moduleMap [ scope ] ) ) {
3635 const path = `${ scope } /${ module . replace ( / ^ \. \/ / , '' ) } ` ;
3736
38- const promise = loadRemote ( path ) ;
37+ const promise = getInstance ( ) . loadRemote ( path ) ;
3938
4039 promise . catch ( ( e ) => {
4140 console . error ( "[chayns-api] Failed to load module" , scope , url , e ) ;
@@ -53,12 +52,11 @@ const loadComponent = (scope: string, module: string, url: string, skipCompatMod
5352 console . warn ( '[chayns-api] skipCompatMode-option is deprecated and is set automatically now' ) ;
5453 }
5554
56- if ( ! globalThis . moduleFederationRuntime || ! globalThis . moduleFederationScopes ) {
55+ if ( ! globalThis . moduleFederationScopes ) {
5756 throw new Error ( '[chayns-api] moduleFederationSharing has not been initialized. Make sure to call initModuleFederationSharing.' ) ;
5857 }
5958
60- const { getInstance } = globalThis . moduleFederationRuntime ;
61- const { componentMap, registeredScopes } = globalThis . moduleFederationScopes ;
59+ const { componentMap, registeredScopes, getInstance } = globalThis . moduleFederationScopes ;
6260
6361 if ( ! componentMap [ scope ] ) {
6462 componentMap [ scope ] = { } ;
@@ -70,7 +68,7 @@ const loadComponent = (scope: string, module: string, url: string, skipCompatMod
7068 return Module ;
7169 }
7270
73- const shareScopes = getInstance ( ) ! . shareScopeMap ;
71+ const shareScopes = getInstance ( ) . shareScopeMap ;
7472
7573 const sharedReact = shareScopes [ 'chayns-api' ] . react ?. [ React . version ] ;
7674 const matchReactVersion = sharedReact && sharedReact . useIn . includes ( scope ) && sharedReact . lib ?.( ) === React ;
0 commit comments