@modern-js/main-doc 2.18.0 → 2.18.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +10 -0
- package/docs/en/components/convention-routing-movitation.mdx +0 -0
- package/docs/en/components/routes-practice.mdx +0 -0
- package/docs/en/guides/basic-features/data-fetch.mdx +8 -0
- package/docs/en/guides/basic-features/routes.mdx +16 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/input/type.mdx +1 -1
- package/docs/zh/components/convention-routing-movitation.mdx +0 -0
- package/docs/zh/components/routes-practice.mdx +0 -0
- package/docs/zh/guides/basic-features/data-fetch.mdx +9 -0
- package/docs/zh/guides/basic-features/routes.mdx +17 -2
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/type.mdx +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
File without changes
|
File without changes
|
@@ -341,6 +341,14 @@ export default async (): Promise<ProfileData> => {
|
|
341
341
|
|
342
342
|
4. When run on the server side, the `loader` functions are packaged into a single bundle, so we do not recommend using `__filename` and `__dirname` for server-side code.
|
343
343
|
|
344
|
+
### FAQ
|
345
|
+
|
346
|
+
1. Relationship between loader and bff functions
|
347
|
+
|
348
|
+
In a CSR project, the loader is executed on the client side and the bff function can be called directly from the loader to make a request.
|
349
|
+
|
350
|
+
In an SSR project, each loader is also a server-side API, and we recommend using loader instead of the BFF function which http method is `get` to avoid one more layer of forwarding and execution.
|
351
|
+
|
344
352
|
## useLoader(Old)
|
345
353
|
|
346
354
|
**`useLoader`** is an API in Modern.js old version. The API is a React Hook specially provided for SSR applications, allowing developers to fetch data in components.
|
@@ -367,6 +367,22 @@ To further improve the user experience and reduce time of loading, Modern.js sup
|
|
367
367
|
- `intent`, the value we recommend for most scenarios, will automatically start loading the corresponding resources and the data defined in the data loader when you mouse over the Link, and will automatically unload it when the mouse is moved away. In our tests, even a direct click can reduce the loading time by about 200ms.
|
368
368
|
- `render`, when the Link component renders, it will load the corresponding resources and the data defined in the data loader.
|
369
369
|
|
370
|
+
#### FAQ
|
371
|
+
|
372
|
+
1. What is the difference between using `render` and not split chunks based on routes?
|
373
|
+
|
374
|
+
- With `render` you can specify which routes are loaded on the first screen, and you can control the rendering so that Link components are rendered only when they are in the visible area.
|
375
|
+
- With `render`, static resources are loaded only when they are idle and do not hog the network with first-screen static resources.
|
376
|
+
- When using server side rendering, data is also prefetched.
|
377
|
+
|
378
|
+
import Motivation from '@site-docs-en/components/convention-routing-movitation'
|
379
|
+
|
380
|
+
<Motivation/>
|
381
|
+
|
382
|
+
import Practice from '@site-docs-en/components/routes-practice'
|
383
|
+
|
384
|
+
<Practice/>
|
385
|
+
|
370
386
|
## Self-controlled routing
|
371
387
|
|
372
388
|
With `src/App.tsx` as the agreed entry, Modern.js will not do additional operations with multiple routes, developers can use the React Router 6 API for development by themselves, for example:
|
@@ -34,7 +34,7 @@ Each option supports two fields:
|
|
34
34
|
|
35
35
|
- label: display name.
|
36
36
|
|
37
|
-
### x-
|
37
|
+
### x-validator
|
38
38
|
|
39
39
|
schema verification rules. Formily's verification method is supported here, for details, please refer to [Formily Validate](https://formilyjs.org/zh-CN/guide/advanced/validate).
|
40
40
|
|
File without changes
|
File without changes
|
@@ -339,6 +339,15 @@ export default async (): Promise<ProfileData> => {
|
|
339
339
|
|
340
340
|
4. 在服务端运行时,`loader` 函数会被打包为一个统一的 bundle,所以我们不推荐服务端的代码使用 `__filename` 和 `__dirname`。
|
341
341
|
|
342
|
+
### 常见问题
|
343
|
+
|
344
|
+
1. loader 和 bff 函数的关系
|
345
|
+
|
346
|
+
在 CSR 项目中,loader 在客户端执行,在 loader 可以直接调用 bff 函数进行接口请求。
|
347
|
+
|
348
|
+
在 SSR 项目中,每个 loader 也是一个服务端接口,我们推荐使用 loader 替代 http method 为 `get` 的 BFF 函数,作为接口层,避免多一层转发和执行。
|
349
|
+
|
350
|
+
|
342
351
|
## useLoader(旧版)
|
343
352
|
|
344
353
|
**`useLoader`** 是 Modern.js 老版本中的 API。该 API 是一个 React Hook,专门提供给 SSR 应用使用,让开发者能同构的在组件中获取数据。
|
@@ -444,7 +444,7 @@ export const init = (context: RuntimeContext) => {
|
|
444
444
|
};
|
445
445
|
```
|
446
446
|
|
447
|
-
###
|
447
|
+
### 预加载
|
448
448
|
|
449
449
|
在约定式路由下, Modern.js 会根据路由,自动地对路由进行分片,当用户访问具体的路由时,会自动加载对应的分片,这样可以有效地减少首屏加载的时间。但这也带来了一个问题,当用户访问一个路由时,如果该路由对应的分片还未加载完成,就会出现白屏的情况。
|
450
450
|
这种情况下你可以通过定义 `loading` 组件,在静态资源加载完成前,展示一个自定义的 `loading` 组件。
|
@@ -462,9 +462,24 @@ export const init = (context: RuntimeContext) => {
|
|
462
462
|
:::
|
463
463
|
|
464
464
|
- `none`, 默认值,不会做 prefetch,没有任何额外的行为。
|
465
|
-
- `intent`,这是我们推荐大多数场景下使用的值,当你把鼠标放在 Link 上时,会自动开始加载对应的分片和 data loader
|
465
|
+
- `intent`,这是我们推荐大多数场景下使用的值,当你把鼠标放在 Link 上时,会自动开始加载对应的分片和 data loader 中定义的数据,当鼠标移开时,会自动取消加载。在我们的测试中,即使是快速点击,也能减少大约 200ms 的加载时间。
|
466
466
|
- `render`,当 Link 组件渲染时,就会加载对应的分片和 data loader 中定义的数据。
|
467
467
|
|
468
|
+
#### 常见问题
|
469
|
+
|
470
|
+
1. 使用 `render` 和不根据路由做静态资源分片的区别?
|
471
|
+
|
472
|
+
- 使用 `render` 可以指定哪些路由在首屏时,进行加载,同时你可以通过对渲染的控制,仅当 Link 组件进入到可视区域时,才对 Link 组件进行渲染。
|
473
|
+
- 使用 `render`,仅在空闲时对静态资源进行加载,不会与首屏静态资源抢占网络。
|
474
|
+
- 在 SSR 场景下,也会对数据进行预取。
|
475
|
+
|
476
|
+
import Motivation from '@site-docs/components/convention-routing-movitation'
|
477
|
+
|
478
|
+
<Motivation/>
|
479
|
+
|
480
|
+
import Practice from '@site-docs/components/routes-practice'
|
481
|
+
|
482
|
+
<Practice/>
|
468
483
|
|
469
484
|
|
470
485
|
## 自控式路由
|
package/package.json
CHANGED
@@ -15,13 +15,13 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.18.
|
18
|
+
"version": "2.18.1",
|
19
19
|
"publishConfig": {
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
21
21
|
"access": "public"
|
22
22
|
},
|
23
23
|
"peerDependencies": {
|
24
|
-
"@modern-js/builder-doc": "^2.18.
|
24
|
+
"@modern-js/builder-doc": "^2.18.1"
|
25
25
|
},
|
26
26
|
"devDependencies": {
|
27
27
|
"classnames": "^2",
|
@@ -33,9 +33,9 @@
|
|
33
33
|
"fs-extra": "^10",
|
34
34
|
"@types/node": "^16",
|
35
35
|
"@types/fs-extra": "^9",
|
36
|
-
"@modern-js/builder-doc": "2.18.
|
37
|
-
"@modern-js/doc-tools": "2.18.
|
38
|
-
"@modern-js/doc-plugin-auto-sidebar": "2.18.
|
36
|
+
"@modern-js/builder-doc": "2.18.1",
|
37
|
+
"@modern-js/doc-tools": "2.18.1",
|
38
|
+
"@modern-js/doc-plugin-auto-sidebar": "2.18.1"
|
39
39
|
},
|
40
40
|
"scripts": {
|
41
41
|
"dev": "modern dev",
|