11import  React  from  'react' ; 
2- import  helpers  from  '@module-federation/runtime/helpers' ; 
3- import  { 
4-   getInstance , 
5-   type  FederationHost , 
6- }  from  '@module-federation/enhanced/runtime' ; 
7- import  {  isBrowserEnv  }  from  '@module-federation/sdk' ; 
2+ import  logger  from  './logger' ; 
3+ import  {  getInstance  }  from  '@module-federation/enhanced/runtime' ; 
84import  { 
95  ErrorBoundary , 
106  ErrorBoundaryPropsWithComponent , 
117}  from  'react-error-boundary' ; 
12- import  {  getDataFetchInfo  }  from  './utils' ; 
138import  {  Await  }  from  './Await' ; 
9+ import  {  fetchData ,  getDataFetchId  }  from  './dataFetch' ; 
10+ import  {  getLoadedRemoteInfos  }  from  './utils' ; 
1411
1512type  IProps  =  { 
1613  id : string ; 
@@ -20,81 +17,6 @@ type IProps = {
2017
2118type  ReactKey  =  {  key ?: React . Key  |  null  } ; 
2219
23- async  function  fetchData ( 
24-   id : string , 
25-   uid : string , 
26- ) : Promise < unknown  |  undefined >  { 
27-   if  ( isBrowserEnv ( ) )  { 
28-     if  ( ! globalThis . _MF__DATA_FETCH_ID_MAP__ )  { 
29-       globalThis . _MF__DATA_FETCH_ID_MAP__  =  { } ; 
30-     } 
31-     if  ( globalThis . _MF__DATA_FETCH_ID_MAP__ [ uid ] )  { 
32-       return ; 
33-     } 
34-     let  res ; 
35-     let  rej ; 
36-     const  p  =  new  Promise ( ( resolve ,  reject )  =>  { 
37-       res  =  resolve ; 
38-       rej  =  reject ; 
39-     } ) ; 
40-     globalThis . _MF__DATA_FETCH_ID_MAP__ [ uid ]  =  [ p ,  res ,  rej ] ; 
41-     return  globalThis . _MF__DATA_FETCH_ID_MAP__ [ uid ] [ 0 ] ; 
42-   } 
43-   const  instance  =  getInstance ( ) ; 
44-   if  ( ! instance )  { 
45-     return ; 
46-   } 
47- 
48-   const  {  name }  =  instance . remoteHandler . idToRemoteMap [ id ]  ||  { } ; 
49-   if  ( ! name )  { 
50-     return ; 
51-   } 
52-   const  module  =  instance . moduleCache . get ( name ) ; 
53-   if  ( ! module )  { 
54-     return ; 
55-   } 
56-   const  dataFetchInfo  =  getDataFetchInfo ( { 
57-     id, 
58-     name, 
59-     alias : module . remoteInfo . alias , 
60-   } ) ; 
61-   if  ( ! dataFetchInfo )  { 
62-     return ; 
63-   } 
64-   const  key  =  `${ name }  @${ module . remoteInfo . version }  @${ dataFetchInfo . dataFetchName }  ` ; 
65-   const  fetchDataPromise  = 
66-     helpers . global . nativeGlobal . __FEDERATION__ . __DATA_FETCH_MAP__ . get ( key ) ; 
67-   if  ( ! fetchDataPromise )  { 
68-     return ; 
69-   } 
70- 
71-   const  fetchDataFn  =  await  fetchDataPromise ; 
72-   if  ( ! fetchDataFn )  { 
73-     return ; 
74-   } 
75-   console . log ( 'fetchDataFn: ' ,  fetchDataFn . toString ( ) ) ; 
76-   return  fetchDataFn ( ) ; 
77- } 
78- 
79- function  getLoadedRemoteInfos ( instance : FederationHost ,  id : string )  { 
80-   const  {  name,  expose }  =  instance . remoteHandler . idToRemoteMap [ id ]  ||  { } ; 
81-   if  ( ! name )  { 
82-     return ; 
83-   } 
84-   const  module  =  instance . moduleCache . get ( name ) ; 
85-   if  ( ! module )  { 
86-     return ; 
87-   } 
88-   const  {  remoteSnapshot }  =  instance . snapshotHandler . getGlobalRemoteInfo ( 
89-     module . remoteInfo , 
90-   ) ; 
91-   return  { 
92-     ...module . remoteInfo , 
93-     snapshot : remoteSnapshot , 
94-     expose, 
95-   } ; 
96- } 
97- 
9820function  getTargetModuleInfo ( id : string )  { 
9921  const  instance  =  getInstance ( ) ; 
10022  if  ( ! instance )  { 
@@ -199,9 +121,6 @@ export function createRemoteSSRComponent<T, E extends keyof T>(info: {
199121  fallback : ErrorBoundaryPropsWithComponent [ 'FallbackComponent' ] ; 
200122  export ?: E ; 
201123} )  { 
202-   // const [uid,setUid] = useState('') 
203-   console . log ( 'createRemoteSSRComponent trigger' ) ; 
204- 
205124  type  ComponentType  =  T [ E ]  extends  ( ...args : any )  =>  any 
206125    ? Parameters < T [ E ] > [ 0 ]  extends  undefined 
207126      ? ReactKey 
@@ -219,18 +138,24 @@ export function createRemoteSSRComponent<T, E extends keyof T>(info: {
219138  } ; 
220139
221140  const  getData  =  async  ( )  =>  { 
222-     // const nodeUid = isBrowserEnv () ? document.get : uid 
223141    const  m  =  await  callLoader ( ) ; 
224142    const  moduleId  =  m  &&  m [ Symbol . for ( 'mf_module_id' ) ] ; 
225-     const  data  =  await  fetchData ( moduleId ,  moduleId ) ; 
226-     console . log ( 'data: ' ,  data ) ; 
143+     const  dataFetchId  =  getDataFetchId ( moduleId ) ; 
144+     logger . debug ( 'getData dataFetchId: ' ,  dataFetchId ) ; 
145+     if  ( ! dataFetchId )  { 
146+       return ; 
147+     } 
148+     const  data  =  await  fetchData ( dataFetchId ) ; 
149+     logger . debug ( 'data: \n' ,  data ) ; 
227150    return  data ; 
228151  } ; 
229152
230153  const  LazyComponent  =  React . lazy ( async  ( )  =>  { 
231154    try  { 
232155      const  m  =  await  callLoader ( ) ; 
233156      const  moduleId  =  m  &&  m [ Symbol . for ( 'mf_module_id' ) ] ; 
157+       const  dataFetchId  =  getDataFetchId ( moduleId ) ; 
158+       logger . debug ( 'LazyComponent dataFetchId: ' ,  dataFetchId ) ; 
234159
235160      const  assets  =  collectSSRAssets ( { 
236161        id : moduleId , 
@@ -247,7 +172,7 @@ export function createRemoteSSRComponent<T, E extends keyof T>(info: {
247172                suppressHydrationWarning 
248173                dangerouslySetInnerHTML = { { 
249174                  __html : String . raw ` 
250-       globalThis._MF__DATA_FETCH_ID_MAP__['${ moduleId }  '][1](${ JSON . stringify ( props . _mfData ) }  ) 
175+       globalThis._MF__DATA_FETCH_ID_MAP__['${ dataFetchId }  '][1](${ JSON . stringify ( props . _mfData ) }  ) 
251176   ` , 
252177                } } 
253178              > </ script > 
0 commit comments