@modern-js/main-doc 3.9.3 → 3.10.1

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.
Files changed (197) hide show
  1. package/docs/en/apis/app/hooks/api/lambda.mdx +2 -1
  2. package/docs/en/apis/app/hooks/config/html.mdx +1 -0
  3. package/docs/en/apis/app/hooks/config/mock.mdx +1 -0
  4. package/docs/en/apis/app/hooks/config/public.mdx +1 -0
  5. package/docs/en/apis/app/hooks/config/upload.mdx +2 -3
  6. package/docs/en/apis/app/hooks/modern-config.mdx +1 -0
  7. package/docs/en/apis/app/hooks/shared.mdx +1 -0
  8. package/docs/en/apis/app/hooks/src/modern.runtime.mdx +1 -0
  9. package/docs/en/apis/app/hooks/src/routes.mdx +1 -0
  10. package/docs/en/apis/app/hooks/src/server.mdx +2 -1
  11. package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +1 -0
  12. package/docs/en/apis/app/runtime/core/create-root.mdx +4 -1
  13. package/docs/en/apis/app/runtime/core/render.mdx +6 -2
  14. package/docs/en/apis/app/runtime/core/runtime-context.mdx +17 -17
  15. package/docs/en/apis/app/runtime/router/router.mdx +9 -6
  16. package/docs/en/apis/app/runtime/ssr/no-ssr.mdx +1 -0
  17. package/docs/en/apis/app/runtime/utility/head.mdx +1 -0
  18. package/docs/en/apis/app/runtime/utility/loadable.mdx +1 -0
  19. package/docs/en/community/blog/v3-release-note.mdx +36 -27
  20. package/docs/en/community/contributing-guide.mdx +15 -33
  21. package/docs/en/components/default-browserslist.mdx +0 -1
  22. package/docs/en/components/deploy-command.mdx +1 -1
  23. package/docs/en/components/deploy.mdx +1 -1
  24. package/docs/en/components/entry-scan-logic.mdx +1 -1
  25. package/docs/en/components/init-app.mdx +9 -3
  26. package/docs/en/components/international/custom-instance-code.mdx +0 -1
  27. package/docs/en/components/micro-runtime-config.mdx +12 -9
  28. package/docs/en/components/nodeVersion.mdx +2 -2
  29. package/docs/en/components/rsc-deploy-tip.mdx +0 -1
  30. package/docs/en/components/ssr-monitor.mdx +1 -1
  31. package/docs/en/configure/app/bff/cross-project.mdx +2 -2
  32. package/docs/en/configure/app/bff/prefix.mdx +1 -1
  33. package/docs/en/configure/app/dev/lazy-compilation.mdx +17 -1
  34. package/docs/en/configure/app/dev/start-url.mdx +0 -1
  35. package/docs/en/configure/app/output/css-modules.mdx +1 -5
  36. package/docs/en/configure/app/output/dist-path.mdx +0 -1
  37. package/docs/en/configure/app/output/inline-scripts.mdx +1 -2
  38. package/docs/en/configure/app/output/inline-styles.mdx +1 -2
  39. package/docs/en/configure/app/output/split-route-chunks.mdx +1 -1
  40. package/docs/en/configure/app/output/ssg.mdx +1 -1
  41. package/docs/en/configure/app/output/ssgByEntries.mdx +1 -0
  42. package/docs/en/configure/app/performance/chunk-split.mdx +1 -4
  43. package/docs/en/configure/app/runtime/plugins.mdx +6 -4
  44. package/docs/en/configure/app/server/rsc.mdx +1 -1
  45. package/docs/en/configure/app/server/ssr.mdx +7 -8
  46. package/docs/en/configure/app/server/tsconfig-path.mdx +2 -2
  47. package/docs/en/configure/app/tools/less.mdx +5 -6
  48. package/docs/en/configure/app/tools/sass.mdx +5 -6
  49. package/docs/en/configure/app/tools/svgr.mdx +7 -7
  50. package/docs/en/configure/app/usage.mdx +1 -5
  51. package/docs/en/guides/advanced-features/bff/cross-project.mdx +5 -4
  52. package/docs/en/guides/advanced-features/compatibility.mdx +0 -1
  53. package/docs/en/guides/advanced-features/international/advanced.mdx +1 -1
  54. package/docs/en/guides/advanced-features/international/api.mdx +34 -28
  55. package/docs/en/guides/advanced-features/international/best-practices.mdx +15 -15
  56. package/docs/en/guides/advanced-features/international/configuration.mdx +37 -37
  57. package/docs/en/guides/advanced-features/international/locale-detection.mdx +37 -28
  58. package/docs/en/guides/advanced-features/international/resource-loading.mdx +19 -17
  59. package/docs/en/guides/advanced-features/international/routing.mdx +8 -6
  60. package/docs/en/guides/advanced-features/international.mdx +8 -8
  61. package/docs/en/guides/advanced-features/server-monitor/logger.mdx +5 -5
  62. package/docs/en/guides/advanced-features/server-monitor/metrics.mdx +8 -8
  63. package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +1 -3
  64. package/docs/en/guides/advanced-features/source-build.mdx +1 -1
  65. package/docs/en/guides/advanced-features/web-server.mdx +3 -3
  66. package/docs/en/guides/basic-features/data/data-fetch.mdx +1 -3
  67. package/docs/en/guides/basic-features/data/data-write.mdx +24 -28
  68. package/docs/en/guides/basic-features/debug/mock.mdx +2 -2
  69. package/docs/en/guides/basic-features/debug/using-storybook.mdx +5 -6
  70. package/docs/en/guides/basic-features/html.mdx +2 -3
  71. package/docs/en/guides/basic-features/output-files.mdx +1 -1
  72. package/docs/en/guides/basic-features/render/overview.mdx +12 -12
  73. package/docs/en/guides/basic-features/render/rsc.mdx +16 -9
  74. package/docs/en/guides/basic-features/render/ssr-cache.mdx +5 -5
  75. package/docs/en/guides/basic-features/render/ssr.mdx +8 -12
  76. package/docs/en/guides/basic-features/render/streaming-ssr.mdx +2 -1
  77. package/docs/en/guides/basic-features/routes/config-routes.mdx +60 -59
  78. package/docs/en/guides/basic-features/testing/playwright.mdx +14 -8
  79. package/docs/en/guides/basic-features/testing/rstest.mdx +6 -4
  80. package/docs/en/guides/get-started/ai-coding-agents.mdx +6 -6
  81. package/docs/en/guides/get-started/introduction.mdx +0 -1
  82. package/docs/en/guides/topic-detail/module-federation/deploy.mdx +2 -2
  83. package/docs/en/guides/topic-detail/module-federation/introduce.mdx +0 -1
  84. package/docs/en/guides/upgrade/config.mdx +12 -0
  85. package/docs/en/guides/upgrade/other.mdx +4 -4
  86. package/docs/en/guides/upgrade/tailwindcss.mdx +0 -1
  87. package/docs/en/guides/upgrade/web-server.md +34 -17
  88. package/docs/en/index.md +1 -0
  89. package/docs/en/plugin/cli-plugins/api.mdx +23 -23
  90. package/docs/en/plugin/cli-plugins/life-cycle.mdx +2 -0
  91. package/docs/en/plugin/introduction.mdx +6 -6
  92. package/docs/en/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
  93. package/docs/en/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
  94. package/docs/en/plugin/plugin-system.mdx +19 -26
  95. package/docs/en/plugin/runtime-plugins/life-cycle.mdx +2 -0
  96. package/docs/en/plugin/server-plugins/api.mdx +11 -14
  97. package/docs/en/plugin/server-plugins/life-cycle.mdx +2 -0
  98. package/docs/zh/apis/app/hooks/api/lambda.mdx +1 -1
  99. package/docs/zh/apis/app/hooks/config/html.mdx +1 -0
  100. package/docs/zh/apis/app/hooks/config/mock.mdx +1 -0
  101. package/docs/zh/apis/app/hooks/config/public.mdx +1 -0
  102. package/docs/zh/apis/app/hooks/config/upload.mdx +2 -3
  103. package/docs/zh/apis/app/hooks/modern-config.mdx +1 -0
  104. package/docs/zh/apis/app/hooks/shared.mdx +1 -0
  105. package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +1 -0
  106. package/docs/zh/apis/app/hooks/src/routes.mdx +1 -0
  107. package/docs/zh/apis/app/hooks/src/server.mdx +2 -1
  108. package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +1 -1
  109. package/docs/zh/apis/app/runtime/core/create-root.mdx +4 -1
  110. package/docs/zh/apis/app/runtime/core/render.mdx +6 -3
  111. package/docs/zh/apis/app/runtime/core/runtime-context.mdx +17 -17
  112. package/docs/zh/apis/app/runtime/router/router.mdx +10 -6
  113. package/docs/zh/apis/app/runtime/ssr/no-ssr.mdx +1 -0
  114. package/docs/zh/apis/app/runtime/utility/head.mdx +1 -0
  115. package/docs/zh/apis/app/runtime/utility/loadable.mdx +1 -0
  116. package/docs/zh/community/blog/v3-release-note.mdx +38 -29
  117. package/docs/zh/community/contributing-guide.mdx +16 -34
  118. package/docs/zh/components/default-browserslist.mdx +0 -1
  119. package/docs/zh/components/deploy-command.mdx +1 -1
  120. package/docs/zh/components/deploy.mdx +1 -1
  121. package/docs/zh/components/entry-scan-logic.mdx +1 -1
  122. package/docs/zh/components/init-app.mdx +9 -3
  123. package/docs/zh/components/international/custom-instance-code.mdx +0 -1
  124. package/docs/zh/components/international/install-command.mdx +0 -1
  125. package/docs/zh/components/micro-runtime-config.mdx +12 -9
  126. package/docs/zh/components/nodeVersion.mdx +2 -2
  127. package/docs/zh/components/rsc-deploy-tip.mdx +0 -1
  128. package/docs/zh/components/ssr-monitor.mdx +1 -1
  129. package/docs/zh/configure/app/bff/cross-project.mdx +2 -2
  130. package/docs/zh/configure/app/bff/prefix.mdx +1 -1
  131. package/docs/zh/configure/app/dev/lazy-compilation.mdx +17 -1
  132. package/docs/zh/configure/app/html/crossorigin.mdx +0 -1
  133. package/docs/zh/configure/app/html/favicon.mdx +0 -1
  134. package/docs/zh/configure/app/output/convert-to-rem.mdx +0 -1
  135. package/docs/zh/configure/app/output/css-modules.mdx +1 -5
  136. package/docs/zh/configure/app/output/inline-scripts.mdx +1 -2
  137. package/docs/zh/configure/app/output/inline-styles.mdx +1 -2
  138. package/docs/zh/configure/app/output/source-map.mdx +0 -2
  139. package/docs/zh/configure/app/output/split-route-chunks.mdx +1 -1
  140. package/docs/zh/configure/app/output/ssg.mdx +1 -0
  141. package/docs/zh/configure/app/output/ssgByEntries.mdx +1 -1
  142. package/docs/zh/configure/app/performance/chunk-split.mdx +1 -4
  143. package/docs/zh/configure/app/resolve/dedupe.mdx +0 -1
  144. package/docs/zh/configure/app/runtime/plugins.mdx +6 -4
  145. package/docs/zh/configure/app/server/rsc.mdx +1 -1
  146. package/docs/zh/configure/app/server/ssr.mdx +6 -7
  147. package/docs/zh/configure/app/server/tsconfig-path.mdx +2 -2
  148. package/docs/zh/configure/app/tools/less.mdx +6 -7
  149. package/docs/zh/configure/app/tools/sass.mdx +6 -7
  150. package/docs/zh/configure/app/tools/svgr.mdx +11 -11
  151. package/docs/zh/configure/app/usage.mdx +1 -5
  152. package/docs/zh/guides/advanced-features/bff.mdx +1 -0
  153. package/docs/zh/guides/advanced-features/international/advanced.mdx +1 -1
  154. package/docs/zh/guides/advanced-features/international/api.mdx +28 -27
  155. package/docs/zh/guides/advanced-features/international/best-practices.mdx +15 -15
  156. package/docs/zh/guides/advanced-features/international/configuration.mdx +38 -36
  157. package/docs/zh/guides/advanced-features/international/locale-detection.mdx +37 -28
  158. package/docs/zh/guides/advanced-features/international/resource-loading.mdx +20 -16
  159. package/docs/zh/guides/advanced-features/international/routing.mdx +6 -4
  160. package/docs/zh/guides/advanced-features/international.mdx +9 -9
  161. package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +4 -6
  162. package/docs/zh/guides/advanced-features/server-monitor/metrics.mdx +9 -10
  163. package/docs/zh/guides/advanced-features/source-build.mdx +1 -1
  164. package/docs/zh/guides/advanced-features/web-server.mdx +3 -3
  165. package/docs/zh/guides/basic-features/data/data-fetch.mdx +1 -3
  166. package/docs/zh/guides/basic-features/data/data-write.mdx +25 -31
  167. package/docs/zh/guides/basic-features/debug/mock.mdx +2 -2
  168. package/docs/zh/guides/basic-features/debug/using-storybook.mdx +5 -5
  169. package/docs/zh/guides/basic-features/env-vars.mdx +0 -1
  170. package/docs/zh/guides/basic-features/html.mdx +2 -3
  171. package/docs/zh/guides/basic-features/render/overview.mdx +12 -13
  172. package/docs/zh/guides/basic-features/render/rsc.mdx +16 -9
  173. package/docs/zh/guides/basic-features/render/ssr.mdx +8 -17
  174. package/docs/zh/guides/basic-features/routes/config-routes.mdx +61 -59
  175. package/docs/zh/guides/basic-features/testing/playwright.mdx +15 -10
  176. package/docs/zh/guides/basic-features/testing/rstest.mdx +6 -4
  177. package/docs/zh/guides/get-started/ai-coding-agents.mdx +7 -7
  178. package/docs/zh/guides/topic-detail/module-federation/deploy.mdx +2 -2
  179. package/docs/zh/guides/upgrade/config.mdx +12 -0
  180. package/docs/zh/guides/upgrade/other.md +4 -11
  181. package/docs/zh/guides/upgrade/overview.mdx +1 -4
  182. package/docs/zh/guides/upgrade/tailwindcss.mdx +0 -1
  183. package/docs/zh/guides/upgrade/web-server.md +34 -19
  184. package/docs/zh/index.md +1 -0
  185. package/docs/zh/plugin/cli-plugins/api.mdx +24 -24
  186. package/docs/zh/plugin/cli-plugins/life-cycle.mdx +2 -0
  187. package/docs/zh/plugin/introduction.mdx +6 -6
  188. package/docs/zh/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
  189. package/docs/zh/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
  190. package/docs/zh/plugin/plugin-system.mdx +19 -26
  191. package/docs/zh/plugin/runtime-plugins/life-cycle.mdx +2 -0
  192. package/docs/zh/plugin/server-plugins/api.mdx +11 -14
  193. package/docs/zh/plugin/server-plugins/life-cycle.mdx +2 -0
  194. package/package.json +11 -13
  195. package/{rspress.config.ts → rstack.config.mts} +7 -10
  196. package/src/components/Footer/styles.module.scss +1 -1
  197. package/src/components/SolutionCards/index.module.scss +3 -1
@@ -26,9 +26,9 @@ i18nPlugin({
26
26
 
27
27
  **效果:**
28
28
 
29
- | 访问路径 | 结果 |
30
- | --- | --- |
31
- | `/about` | 重定向到 `/en/about` |
29
+ | 访问路径 | 结果 |
30
+ | ----------- | --------------------- |
31
+ | `/about` | 重定向到 `/en/about` |
32
32
  | `/en/about` | 正常访问,语言为 `en` |
33
33
  | `/zh/about` | 正常访问,语言为 `zh` |
34
34
 
@@ -108,7 +108,9 @@ function Navigation() {
108
108
  <nav>
109
109
  <I18nLink to="/">首页</I18nLink>
110
110
  <I18nLink to="/about">关于</I18nLink>
111
- <I18nLink to="/contact" replace>联系</I18nLink>
111
+ <I18nLink to="/contact" replace>
112
+ 联系
113
+ </I18nLink>
112
114
  </nav>
113
115
  );
114
116
  }
@@ -10,15 +10,15 @@ import I18nPluginIntroduce from '@site-docs/components/international/introduce';
10
10
 
11
11
  ## 从哪里开始?
12
12
 
13
- | 想做的事 | 文档 |
14
- | --- | --- |
15
- | 首次接入,跑通示例 | [快速开始](./international/quick-start.md) |
16
- | 了解完整的配置选项 | [配置说明](./international/configuration.md) |
17
- | 根据 URL / Cookie / Header 自动判断语言 | [语言检测](./international/locale-detection.md) |
18
- | 实现 `/en/about` 这类带语言前缀的路径 | [路由集成](./international/routing.md) |
19
- | 从远程服务或平台加载翻译资源 | [资源加载 → 自定义后端](./international/resource-loading.md#sdk-后端) |
20
- | SSR 场景、多入口、自定义实例 | [高级用法](./international/advanced.md) |
21
- | 查询 Hook / 组件 / 类型定义 | [API 参考](./international/api.md) |
13
+ | 想做的事 | 文档 |
14
+ | --------------------------------------- | --------------------------------------------------------------------- |
15
+ | 首次接入,跑通示例 | [快速开始](./international/quick-start.md) |
16
+ | 了解完整的配置选项 | [配置说明](./international/configuration.md) |
17
+ | 根据 URL / Cookie / Header 自动判断语言 | [语言检测](./international/locale-detection.md) |
18
+ | 实现 `/en/about` 这类带语言前缀的路径 | [路由集成](./international/routing.md) |
19
+ | 从远程服务或平台加载翻译资源 | [资源加载 → 自定义后端](./international/resource-loading.md#sdk-后端) |
20
+ | SSR 场景、多入口、自定义实例 | [高级用法](./international/advanced.md) |
21
+ | 查询 Hook / 组件 / 类型定义 | [API 参考](./international/api.md) |
22
22
 
23
23
  ## 核心能力
24
24
 
@@ -6,10 +6,10 @@
6
6
 
7
7
  基于服务端运行逻辑,Modern.js 在内部提供了以下日志事件:
8
8
 
9
- | 阶段 | 消息 | Level |
10
- | ------------- | -------------------------------------------- | ----- |
11
- | RENDER_HTML | App Render To HTML | error |
12
- | RENDER_STREAM | An error occurs during streaming SSR | error |
9
+ | 阶段 | 消息 | Level |
10
+ | ------------- | --------------------------------------------- | ----- |
11
+ | RENDER_HTML | App Render To HTML | error |
12
+ | RENDER_STREAM | An error occurs during streaming SSR | error |
13
13
  | RENDER_SHELL | An error occurs during streaming render shell | error |
14
14
 
15
15
  ## 内置 Monitor
@@ -17,5 +17,3 @@
17
17
  import InternalLogger from '@site-docs/components/internal-logger.mdx';
18
18
 
19
19
  <InternalLogger />
20
-
21
-
@@ -8,21 +8,20 @@
8
8
 
9
9
  基于服务端运行逻辑,Modern.js 在内部提供了以下指标事件:
10
10
 
11
- | Key | 描述 |
12
- | ------------------------ | --------------- |
13
- | server-handle-request | Modern.js Server 处理请求单次耗时 |
14
- | ssr-render-shell | [SSR]在使用 Streaming SSR 时, React 将渲染一个套壳(shell)优先传输。这里表明套壳渲染完成时间 |
15
- | ssr-render-html | [SSR] React 将组件树渲染成 html 所消耗的时间,通常不会超过 50ms |
16
- | server-middleware | Modern.js 自定义 Server `Middleware` 执行总时 |
17
- | server-loader | Server 端整体 Data Loader 耗时 |
18
- | server-loader-#id | Server 端各个 Data Loader 耗时 |
19
- | server-loader-navigation | 前端导航时,服务端 Data Loader 的整体耗时 |
11
+ | Key | 描述 |
12
+ | ------------------------ | -------------------------------------------------------------------------------------------- |
13
+ | server-handle-request | Modern.js Server 处理请求单次耗时 |
14
+ | ssr-render-shell | [SSR]在使用 Streaming SSR 时, React 将渲染一个套壳(shell)优先传输。这里表明套壳渲染完成时间 |
15
+ | ssr-render-html | [SSR] React 将组件树渲染成 html 所消耗的时间,通常不会超过 50ms |
16
+ | server-middleware | Modern.js 自定义 Server `Middleware` 执行总时 |
17
+ | server-loader | Server 端整体 Data Loader 耗时 |
18
+ | server-loader-#id | Server 端各个 Data Loader 耗时 |
19
+ | server-loader-navigation | 前端导航时,服务端 Data Loader 的整体耗时 |
20
20
 
21
21
  Modern.js 服务端流程如图所示:
22
22
 
23
23
  ![server](https://lf3-static.bytednsdoc.com/obj/eden-cn/eeeh7uhbepxlpe/edenx-website/e374def0-c179-40aa-9cfe-e82e181663b1.jpeg)
24
24
 
25
-
26
25
  ## 内置 Monitor
27
26
 
28
27
  import InternalMetrics from '@site-docs/components/internal-metrics.mdx';
@@ -142,7 +142,7 @@ Project reference 提供了以下能力:
142
142
  {
143
143
  "compilerOptions": {
144
144
  "composite": true
145
- },
145
+ }
146
146
  }
147
147
  ```
148
148
 
@@ -50,13 +50,13 @@ export default defineServerConfig({
50
50
 
51
51
  3. 你可以将 `server` 目录包含在 `tsconfig.json` 中
52
52
 
53
- ```json5
53
+ ```jsonc
54
54
  {
55
55
  // ...
56
56
  "include": [
57
57
  // ...
58
- "server"
59
- ]
58
+ "server",
59
+ ],
60
60
  }
61
61
  ```
62
62
 
@@ -25,9 +25,7 @@ Modern.js 推荐使用[约定式路由](/guides/basic-features/routes/routes)做
25
25
  在 `routes/user/page.data.ts` 文件中,可以导出一个 `loader` 函数:
26
26
 
27
27
  ```ts title="routes/user/page.data.ts"
28
- export type ProfileData = {
29
- /* some types */
30
- };
28
+ export type ProfileData = {/* some types */};
31
29
 
32
30
  export const loader = async (): Promise<ProfileData> => {
33
31
  const res = await fetch('https://api/user/profile');
@@ -33,7 +33,7 @@ export const action: ActionFunction = async ({ request }) => {
33
33
  const newUser = await request.json();
34
34
  const name = newUser.name;
35
35
  return updateUserProfile(name);
36
- }
36
+ };
37
37
  ```
38
38
 
39
39
  在路由组件中,你可以通过 `useFetcher` 获取对应 `submit` 函数,执行并触发 Data Action:
@@ -43,7 +43,7 @@ import {
43
43
  useFetcher,
44
44
  useLoaderData,
45
45
  useParams,
46
- Outlet
46
+ Outlet,
47
47
  } from '@modern-js/runtime/router';
48
48
 
49
49
  export default () => {
@@ -51,23 +51,21 @@ export default () => {
51
51
  const { submit } = useFetcher();
52
52
  const editUser = () => {
53
53
  const newUser = {
54
- name: 'Modern.js'
55
- }
54
+ name: 'Modern.js',
55
+ };
56
56
  return submit(newUser, {
57
57
  method: 'post',
58
58
  encType: 'application/json',
59
- })
60
- }
59
+ });
60
+ };
61
61
  return (
62
62
  <div>
63
63
  <button onClick={editUser}>edit user</button>
64
- <div className="user-profile">
65
- {userInfo}
66
- </div>
64
+ <div className="user-profile">{userInfo}</div>
67
65
  <Outlet context={userInfo}></Outlet>
68
66
  </div>
69
- )
70
- }
67
+ );
68
+ };
71
69
  ```
72
70
 
73
71
  当执行 `submit` 后,会触发定义的 `action` 函数。在 `action` 函数中,可以通过[入参](/guides/basic-features/data/data-write.html#入参)获取提交的数据,最终发送数据到服务端。
@@ -124,17 +122,18 @@ useSubmit:
124
122
 
125
123
  ```ts
