@@ -8,7 +8,10 @@ import RemoteModule from './RemoteModule';
88import { getFederationGlobalScope } from './runtime/utils' ;
99import type ExternalModule from 'webpack/lib/ExternalModule' ;
1010import type FallbackModule from './FallbackModule' ;
11- import type { RemotesOptions } from '@module-federation/webpack-bundler-runtime' ;
11+ import type {
12+ ModuleIdToRemoteDataMapping ,
13+ RemotesOptions ,
14+ } from '@module-federation/webpack-bundler-runtime' ;
1215
1316const extractUrlAndGlobal = require (
1417 normalizeWebpackPath ( 'webpack/lib/util/extractUrlAndGlobal' ) ,
@@ -32,6 +35,8 @@ class RemoteRuntimeModule extends RuntimeModule {
3235 const chunkToRemotesMapping : Record < string , any > = { } ;
3336 const idToExternalAndNameMapping : Record < string | number , any > = { } ;
3437 const idToRemoteMap : RemotesOptions [ 'idToRemoteMap' ] = { } ;
38+ const moduleIdToRemoteDataMapping : ModuleIdToRemoteDataMapping = { } ;
39+
3540 // let chunkReferences: Set<Chunk> = new Set();
3641
3742 // if (this.chunk && chunkGraph) {
@@ -113,8 +118,15 @@ class RemoteRuntimeModule extends RuntimeModule {
113118 idToRemoteMap [ id ] . push ( {
114119 externalType : remoteModule . externalType ,
115120 name : remoteModule . externalType === 'script' ? remoteName : '' ,
116- externalModuleId,
117121 } ) ;
122+ moduleIdToRemoteDataMapping [ id ] = {
123+ shareScope : shareScope as string ,
124+ name,
125+ externalModuleId : externalModuleId as string ,
126+ // Preserve the extracted remote name so lazy updates can
127+ // rebuild idToRemoteMap via updateRemoteOptions.
128+ remoteName : remoteName ,
129+ } ;
118130 } ) ;
119131 }
120132 }
@@ -135,7 +147,14 @@ class RemoteRuntimeModule extends RuntimeModule {
135147 '\t' ,
136148 ) } ;`,
137149 `var idToRemoteMap = ${ JSON . stringify ( idToRemoteMap , null , '\t' ) } ;` ,
138- `${ federationGlobal } .bundlerRuntimeOptions.remotes = {idToRemoteMap,chunkMapping, idToExternalAndNameMapping, webpackRequire:${ RuntimeGlobals . require } };` ,
150+ `${ federationGlobal } .bundlerRuntimeOptions.remotes.chunkMapping = chunkMapping;` ,
151+ `${ federationGlobal } .bundlerRuntimeOptions.remotes.idToExternalAndNameMapping = idToExternalAndNameMapping;` ,
152+ `${ federationGlobal } .bundlerRuntimeOptions.remotes.idToRemoteMap = idToRemoteMap;` ,
153+ `${ RuntimeGlobals . require } .remotesLoadingData.moduleIdToRemoteDataMapping = ${ JSON . stringify (
154+ moduleIdToRemoteDataMapping ,
155+ null ,
156+ '\t' ,
157+ ) } ;`,
139158 `${
140159 RuntimeGlobals . ensureChunkHandlers
141160 } .remotes = ${ runtimeTemplate . basicFunction ( 'chunkId, promises' , [
0 commit comments