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 1
1
import { kit } from '@module-federation/modern-js/runtime' ;
2
2
import './index.css' ;
3
- import RemoteSSRComponent2 from 'remote/Content2' ;
3
+ // import RemoteSSRComponent2 from 'remote/Content2';
4
4
5
5
const { createRemoteSSRComponent } = kit ;
6
6
@@ -18,19 +18,19 @@ const RemoteSSRComponent = createRemoteSSRComponent({
18
18
} ,
19
19
} ) ;
20
20
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
+ } ) ;
34
34
35
35
const Index = ( ) => (
36
36
< >
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 = {
3
3
} ;
4
4
5
5
export const fetchData = async ( ) : Promise < Data > => {
6
+ console . log ( 'Content.data.server' ) ;
7
+
6
8
return new Promise ( ( resolve ) => {
7
9
setTimeout ( ( ) => {
8
10
resolve ( {
Original file line number Diff line number Diff line change 1
1
import fs from 'fs' ;
2
2
import path from 'path' ;
3
+ import { TEMP_DIR } from '@module-federation/sdk' ;
3
4
4
5
import type { moduleFederationPlugin } from '@module-federation/sdk' ;
5
6
@@ -21,7 +22,7 @@ const addDataFetchExpose = (
21
22
if ( ! exposes [ dataFetchKey ] ) {
22
23
exposes [ dataFetchKey ] = filepath ;
23
24
}
24
- return true ;
25
+ return dataFetchKey ;
25
26
} ;
26
27
27
28
export function addDataFetchExposes (
@@ -46,7 +47,16 @@ export function addDataFetchExposes(
46
47
return ;
47
48
}
48
49
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
+ }
50
60
return ;
51
61
} ) ;
52
62
}
You can’t perform that action at this time.
0 commit comments