@bleedingdev/modern-js-main-doc 3.2.0-ultramodern.101 → 3.2.0-ultramodern.103

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 preloading static resources and data with the `prefetch` attribute on `<Link>` components.
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
- Data preloading currently only preloads data returned by the [Data Loader](/guides/basic-features/data/data-fetch) in SSR projects.
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
- The `prefetch` attribute has three optional values:
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
- - `none`: The default value. No prefetching, no additional behavior.
484
- - `intent`: This is the recommended value for most scenarios. When you hover over the Link, it will automatically start loading the corresponding chunk and the data defined in the Data Loader. If the mouse moves away, the loading is automatically canceled. In our tests, even quick clicks can reduce load time by approximately 200ms.
485
- - `render`: When the `<Link>` component is rendered, it begins loading the corresponding chunk and data defined in the Data Loader.
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 the timing of route splitting, triggering only when the `<Link>` component enters the viewport. You can control the loading timing of the split by adjusting the rendering position of the `<Link>` component.
490
- - `render` loads static resources only during idle times, thus not occupying the loading time of critical modules.
491
- - Besides preloading route splits, `render` will also initiate data prefetching in SSR projects.
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
- 对数据的预加载目前只会预加载 SSR 项目中 [Data Loader](/guides/basic-features/data/data-fetch) 中返回的数据。
479
+ 路由数据预热需要显式开启。在 SSR 项目中,只有匹配到的路由通过 `handle.navigationWarmup.data` 开启后,才会预取 [Data Loader](/guides/basic-features/data/data-fetch) 返回的数据。
480
480
 
481
481
  :::
482
482
 
483
- `prefetch` 属性有三个可选值:
483
+ 默认情况下,同源链接会在 `<Link>` 渲染时预取路由模块,并在链接进入视窗时进行预加载。当用户开启 Save-Data 或处于慢速网络时,Modern.js 会跳过这些自动预热。
484
484
 
485
- - `none`, 默认值,不会做 prefetch,没有任何额外的行为。
486
- - `intent`,这是我们推荐大多数场景下使用的值,当你把鼠标放在 Link 上时,会自动开始加载对应的分片和 Data Loader 中定义的数据,当鼠标移开时,会自动取消加载。在我们的测试中,即使是快速点击,也能减少大约 200ms 的加载时间。
487
- - `render`,当 `<Link>` 组件渲染时,就会加载对应的分片和 Data Loader 中定义的数据。
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` 加载路由分片的时机是可控的,只有在 `<Link>` 组件进入视窗时才触发,可以通过控制 `<Link>` 组件的渲染位置来控制分片加载时机。
492
- - `render` 仅在空闲时对静态资源进行加载,不占用重要模块的加载时间。
493
- - 除了预加载路由分片,`render` SSR 项目中还会发起数据预取。
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.101",
21
+ "version": "3.2.0-ultramodern.103",
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.101"
28
+ "@modern-js/sandpack-react": "npm:@bleedingdev/modern-js-sandpack-react@3.2.0-ultramodern.103"
29
29
  },
30
30
  "devDependencies": {
31
- "@rsbuild/plugin-sass": "1.5.2",
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.2"
44
+ "rsbuild-plugin-open-graph": "1.1.3"
45
45
  },
46
46
  "scripts": {
47
47
  "dev": "rspress dev",