File tree Expand file tree Collapse file tree 4 files changed +42
-16
lines changed 
apps/modern-component-data-fetch 
packages/rsbuild-plugin/src/utils Expand file tree Collapse file tree 4 files changed +42
-16
lines changed Original file line number Diff line number Diff line change 11import  {  kit  }  from  '@module-federation/modern-js/runtime' ; 
22import  './index.css' ; 
3- import  RemoteSSRComponent2  from  'remote/Content2' ; 
3+ //  import RemoteSSRComponent2 from 'remote/Content2';
44
55const  {  createRemoteSSRComponent }  =  kit ; 
66
@@ -18,19 +18,19 @@ const RemoteSSRComponent = createRemoteSSRComponent({
1818  } , 
1919} ) ; 
2020
21- //  const RemoteSSRComponent2 = createRemoteSSRComponent({
22- //    loader: () => import('remote/Content2'),
23- //    loading: 'loading...',
24- //    export: 'default',
25- //    fallback: ({ error }) => {
26- //      console.log(33333333333);
27- //      console.error(error);
28- //      if (error instanceof Error && error.message.includes('not exist')) {
29- //        return <div>fallback - not existed id</div>;
30- //      }
31- //      return <div>fallback</div>;
32- //    },
33- //  });
21+ const  RemoteSSRComponent2  =  createRemoteSSRComponent ( { 
22+   loader : ( )  =>  import ( 'remote/Content2' ) , 
23+   loading : 'loading...' , 
24+   export : 'default' , 
25+   fallback : ( {  error } )  =>  { 
26+     console . log ( 33333333333 ) ; 
27+     console . error ( error ) ; 
28+     if  ( error  instanceof  Error  &&  error . message . includes ( 'not exist' ) )  { 
29+       return  < div > fallback - not existed id</ div > ; 
30+     } 
31+     return  < div > fallback</ div > ; 
32+   } , 
33+ } ) ; 
3434
3535const  Index  =  ( )  =>  ( 
3636  < > 
Original file line number Diff line number Diff line change 1+ export  type  Data  =  { 
2+   data : string ; 
3+ } ; 
4+ 
5+ export  const  fetchData  =  async  ( ) : Promise < Data >  =>  { 
6+   console . log ( 'Content.data.client' ) ; 
7+   return  new  Promise ( ( resolve )  =>  { 
8+     setTimeout ( ( )  =>  { 
9+       resolve ( { 
10+         data : `fetch data from provider ${ new  Date ( ) }  ` , 
11+       } ) ; 
12+     } ,  1000 ) ; 
13+   } ) ; 
14+ } ; 
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ export type Data = {
33} ; 
44
55export  const  fetchData  =  async  ( ) : Promise < Data >  =>  { 
6+   console . log ( 'Content.data.server' ) ; 
7+ 
68  return  new  Promise ( ( resolve )  =>  { 
79    setTimeout ( ( )  =>  { 
810      resolve ( { 
Original file line number Diff line number Diff line change 11import  fs  from  'fs' ; 
22import  path  from  'path' ; 
3+ import  {  TEMP_DIR  }  from  '@module-federation/sdk' ; 
34
45import  type  {  moduleFederationPlugin  }  from  '@module-federation/sdk' ; 
56
@@ -21,7 +22,7 @@ const addDataFetchExpose = (
2122  if  ( ! exposes [ dataFetchKey ] )  { 
2223    exposes [ dataFetchKey ]  =  filepath ; 
2324  } 
24-   return  true ; 
25+   return  dataFetchKey ; 
2526} ; 
2627
2728export  function  addDataFetchExposes ( 
@@ -46,7 +47,16 @@ export function addDataFetchExposes(
4647      return ; 
4748    } 
4849
49-     addDataFetchExpose ( exposes ,  key ,  dataFetchPath ) ; 
50+     const  dataFetchKey  =  addDataFetchExpose ( exposes ,  key ,  dataFetchPath ) ; 
51+     if  ( ! isServer  &&  dataFetchKey )  { 
52+       const  tempDataFetchFilepath  =  path . resolve ( 
53+         process . cwd ( ) , 
54+         `node_modules/${ TEMP_DIR }  /data-fetch.ts` , 
55+       ) ; 
56+       const  content  =  `export const fetchData=()=>{throw new Error('should not be called')};` ; 
57+       fs . writeFileSync ( tempDataFetchFilepath ,  content ) ; 
58+       exposes [ dataFetchKey ]  =  tempDataFetchFilepath ; 
59+     } 
5060    return ; 
5161  } ) ; 
5262} 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments