@modern-js/main-doc 2.68.7 → 2.68.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/en/guides/topic-detail/module-federation/application.mdx +3 -3
- package/docs/en/guides/topic-detail/module-federation/ssr.mdx +42 -3
- package/docs/zh/guides/topic-detail/module-federation/application.mdx +3 -3
- package/docs/zh/guides/topic-detail/module-federation/ssr.mdx +45 -4
- package/package.json +3 -3
- package/rspress.config.ts +6 -0
@@ -75,7 +75,7 @@ If you are not familiar with the capabilities of `$.tsx`, please read [Wildcard
|
|
75
75
|
:::
|
76
76
|
|
77
77
|
```tsx title="src/routes/remote/$.tsx"
|
78
|
-
import {
|
78
|
+
import { createRemoteAppComponent } from '@module-federation/bridge-react';
|
79
79
|
import { loadRemote } from '@module-federation/modern-js/runtime';
|
80
80
|
|
81
81
|
const ErrorBoundary = (info?: { error: { message: string } }) => {
|
@@ -87,7 +87,7 @@ const ErrorBoundary = (info?: { error: { message: string } }) => {
|
|
87
87
|
);
|
88
88
|
};
|
89
89
|
const Loading = <div>loading...</div>;
|
90
|
-
const RemoteApp =
|
90
|
+
const RemoteApp = createRemoteAppComponent({
|
91
91
|
loader: () => loadRemote('remote/app'),
|
92
92
|
fallback: ErrorBoundary,
|
93
93
|
loading: Loading,
|
@@ -97,7 +97,7 @@ export default RemoteApp;
|
|
97
97
|
```
|
98
98
|
|
99
99
|
:::info
|
100
|
-
[`
|
100
|
+
[`createRemoteAppComponent`](https://module-federation.io/practice/bridge/react-bridge.html#createremoteappcomponent) is used to load application-level modules.
|
101
101
|
:::
|
102
102
|
|
103
103
|
## Start the Application
|
@@ -26,6 +26,45 @@ Currently, `@module-federation/bridge-react` is not compatible with the Node env
|
|
26
26
|
|
27
27
|
## Data Fetching
|
28
28
|
|
29
|
-
:::
|
30
|
-
|
31
|
-
:::
|
29
|
+
:::tip
|
30
|
+
Currently, this feature is experimental and has not been fully practiced. Please use it with caution.
|
31
|
+
:::
|
32
|
+
|
33
|
+
Module Federation now supports [data fetching](https://module-federation.io/zh/guide/basic/data-fetch/index.html#%E7%AE%80%E4%BB%8B) capabilities. Each producer file can have a corresponding data fetching file, with the file name format of `[name].data.ts`.
|
34
|
+
|
35
|
+
In Modern.js, data fetching can be used with SSR. Using the example in the previous chapter, create a data fetching file:
|
36
|
+
|
37
|
+
```ts title="src/components/Button.data.ts"
|
38
|
+
import type { DataFetchParams } from '@module-federation/modern-js/react';
|
39
|
+
|
40
|
+
export type Data = {
|
41
|
+
data: string;
|
42
|
+
};
|
43
|
+
|
44
|
+
export const fetchData = async (params: DataFetchParams): Promise<Data> => {
|
45
|
+
return new Promise(resolve => {
|
46
|
+
setTimeout(() => {
|
47
|
+
resolve({
|
48
|
+
data: `data: ${new Date()}`,
|
49
|
+
});
|
50
|
+
}, 1000);
|
51
|
+
});
|
52
|
+
};
|
53
|
+
```
|
54
|
+
|
55
|
+
In Button, we get the data from the `Props`:
|
56
|
+
|
57
|
+
```ts title="src/components/Button.tsx"
|
58
|
+
import React from 'react';
|
59
|
+
import './index.css';
|
60
|
+
import type { Data } from './Button.data';
|
61
|
+
|
62
|
+
export const Button = (props: { mfData: Data }) => {
|
63
|
+
const { mfData } = props;
|
64
|
+
return (
|
65
|
+
<button type="button" className="test">
|
66
|
+
Remote Button {mfData?.data}
|
67
|
+
</button>
|
68
|
+
);
|
69
|
+
};
|
70
|
+
```
|
@@ -75,7 +75,7 @@ export default createModuleFederationConfig({
|
|
75
75
|
:::
|
76
76
|
|
77
77
|
```tsx title="src/routes/remote/$.tsx"
|
78
|
-
import {
|
78
|
+
import { createRemoteAppComponent } from '@module-federation/bridge-react';
|
79
79
|
import { loadRemote } from '@module-federation/modern-js/runtime';
|
80
80
|
|
81
81
|
const ErrorBoundary = (info?: { error: { message: string } }) => {
|
@@ -87,7 +87,7 @@ const ErrorBoundary = (info?: { error: { message: string } }) => {
|
|
87
87
|
);
|
88
88
|
};
|
89
89
|
const Loading = <div>loading...</div>;
|
90
|
-
const RemoteApp =
|
90
|
+
const RemoteApp = createRemoteAppComponent({
|
91
91
|
loader: () => loadRemote('remote/app'),
|
92
92
|
fallback: ErrorBoundary,
|
93
93
|
loading: Loading,
|
@@ -97,7 +97,7 @@ export default RemoteApp;
|
|
97
97
|
```
|
98
98
|
|
99
99
|
:::info
|
100
|
-
[`
|
100
|
+
[`createRemoteAppComponent`](https://module-federation.io/zh/practice/bridge/react-bridge.html#createremoteappcomponent) 用于加载应用级别模块。
|
101
101
|
:::
|
102
102
|
|
103
103
|
## 启动应用
|
@@ -13,9 +13,11 @@ export default defineConfig({
|
|
13
13
|
server: {
|
14
14
|
ssr: {
|
15
15
|
mode: 'stream',
|
16
|
+
// 禁用预渲染,优化 SSR 性能
|
17
|
+
disablePrerender: true,
|
16
18
|
},
|
17
19
|
},
|
18
|
-
}
|
20
|
+
})
|
19
21
|
```
|
20
22
|
|
21
23
|
为更好的性能体验,我们仅支持 Streaming SSR 情况使用这种能力组合。
|
@@ -26,6 +28,45 @@ export default defineConfig({
|
|
26
28
|
|
27
29
|
## 数据获取
|
28
30
|
|
29
|
-
:::
|
30
|
-
|
31
|
-
:::
|
31
|
+
:::tip
|
32
|
+
目前该功能为实验性功能,功能还未经过充分实践,请谨慎使用。
|
33
|
+
:::
|
34
|
+
|
35
|
+
Module Federation 在新版本中支持了[数据获取](https://module-federation.io/zh/guide/basic/data-fetch/index.html#%E7%AE%80%E4%BB%8B)的能力。每个生产者文件都可以有一个对应的数据获取文件,文件名格式为 `[name].data.ts`。
|
36
|
+
|
37
|
+
在 Modern.js 中,数据获取可以配合 SSR 使用。我们以前面章节的 Demo 为例子,创建一个数据获取文件:
|
38
|
+
|
39
|
+
```ts title="src/components/Button.data.ts"
|
40
|
+
import type { DataFetchParams } from '@module-federation/modern-js/react';
|
41
|
+
|
42
|
+
export type Data = {
|
43
|
+
data: string;
|
44
|
+
};
|
45
|
+
|
46
|
+
export const fetchData = async (params: DataFetchParams): Promise<Data> => {
|
47
|
+
return new Promise(resolve => {
|
48
|
+
setTimeout(() => {
|
49
|
+
resolve({
|
50
|
+
data: `data: ${new Date()}`,
|
51
|
+
});
|
52
|
+
}, 1000);
|
53
|
+
});
|
54
|
+
};
|
55
|
+
```
|
56
|
+
|
57
|
+
在 Button 中,我们从 `Props` 中获取到数据:
|
58
|
+
|
59
|
+
```ts title="src/components/Button.tsx"
|
60
|
+
import React from 'react';
|
61
|
+
import './index.css';
|
62
|
+
import type { Data } from './Button.data';
|
63
|
+
|
64
|
+
export const Button = (props: { mfData: Data }) => {
|
65
|
+
const { mfData } = props;
|
66
|
+
return (
|
67
|
+
<button type="button" className="test">
|
68
|
+
Remote Button {mfData?.data}
|
69
|
+
</button>
|
70
|
+
);
|
71
|
+
};
|
72
|
+
```
|
package/package.json
CHANGED
@@ -15,17 +15,17 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.68.
|
18
|
+
"version": "2.68.9",
|
19
19
|
"publishConfig": {
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
21
21
|
"access": "public"
|
22
22
|
},
|
23
23
|
"dependencies": {
|
24
24
|
"mermaid": "^11.4.1",
|
25
|
-
"@modern-js/sandpack-react": "2.68.
|
25
|
+
"@modern-js/sandpack-react": "2.68.9"
|
26
26
|
},
|
27
27
|
"devDependencies": {
|
28
|
-
"@rsbuild/plugin-sass": "1.3.
|
28
|
+
"@rsbuild/plugin-sass": "1.3.5",
|
29
29
|
"@shikijs/transformers": "^3.4.2",
|
30
30
|
"@rspress/shared": "2.0.0-beta.16",
|
31
31
|
"@rspress/plugin-llms": "2.0.0-beta.16",
|
package/rspress.config.ts
CHANGED
@@ -77,6 +77,12 @@ export default defineConfig({
|
|
77
77
|
mode: 'link',
|
78
78
|
content: 'https://github.com/web-infra-dev/modern.js',
|
79
79
|
},
|
80
|
+
{
|
81
|
+
icon: 'lark',
|
82
|
+
mode: 'link',
|
83
|
+
content:
|
84
|
+
'https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=d21hc667-9403-48a9-ba32-bc1440a80279',
|
85
|
+
},
|
80
86
|
],
|
81
87
|
},
|
82
88
|
route: {
|