126
124
  const submit = useSubmit();
127
- submit(null, { method: "post", action: "/logout" });
125
+ submit(null, { method: 'post', action: '/logout' });
128
126
  ```
129
127
 
130
128
  useFetcher:
131
129
 
132
130
  ```ts
133
131
  const { submit } = useFetcher();
134
- submit(null, { method: "post", action: "/logout" });
132
+ submit(null, { method: 'post', action: '/logout' });
135
133
  ```
136
134
 
137
135
  `submit` 函数有两个入参,第一个入参是传递到服务端的 `formData`。第二个入参是可选参数,其中
136
+
138
137
  - `method` 相当于表单提交时的 `method`,大部分写入数据的场景下,`method` 可以传入 `post`。
139
138
  - `action` 用来指定触发哪个路由组件的 Data Action,如果未传入 `action` 入参,默认会触发当前路由组件的 action,即 `user/page.tsx` 组件或子组件中执行 submit,会触发 `user/page.data.ts` 中定义的 action。
140
139
 
@@ -144,7 +143,6 @@ submit(null, { method: "post", action: "/logout" });
144
143
 
145
144
  :::
146
145
 
147
-
148
146
  ### 数据类型
149
147
 
150
148
  `submit` 函数的第一个入参,可以接受不同类型的值。
@@ -153,7 +151,7 @@ submit(null, { method: "post", action: "/logout" });
153
151
 
154
152
  ```ts
