You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/website-new/docs/en/guide/basic/data-fetch/index.mdx
+13-51Lines changed: 13 additions & 51 deletions
Original file line number
Diff line number
Diff line change
@@ -13,24 +13,24 @@ In SSR scenarios, `useEffect` does not execute. This behavior means that under n
13
13
14
14
To support this functionality, mainstream frameworks typically pre-fetch data using the `data loader` provided by React Router and inject it into the route component. The route component then retrieves the data using [useLoaderData](https://reactrouter.com/api/hooks/useLoaderData#useloaderdata) for rendering.
15
15
16
-
This approach heavily relies on routing functionality and cannot be used directly with Module Federation.
16
+
This approach heavily relies on routing functionality and cannot be used directly with {props.name||'Module Federation'}.
17
17
18
-
To solve this problem, Module Federation provides **component-level** data fetching capabilities, allowing developers to fetch data and render components in SSR scenarios.
18
+
To solve this problem, {props.name||'Module Federation'} provides **component-level** data fetching capabilities, allowing developers to fetch data and render components in SSR scenarios.
19
19
20
20
:::tip What is component-level?
21
-
The use of Module Federation can be broadly divided into two parts: components (functions) and applications. The difference between them is whether they include *routing* functionality.
21
+
The use of {props.name||'Module Federation'} can be broadly divided into two parts: components (functions) and applications. The difference between them is whether they include *routing* functionality.
22
22
:::
23
23
24
24
## How to Use
25
25
26
26
Different actions are required depending on the role.
27
27
28
28
### Producer
29
-
::: info Note
30
-
Producers can use [Rslib](../../basic/rsbuild#ssr) and [Modern.js](../../framework/modernjs) to generate components.
31
29
32
-
However, it's important to note that because the data in "Data Fetching" is injected by the consumer, if a component uses "Data Fetching", its exported non-MF components cannot be isomorphic with the MF components.
Each exposed module can have a corresponding `.data` file with the same name. These files can export a loader function, which we call a Data Loader. It executes before the corresponding `expose` component renders, providing data to the component. Here is an example:
36
36
@@ -84,7 +84,7 @@ export default List;
84
84
85
85
If you use Modern.js to develop a producer, and that producer's page is also accessed directly, you can use the [Data Loader](https://modernjs.dev/guides/basic-features/data/data-fetch.html) provided by Modern.js to inject data.
86
86
87
-
Its usage is almost identical to Module Federation's, except for the function name. This makes it easy to consume the Data Loader in the producer. Here's an example:
87
+
Its usage is almost identical to {props.name||'Module Federation'}'s, except for the function name. This makes it easy to consume the Data Loader in the producer. Here's an example:
88
88
89
89
* Create a `page.data.ts` file in the producer's page directory and export a function named `loader`:
In SSR scenarios, this can only be used with [Modern.js](../../framework/modernjs).
126
-
:::
127
124
128
-
In the consumer, we need to use the [createLazyComponent](../../../practice/bridge/react-bridge#createlazycomponent) API to load the remote component and fetch its data.
@@ -184,7 +146,7 @@ The loader function can be executed on the server or in the browser. A loader fu
184
146
185
147
In CSR applications, the loader function is executed in the browser, so they are all Client Loaders by default.
186
148
187
-
In SSR applications, the loader function is only executed on the server, so they are all Server Loaders by default. In SSR, Module Federation directly calls the corresponding loader function on the server. When switching routes in the browser, Module Federation sends an HTTP request to the SSR service, which also triggers the loader function on the server.
149
+
In SSR applications, the loader function is only executed on the server, so they are all Server Loaders by default. In SSR, {props.name||'Module Federation'} directly calls the corresponding loader function on the server. When switching routes in the browser, {props.name||'Module Federation'} sends an HTTP request to the SSR service, which also triggers the loader function on the server.
188
150
189
151
:::note NOTE
190
152
@@ -203,7 +165,7 @@ By default, in SSR applications, the loader function is only executed on the ser
203
165
1. To reduce network consumption in the browser by directly requesting the data source.
204
166
2. The application has a data cache in the browser and does not want to request data from the SSR service.
205
167
206
-
Module Federation supports adding an additional `.data.client` file in SSR applications, which also exports a named loader. In this case, if the Data Loader on the server fails and falls back, or when switching routes in the browser, the application will execute this loader function in the browser like a CSR application, instead of sending another data request to the SSR service.
168
+
{props.name||'Module Federation'} supports adding an additional `.data.client` file in SSR applications, which also exports a named loader. In this case, if the Data Loader on the server fails and falls back, or when switching routes in the browser, the application will execute this loader function in the browser like a CSR application, instead of sending another data request to the SSR service.
Copy file name to clipboardExpand all lines: apps/website-new/docs/en/guide/basic/data-fetch/prefetch.mdx
+6-34Lines changed: 6 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,10 @@
2
2
3
3
The `prefetch` function is used to pre-fetch resources and **data** for remote modules, thereby improving application performance and user experience. By pre-loading required content before a user accesses a feature, waiting times can be significantly reduced.
4
4
5
-
> This API requires the [`lazyLoadComponentPlugin` to be registered](../../../practice/bridge/react-bridge#register-lazyloadcomponentplugin) before it can be used.
By using `prefetch` flexibly, you can finely control the timing of resource loading based on your application's specific scenarios and user behavior, thereby optimizing application performance.
Copy file name to clipboardExpand all lines: apps/website-new/docs/en/guide/troubleshooting/runtime/RUNTIME-008.mdx
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -9,4 +9,4 @@ Failed to load resource during the runtime process, which may be caused by netwo
9
9
10
10
## Solutions
11
11
12
-
check whether the resource address is correct. If the resource address is correct, check whether the network is stable. If the network is unstable, you can add the retry mechanism, refer to [Runtime Retry Mechanism](en/plugin/plugins/retry-plugin.html).
12
+
check whether the resource address is correct. If the resource address is correct, check whether the network is stable. If the network is unstable, you can add the retry mechanism, refer to [Runtime Retry Mechanism](/plugin/plugins/retry-plugin.html).
loader 函数可能会在服务端或浏览器端执行。在服务端执行的 loader 函数,我们称为 Server Loader,在浏览器端执行的称为 Client Loader。
184
145
185
146
在 CSR 应用中,loader 函数会在浏览器端执行,即默认都是 Client Loader。
186
147
187
-
在 SSR 应用中,loader 函数只会在服务端执行,即默认都是 Server Loader。在 SSR Module Federation 会直接在服务端调用对应的 loader 函数。在浏览器端切换路由时,Module Federation 会发送一个 http 请求到 SSR 服务,同样在服务端触发 loader 函数。
148
+
在 SSR 应用中,loader 函数只会在服务端执行,即默认都是 Server Loader。在 SSR {props.name||'Module Federation'} 会直接在服务端调用对应的 loader 函数。在浏览器端切换路由时,Module Federation 会发送一个 http 请求到 SSR 服务,同样在服务端触发 loader 函数。
188
149
189
150
:::note NOTE
190
151
@@ -196,14 +157,14 @@ SSR 应用的 loader 函数只在服务端执行可以带来以下好处:
196
157
197
158
:::
198
159
199
-
#### 在 SSR 应用中使用 Client Loader
160
+
#####在 SSR 应用中使用 Client Loader
200
161
201
162
默认情况下,在 SSR 应用中,loader 函数只会在服务端执行。但有些场景下,开发者可能期望在浏览器端发送的请求不经过 SSR 服务,直接请求数据源,例如:
202
163
203
164
1. 在浏览器端希望减少网络消耗,直接请求数据源。
204
165
2. 应用在浏览器端有数据缓存,不希望请求 SSR 服务获取数据。
205
166
206
-
Module Federation 支持在 SSR 应用中额外添加 .data.client 文件,同样具名导出 loader。此时 SSR 应用在服务端执行 Data Loader 报错降级,或浏览器端切换路由时,会像 CSR 应用一样在浏览器端执行该 loader 函数,而不是再向 SSR 服务发送数据请求。
167
+
{props.name||'Module Federation'} 支持在 SSR 应用中额外添加 .data.client 文件,同样具名导出 loader。此时 SSR 应用在服务端执行 Data Loader 报错降级,或浏览器端切换路由时,会像 CSR 应用一样在浏览器端执行该 loader 函数,而不是再向 SSR 服务发送数据请求。
0 commit comments