@bleedingdev/modern-js-main-doc 3.2.0-ultramodern.102 → 3.2.0-ultramodern.104
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.
|
@@ -464,7 +464,7 @@ When defining a `loading.tsx`, if the route transitions from `/` to `/blog` or f
|
|
|
464
464
|
|
|
465
465
|
## Prefetching
|
|
466
466
|
|
|
467
|
-
Most white screens during route transitions can be optimized by defining a `<Loading>` component. Modern.js also supports
|
|
467
|
+
Most white screens during route transitions can be optimized by defining a `<Loading>` component. Modern.js also supports navigation warmup with the `prefetch` and `preload` attributes on `<Link>` components.
|
|
468
468
|
|
|
469
469
|
For applications with higher performance requirements, prefetching can further enhance the user experience by reducing the time spent displaying the `<Loading>` component:
|
|
470
470
|
|
|
@@ -474,21 +474,36 @@ For applications with higher performance requirements, prefetching can further e
|
|
|
474
474
|
|
|
475
475
|
:::tip
|
|
476
476
|
|
|
477
|
-
|
|
477
|
+
Route data warmup is opt-in. In SSR projects, data returned by the [Data Loader](/guides/basic-features/data/data-fetch) is only prefetched when the matched route explicitly enables it with `handle.navigationWarmup.data`.
|
|
478
478
|
|
|
479
479
|
:::
|
|
480
480
|
|
|
481
|
-
|
|
481
|
+
By default, same-origin links prefetch the route module when the `<Link>` renders and preload when the link enters the viewport. Modern.js skips these automatic warmups on Save-Data or slow network connections.
|
|
482
482
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
- `render`: When the `<Link>` component is rendered, it begins
|
|
483
|
+
The `prefetch` attribute has four optional values:
|
|
484
|
+
|
|
485
|
+
- `render`: The default value. When the `<Link>` component is rendered, it begins warming the corresponding route module.
|
|
486
|
+
- `intent`: When users focus, hover, or touch the link, it starts warming the corresponding route module. If the intent is canceled before warmup starts, the warmup is canceled.
|
|
487
|
+
- `viewport`: When the `<Link>` component enters the viewport, it begins warming the corresponding route module.
|
|
488
|
+
- `none`: Disables automatic render prefetching. It also disables the default viewport preload unless an explicit `preload` value is provided.
|
|
489
|
+
|
|
490
|
+
The `preload` attribute accepts the same timing values and defaults to `viewport`. Explicit `preload` values always win, and `preload={false}` disables preload behavior.
|
|
491
|
+
|
|
492
|
+
To opt a route into SSR data warmup:
|
|
493
|
+
|
|
494
|
+
```ts title="routes/page.config.ts"
|
|
495
|
+
export const handle = {
|
|
496
|
+
navigationWarmup: {
|
|
497
|
+
data: true,
|
|
498
|
+
},
|
|
499
|
+
};
|
|
500
|
+
```
|
|
486
501
|
|
|
487
502
|
:::details Difference Between "render" and Not Using Route Splitting
|
|
488
503
|
|
|
489
|
-
- `render` allows you to control
|
|
490
|
-
- `
|
|
491
|
-
-
|
|
504
|
+
- `render` allows you to control route-module warmup with the position of the `<Link>` component in the tree.
|
|
505
|
+
- `viewport` lets you defer module warmup until the link is close to becoming actionable.
|
|
506
|
+
- SSR data prefetching is not enabled by default; use `handle.navigationWarmup.data` only for routes whose loader data is safe and useful to fetch before navigation.
|
|
492
507
|
|
|
493
508
|
:::
|
|
494
509
|
|
|
@@ -466,7 +466,7 @@ Modern.js 支持通过 `loading.tsx` 文件来解决这个问题,`routes/` 下
|
|
|
466
466
|
|
|
467
467
|
## 预加载
|
|
468
468
|
|
|
469
|
-
大多数切换路由时白屏的情况,都可以通过定义 `<Loading>` 组件来优化体验。Modern.js 也支持在 `<Link>` 组件上定义 `prefetch`
|
|
469
|
+
大多数切换路由时白屏的情况,都可以通过定义 `<Loading>` 组件来优化体验。Modern.js 也支持在 `<Link>` 组件上定义 `prefetch` 和 `preload` 属性,提前对导航进行预热。
|
|
470
470
|
|
|
471
471
|
对于有更高性能要求的应用,预加载可以进一步提升用户体验,减少展示 `<Loading>` 组件的时间:
|
|
472
472
|
|
|
@@ -476,21 +476,36 @@ Modern.js 支持通过 `loading.tsx` 文件来解决这个问题,`routes/` 下
|
|
|
476
476
|
|
|
477
477
|
:::tip
|
|
478
478
|
|
|
479
|
-
|
|
479
|
+
路由数据预热需要显式开启。在 SSR 项目中,只有匹配到的路由通过 `handle.navigationWarmup.data` 开启后,才会预取 [Data Loader](/guides/basic-features/data/data-fetch) 返回的数据。
|
|
480
480
|
|
|
481
481
|
:::
|
|
482
482
|
|
|
483
|
-
|
|
483
|
+
默认情况下,同源链接会在 `<Link>` 渲染时预取路由模块,并在链接进入视窗时进行预加载。当用户开启 Save-Data 或处于慢速网络时,Modern.js 会跳过这些自动预热。
|
|
484
484
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
- `render
|
|
485
|
+
`prefetch` 属性有四个可选值:
|
|
486
|
+
|
|
487
|
+
- `render`,默认值。当 `<Link>` 组件渲染时,就会预热对应的路由模块。
|
|
488
|
+
- `intent`,当用户聚焦、悬停或触摸链接时,会开始预热对应的路由模块。如果意图在预热开始前取消,预热也会取消。
|
|
489
|
+
- `viewport`,当 `<Link>` 组件进入视窗时,会开始预热对应的路由模块。
|
|
490
|
+
- `none`,关闭自动 render prefetch。如果没有显式设置 `preload`,也会关闭默认的 viewport preload。
|
|
491
|
+
|
|
492
|
+
`preload` 属性接受同样的时机值,默认值为 `viewport`。显式设置的 `preload` 总是优先生效,`preload={false}` 会关闭 preload 行为。
|
|
493
|
+
|
|
494
|
+
如果要让某个路由开启 SSR 数据预热:
|
|
495
|
+
|
|
496
|
+
```ts title="routes/page.config.ts"
|
|
497
|
+
export const handle = {
|
|
498
|
+
navigationWarmup: {
|
|
499
|
+
data: true,
|
|
500
|
+
},
|
|
501
|
+
};
|
|
502
|
+
```
|
|
488
503
|
|
|
489
504
|
:::details 值为 render 和不做路由分片的区别
|
|
490
505
|
|
|
491
|
-
- `render`
|
|
492
|
-
- `
|
|
493
|
-
-
|
|
506
|
+
- `render` 可以通过 `<Link>` 组件在组件树中的位置控制路由模块预热时机。
|
|
507
|
+
- `viewport` 可以把模块预热推迟到链接接近可操作时再触发。
|
|
508
|
+
- SSR 数据预取默认不开启;只有当路由的 loader 数据适合在导航前获取时,才应该使用 `handle.navigationWarmup.data`。
|
|
494
509
|
|
|
495
510
|
:::
|
|
496
511
|
|
package/package.json
CHANGED
|
@@ -18,17 +18,17 @@
|
|
|
18
18
|
"modern",
|
|
19
19
|
"modern.js"
|
|
20
20
|
],
|
|
21
|
-
"version": "3.2.0-ultramodern.
|
|
21
|
+
"version": "3.2.0-ultramodern.104",
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"registry": "https://registry.npmjs.org/",
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"mermaid": "^11.15.0",
|
|
28
|
-
"@modern-js/sandpack-react": "npm:@bleedingdev/modern-js-sandpack-react@3.2.0-ultramodern.
|
|
28
|
+
"@modern-js/sandpack-react": "npm:@bleedingdev/modern-js-sandpack-react@3.2.0-ultramodern.104"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@rsbuild/plugin-sass": "1.5.
|
|
31
|
+
"@rsbuild/plugin-sass": "1.5.3",
|
|
32
32
|
"@rspress/core": "2.0.13",
|
|
33
33
|
"@rspress/plugin-llms": "2.0.13",
|
|
34
34
|
"@rspress/shared": "2.0.13",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"fs-extra": "^11.3.5",
|
|
42
42
|
"react": "^19.2.6",
|
|
43
43
|
"react-dom": "^19.2.6",
|
|
44
|
-
"rsbuild-plugin-open-graph": "1.1.
|
|
44
|
+
"rsbuild-plugin-open-graph": "1.1.3"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"dev": "rspress dev",
|