155
153
  let formData = new FormData();
156
- formData.append("cheese", "gouda");
154
+ formData.append('cheese', 'gouda');
157
155
  submit(formData);
158
156
  // In the action, you can get the data by request.json
159
157
  ```
@@ -162,7 +160,7 @@ submit(formData);
162
160
 
163
161
  ```ts
164
162
  let searchParams = new URLSearchParams();
165
- searchParams.append("cheese", "gouda");
163
+ searchParams.append('cheese', 'gouda');
166
164
  submit(searchParams);
167
165
  // In the action, you can get the data by request.json
168
166
  ```
@@ -170,10 +168,10 @@ submit(searchParams);
170
168
  或任意 `URLSearchParams` 构造函数可接受的值:
171
169
 
172
170
  ```ts
173
- submit("cheese=gouda&toasted=yes");
171
+ submit('cheese=gouda&toasted=yes');
174
172
  submit([
175
- ["cheese", "gouda"],
176
- ["toasted", "yes"],
173
+ ['cheese', 'gouda'],
174
+ ['toasted', 'yes'],
177
175
  ]);
178
176
  // In the action, you can get the data by request.json
179
177
  ```
@@ -182,11 +180,11 @@ submit([
182
180
 
183
181
  ```ts
184
182
  submit(
185
- { key: "value" },
183
+ { key: 'value' },
186
184
  {
187
- method: "post",
188
- encType: "application/x-www-form-urlencoded",
189
- }
185
+ method: 'post',
186
+ encType: 'application/x-www-form-urlencoded',
187
+ },
190
188
  );
