Skip to content

Commit de7c9ca

Browse files
committed
chore: use rspack host
1 parent 97875a6 commit de7c9ca

File tree

4 files changed

+25
-56
lines changed

4 files changed

+25
-56
lines changed

modernjs-ssr/host/modern.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { moduleFederationPlugin } from '@module-federation/modern-js';
33

44
// https://modernjs.dev/en/configure/app/usage
55
export default defineConfig({
6-
dev:{
6+
dev: {
77
// FIXME: it should be removed , related issue: https://github.com/web-infra-dev/modern.js/issues/5999
88
host: '0.0.0.0',
99
},
@@ -18,7 +18,7 @@ export default defineConfig({
1818
},
1919
plugins: [
2020
// not support data loader in rspack mode yet
21-
appTools(),
21+
appTools({ bundler: 'experimental-rspack' }),
2222
moduleFederationPlugin()
2323
],
2424
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createRemoteSSRComponent, loadRemote, registerRemotes } from '@modern-js/runtime/mf';
2+
3+
registerRemotes([
4+
{
5+
name: 'dynamic_provider',
6+
entry: 'http://localhost:3008/mf-manifest.json',
7+
}
8+
])
9+
10+
export const DynamicRemoteSSRComponents = createRemoteSSRComponent({
11+
loader: () => loadRemote('dynamic_provider/Image'),
12+
loading: 'loading...',
13+
fallback: ({ error }) => {
14+
if (error instanceof Error && error.message.includes('not exist')) {
15+
return <div>fallback - not existed id</div>;
16+
}
17+
return <div>fallback</div>;
18+
},
19+
});

modernjs-ssr/host/src/routes/page.data.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

modernjs-ssr/host/src/routes/page.tsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { createRemoteSSRComponent, loadRemote, registerRemotes } from '@modern-js/runtime/mf';
2-
import type { DataLoaderRes } from './page.data'
3-
import { useRouteLoaderData } from '@modern-js/runtime/router';
4-
2+
import {DynamicRemoteSSRComponents} from '../components/dynamic-remote'
53
import './index.css';
64

75
const RemoteSSRComponent = createRemoteSSRComponent({
@@ -16,28 +14,13 @@ const RemoteSSRComponent = createRemoteSSRComponent({
1614
},
1715
});
1816

19-
const Index = () => {
20-
const dataLoader = useRouteLoaderData('page') as DataLoaderRes;
21-
registerRemotes(dataLoader.providerList);
2217

23-
const DynamicRemoteSSRComponents = dataLoader.providerList.map(item => {
24-
const { id } = item;
25-
const Com = createRemoteSSRComponent({
26-
loader: () => loadRemote(id),
27-
loading: 'loading...',
28-
fallback: ({ error }) => {
29-
if (error instanceof Error && error.message.includes('not exist')) {
30-
return <div>fallback - not existed id</div>;
31-
}
32-
return <div>fallback</div>;
33-
},
34-
});
35-
return <Com />
36-
})
18+
19+
const Index = () => {
3720
return (
3821
<div className="container-box">
3922
<RemoteSSRComponent />
40-
{DynamicRemoteSSRComponents}
23+
<DynamicRemoteSSRComponents />
4124
</div>
4225
);
4326
}

0 commit comments

Comments
 (0)