-
-
Notifications
You must be signed in to change notification settings - Fork 420
Expand file tree
/
Copy pathpage.tsx
More file actions
147 lines (138 loc) · 3.81 KB
/
Copy pathpage.tsx
File metadata and controls
147 lines (138 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import React, { Suspense } from 'react';
import {
loadRemote,
registerRemotes,
} from '@module-federation/modern-js-v3/runtime';
type LazyRemoteModule = { default: React.ComponentType<any> };
registerRemotes([
{
name: 'dynamic_nested_remote',
entry: 'http://localhost:3054/mf-manifest.json',
},
{
name: 'dynamic_remote',
entry: 'http://localhost:3053/mf-manifest.json',
},
]);
const DynamicNestedRemote = React.lazy(() =>
loadRemote('dynamic_nested_remote/Content').then((m) => {
return m as LazyRemoteModule;
}),
);
const DynamicRemote = React.lazy(() =>
loadRemote('dynamic_remote').then((m) => {
return m as LazyRemoteModule;
}),
);
const Remote = React.lazy(() => {
return import('remote/Image').then((r) => {
return new Promise<typeof import('remote/Image')>((resolve) => {
setTimeout(() => {
resolve(r);
}, 2000);
});
});
});
const NestedRemote = React.lazy(() => {
return import('nested_remote/Content').then((r) => {
return new Promise<typeof import('nested_remote/Content')>((resolve) => {
setTimeout(() => {
resolve(r);
}, 1000);
});
});
});
const Index = (): JSX.Element => {
return (
<div>
<h1>Dynamic Nested Remote</h1>
<table border={1} cellPadding={5}>
<thead>
<tr>
<td></td>
<td>Desc</td>
<td>Host component</td>
<td>Remote component</td>
</tr>
</thead>
<tbody>
{/* remote */}
<tr>
<td>✅</td>
<td>This component is from a remote(localhost:3051)</td>
<td>
<button
style={{ marginBottom: '1rem' }}
onClick={() => alert('Client side Javascript works!')}
>
Click me to test host interactive!
</button>
</td>
<td>
<Suspense fallback={'loading remote for 2000ms'}>
<Remote />
</Suspense>
</td>
</tr>
{/* nested remote */}
<tr>
<td>✅</td>
<td>
This component is from a remote(localhost:3052) which nest a
static remote
</td>
<td>
<button
style={{ marginBottom: '1rem' }}
onClick={() => alert('Client side Javascript works!')}
>
Click me to test host interactive!
</button>
</td>
<td>
<Suspense fallback={'loading nested remote for 1000ms'}>
<NestedRemote />
</Suspense>
</td>
</tr>
{/* dynamic remote */}
<tr>
<td>✅</td>
<td>This component is from a dynamic remote(localhost:3053)</td>
<td>
<button
style={{ marginBottom: '1rem' }}
onClick={() => alert('Client side Javascript works!')}
>
Click me to test host interactive!
</button>
</td>
<td>
<DynamicRemote text="" />
</td>
</tr>
{/* dynamic nested remote */}
<tr>
<td>✅</td>
<td>
This component is from a dynamic remote(localhost:3054) which nest
a dynamic remote
</td>
<td>
<button
style={{ marginBottom: '1rem' }}
onClick={() => alert('Client side Javascript works!')}
>
Click me to test host interactive!
</button>
</td>
<td>
<DynamicNestedRemote />
</td>
</tr>
</tbody>
</table>
</div>
);
};
export default Index;