191
189
 
192
190
  // In the action, you can get the data by request.formData
@@ -195,14 +193,11 @@ submit(
195
193
  你也可以通过第二个参数,指定为编码方式:
196
194
 
197
195
  ```tsx
198
- submit(
199
- { key: "value" },
200
- { method: "post", encType: "application/json" }
201
- );
196
+ submit({ key: 'value' }, { method: 'post', encType: 'application/json' });
202
197
 
203
198
  submit('{"key":"value"}', {
204
- method: "post",
205
- encType: "application/json",
199
+ method: 'post',
200
+ encType: 'application/json',
206
201
  });
207
202
 
208
203
  // In the action, you can get the data by request.json
@@ -211,7 +206,7 @@ submit('{"key":"value"}', {
211
206
  或提交纯文本:
212
207
 
213
208
  ```ts
214
- submit("value", { method: "post", encType: "text/plain" });
209
+ submit('value', { method: 'post', encType: 'text/plain' });
215
210
  // In the action, you can get the data by request.text
216
211
  ```
217
212
 
@@ -228,7 +223,6 @@ Modern.js 中提供 Data Action 主要是为了使 UI 和服务器的状态能
228
223
 
229
224
  如果项目中组件共享的数据主要来自于服务端的状态,则无需在项目引入浏览器端状态管理库。可以使用 Data Loader 请求数据,通过 [`useRouteLoaderData`](/guides/basic-features/data/data-fetch.md) 在子组件中共享数据,使用 Data Action 修改和同步服务端的状态。
230
225
 
231
-
232
226
  ## CSR 和 SSR
233
227
 
234
228
  与 Data Loader 一样,SSR 项目中,Data Action 是在服务端执行的(框架会自动发请求触发 Data Action),而在 CSR 项目中,Data Action 是在浏览器端执行的。
@@ -101,8 +101,8 @@ type MockConfig = {
101
101
  };
102
102
 
103
103
  export const config = {
104
- enable: false
105
- }
104
+ enable: false,
105
+ };
106
106
  ```
107
107
 
108
108
  目前仅支持 `enable` 配置,开发者可以通过该配置控制是否执行 Mock。
@@ -2,7 +2,7 @@
2
2
  sidebar_position: 15
3
3
  ---
4
4
 
5
- import { PackageManagerTabs } from '@theme'
5
+ import { PackageManagerTabs } from '@theme';
6
6
 
7
7
  # 使用 Storybook
8
8
 
@@ -33,14 +33,14 @@ Modern.js 基于此工具实现了 `storybook-addon-modernjs`,该插件会加
33
33
  ## 配置 `.storybook/main.ts`
34
34
 
35
35
  ```ts
36
- import type { StorybookConfig } from 'storybook-react-rsbuild'
36
+ import type { StorybookConfig } from 'storybook-react-rsbuild';
37
37
 
38
38
  const config: StorybookConfig = {
39
39
  stories: ['../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
40
40
  addons: ['storybook-addon-modernjs'],
41
41
  framework: 'storybook-react-rsbuild',
42
- }
43
- export default config
42
+ };
43
+ export default config;
44
44
  ```
45
45
 
46
46
  ## Storybook 中进行 BFF 一体化调用
@@ -55,7 +55,7 @@ export default config
55
55
  {
56
56
  "scripts": {
57
57
  "dev:api": "modern dev --api-only",
58
- "storybook": "BFF_PROXY=1 storybook dev -p 6006 --no-open",
58
+ "storybook": "BFF_PROXY=1 storybook dev -p 6006 --no-open"
59
59
  }
60
60
  }
61
61
  ```
@@ -72,7 +72,6 @@ function App() {
72
72
 
73
73
  :::
74
74
 
75
-
76
75
  ## 自定义环境变量
77
76
 
78
77
  环境变量支持通过 `shell` 和 `.env` 文件两种方式指定。
@@ -20,9 +20,8 @@ Modern.js 约定,在 `src/` 或入口目录下,可以创建 `Document.tsx`
20
20
  ├── entry-a
21
21
  │ ├── Document.tsx
22
22
  │ └── routes
23
- ├── entry-b
24
- │ └── routes
25
- └── modern-app-env.d.ts
23
+ └── entry-b
24
+ └── routes
26
25
  ```
27
26
 
28
27
  `entry-a` 会优先使用当前入口下的 `Document.tsx` 文件。如果当前入口没有 `Document.tsx` 文件,例如 `entry-b`,则会查找根目录下的 `Document.tsx` 文件。
@@ -8,21 +8,21 @@ Modern.js 支持多种渲染模式,不同的渲染模式适用于不同的场
8
8
 
9
9
  ## 渲染模式速览
10
10
 
11
- | 渲染模式 | 特点 | 适用场景 |
12
- |---------|------|---------|
13
- | **CSR** | 在浏览器端执行 JavaScript 渲染页面 | 交互性强、对 SEO 要求不高的应用 |
14
- | **SSR** | 在服务端预先渲染完整 HTML 页面 | 对首屏性能和 SEO 要求高的网站 |
15
- | **Streaming SSR** | 边渲染边返回,更快显示初始 UI | 需要更快首屏感知速度的应用(**SSR 默认模式**) |
16
- | **RSC** | 组件在服务端渲染,减少客户端 JS 体积;数据与组件逻辑高内聚,减少状态传递 | 追求极致性能、需要减少客户端代码的项目 |
17
- | **SSG** | 构建时生成静态页面,可被 CDN 缓存 | 内容相对静态的网站,如博客、文档站点 |
11
+ | 渲染模式 | 特点 | 适用场景 |
12
+ | ----------------- | ------------------------------------------------------------------------ | ---------------------------------------------- |
13
+ | **CSR** | 在浏览器端执行 JavaScript 渲染页面 | 交互性强、对 SEO 要求不高的应用 |
14
+ | **SSR** | 在服务端预先渲染完整 HTML 页面 | 对首屏性能和 SEO 要求高的网站 |
15
+ | **Streaming SSR** | 边渲染边返回,更快显示初始 UI | 需要更快首屏感知速度的应用(**SSR 默认模式**) |
16
+ | **RSC** | 组件在服务端渲染,减少客户端 JS 体积;数据与组件逻辑高内聚,减少状态传递 | 追求极致性能、需要减少客户端代码的项目 |
17
+ | **SSG** | 构建时生成静态页面,可被 CDN 缓存 | 内容相对静态的网站,如博客、文档站点 |
18
18
 
19
19
  ## 性能对比
20
20
 
21
- | 渲染技术 | 核心优势 | 主要瓶颈 |
22
- |---------|---------|---------|
23
- | **SSR** | 服务端预渲染,有利于 SEO | 需等待所有数据加载完成才能响应 |
24
- | **Streaming SSR** | 边渲染边返回,更快首屏 | JS 体积仍然较大 |
25
- | **Streaming SSR + RSC** | 减少客户端 JS 体积 | - |
21
+ | 渲染技术 | 核心优势 | 主要瓶颈 |
22
+ | ----------------------- | ------------------------ | ------------------------------ |
23
+ | **SSR** | 服务端预渲染,有利于 SEO | 需等待所有数据加载完成才能响应 |
24
+ | **Streaming SSR** | 边渲染边返回,更快首屏 | JS 体积仍然较大 |
25
+ | **Streaming SSR + RSC** | 减少客户端 JS 体积 | - |
26
26
 
27
27
  ## 如何选择
28
28
 
@@ -42,7 +42,6 @@ Modern.js 支持多种渲染模式组合使用:
42
42
  - **SSG + SSR**:部分页面静态,部分页面动态
43
43
  - **CSR + RSC**:客户端渲染 + 部分 Server Component
44
44
 
45
-
46
45
  ## 相关文档
47
46
 
48
47
  - [服务端渲染(SSR)](/guides/basic-features/render/ssr)
@@ -239,12 +239,12 @@ export default function DashboardPage() {
239
239
 
240
240
  ### 两种数据获取方式对比
241
241
 
242
- | 特性 | Server Component 中获取 | Data Loader 中获取 |
243
- | --- | --- | --- |
244
- | 避免请求瀑布 | 需要手动优化 | ✅ 自动并行执行 |
245
- | 组件内聚性 | ✅ 数据和 UI 在同一处 | 数据逻辑分离到单独文件 |
246
- | 维护性 | ✅ 更易理解和维护 | 需要维护额外文件 |
247
- | 类型安全 | ✅ 天然类型推断 | 需要手动管理类型 |
242
+ | 特性 | Server Component 中获取 | Data Loader 中获取 |
243
+ | ------------ | ----------------------- | ---------------------- |
244
+ | 避免请求瀑布 | 需要手动优化 | ✅ 自动并行执行 |
245
+ | 组件内聚性 | ✅ 数据和 UI 在同一处 | 数据逻辑分离到单独文件 |
246
+ | 维护性 | ✅ 更易理解和维护 | 需要维护额外文件 |
247
+ | 类型安全 | ✅ 天然类型推断 | 需要手动管理类型 |
248
248
 
249
249
  **一般情况下,我们推荐在 Server Component 中获取数据**,因为在服务端瀑布请求对性能的影响较小,这种方式使组件更加内聚,数据获取逻辑和 UI 渲染在同一处,更易于理解和维护。但如果你的页面有多个独立的数据源,且希望完全避免请求瀑布问题,Data Loader 的并行执行特性会更有优势。
250
250
 
@@ -268,7 +268,11 @@ export default function DashboardPage() {
268
268
 
269
269
  ```tsx title="routes/user/page.tsx"
270
270
  // Server Component 通过 props 接收 loaderData
271
- export default function UserPage({ loaderData }: { loaderData: { name: string } }) {
271
+ export default function UserPage({
272
+ loaderData,
273
+ }: {
274
+ loaderData: { name: string };
275
+ }) {
272
276
  return <div>Welcome, {loaderData.name}</div>;
273
277
  }
274
278
  ```
@@ -276,7 +280,11 @@ export default function UserPage({ loaderData }: { loaderData: { name: string }
276
280
  ```tsx title="routes/user/page.tsx"
277
281
  'use client';
278
282
  // Client Component 同样可以通过 props 接收 loaderData
279
- export default function UserPage({ loaderData }: { loaderData: { name: string } }) {
283
+ export default function UserPage({
284
+ loaderData,
285
+ }: {
286
+ loaderData: { name: string };
287
+ }) {
280
288
  return <div>Welcome, {loaderData.name}</div>;
281
289
  }
282
290
  ```
@@ -600,7 +608,6 @@ export default function ProfilePage() {
600
608
 
601
609
  import DeployTip from '@site-docs/components/rsc-deploy-tip';
602
610
 
603
-
604
611
  <DeployTip />
605
612
 
606
613
  ## 常见问题
@@ -74,10 +74,8 @@ export default () => {
74
74
  };
75
75
  ```
76
76
 
77
-
78
77
  ### 使用 Client Loader
79
78
 
80
-
81
79
  默认情况下,在 SSR 应用中,`loader` 函数只会在服务端执行。但有些场景下,开发者可能期望在浏览器端发送的请求不经过 SSR 服务,直接请求数据源,例如:
82
80
 
83
81
  1. 在浏览器端希望减少网络消耗,直接请求数据源。
@@ -96,12 +94,10 @@ export async function loader({ params }) {
96
94
  const data = await res.json();
97
95
  return {
98
96
  message: data.message,
99
- }
97
+ };
100
98
  }
101
99
  ```
102
100
 
103
-
104
-
105
101
  ## SSR 降级
106
102
 
107
103
  在 Modern.js 中,如果应用在 SSR 过程中出现异常,Modern.js 会自动降级到 CSR 模式,并在 CSR 重新发起数据请求,保证页面能够正常展示。SSR 降级的原因主要分为两种:
@@ -133,11 +129,7 @@ const Page = () => {
133
129
  const undefinedVars = data.unDefined;
134
130
  const definedVars = data.defined;
135
131
 
136
- return (
137
- <div>
138
- {isNode ? undefinedVars.msg : definedVars.msg}
139
- </div>
140
- );
132
+ return <div>{isNode ? undefinedVars.msg : definedVars.msg}</div>;
141
133
  };
142
134
 
143
135
  export default Page;
@@ -222,7 +214,7 @@ document.addEventListener('load', () => {
222
214
  console.log('document load');
223
215
  });
224
216
 
225
- export const doSomething = () => {}
217
+ export const doSomething = () => {};
226
218
  ```
227
219
 
228
220
  如果直接引用到组件中,会造成 SSR 加载报错,即使你已经使用环境变量进行判断,但仍然无法移除依赖中副作用的执行。
@@ -234,8 +226,8 @@ export const Page = () => {
234
226
  if (process.env.MODERN_TARGET === 'browser') {
235
227
  doSomething();
236
228
  }
237
- return <div>Hello World</div>
238
- }
229
+ return <div>Hello World</div>;
230
+ };
239
231
  ```
240
232
 
241
233
  Modern.js 也支持通过 `.server.` 后缀的文件来区分 SSR Bundle 和 CSR Bundle 产物的打包文件。可以创建同名的 `.ts` 和 `.server.ts` 文件做一层代理:
@@ -251,12 +243,12 @@ export const doSomething: any = () => {};
251
243
  在文件中直接引入 `./a`,此时 SSR 打包下会优先使用 `.server.ts` 后缀的文件,CSR 打包下会使用 `.ts` 后缀的文件。
252
244
 
253
245
  ```tsx title="routes/page.tsx"
254
- import { doSomething } from './a'
246
+ import { doSomething } from './a';
255
247
 
256
248
  export const Page = () => {
257
249
  doSomething();
258
- return <div>Hello World</div>
259
- }
250
+ return <div>Hello World</div>;
251
+ };
260
252
  ```
261
253
 
262
254
  ## 常见问题
@@ -331,4 +323,3 @@ export default function Test() {
331
323
  在浏览器端,这段代码不会造成任何问题,但是在 SSR 时,Middleware 实例会一直无法被销毁。每次渲染组件,调用 `epicMiddleware.run(rootEpic)` 时,都会在内部添加新的事件绑定,导致整个对象不断变大,最终对应用性能造成影响。
332
324
 
333
325
  CSR 中这类问题不易被发觉,因此从 CSR 切换到 SSR 时,如果不确定应用是否存在这类隐患,可以对应用进行压测。
334
-