@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
@@ -7,7 +7,7 @@ title: crossProject
7
7
  - **Type:** `boolean`
8
8
  - **Default:** `false`
9
9
 
10
- import EnableBFFCaution from "@site-docs-en/components/enable-bff-caution";
10
+ import EnableBFFCaution from '@site-docs-en/components/enable-bff-caution';
11
11
 
12
12
  <EnableBFFCaution />
13
13
 
@@ -21,4 +21,4 @@ export default defineConfig({
21
21
  });
22
22
  ```
23
23
 
24
- For detailed configuration and usage of BFF cross-project invocation, please refer to the [BFF Cross-Project Invocation Guide](/guides/advanced-features/bff/cross-project.html).
24
+ For detailed configuration and usage of BFF cross-project invocation, please refer to the [BFF Cross-Project Invocation Guide](/guides/advanced-features/bff/cross-project.html).
@@ -7,7 +7,7 @@ title: prefix
7
7
  - **Type:** `string`
8
8
  - **Default:** `/api`
9
9
 
10
- import EnableBFFCaution from "@site-docs-en/components/enable-bff-caution";
10
+ import EnableBFFCaution from '@site-docs-en/components/enable-bff-caution';
11
11
 
12
12
  <EnableBFFCaution />
13
13
 
@@ -33,10 +33,26 @@ type LazyCompilationOptions =
33
33
  };
34
34
  ```
35
35
 
36
- - **Default:** `false`
36
+ - **Default:** depends on how the application renders:
37
+ - Pure CSR and streaming SSR applications: `{ imports: true, entries: false }`, which compiles dynamic imports on demand;
38
+ - Applications using string SSR (including any entry in `server.ssrByEntries` using string SSR), RSC or SSG: `false`.
37
39
 
38
40
  Enable lazy compilation (compilation on demand), implemented based on Rspack's [lazy compilation](https://rspack.rs/guide/features/lazy-compilation) feature.
39
41
 
42
+ This option only takes effect in the dev server and does not affect production build output. When enabled for streaming SSR applications, route components are still compiled eagerly so that first-screen JS/CSS injection stays correct.
43
+
44
+ An explicitly configured `dev.lazyCompilation` always takes precedence over the default. To disable it:
45
+
46
+ ```ts
47
+ import { defineConfig } from '@modern-js/app-tools';
48
+
49
+ export default defineConfig({
50
+ dev: {
51
+ lazyCompilation: false,
52
+ },
53
+ });
54
+ ```
55
+
40
56
  import RsbuildLink from '@site/src/components/RsbuildLink';
41
57
 
42
58
  :::info
@@ -50,4 +50,3 @@ On MacOS, you can open the specified browser when Dev Server starts, by set envi
50
50
  - Brave Browser
51
51
  - Vivaldi
52
52
  - Chromium
53
-
@@ -17,11 +17,7 @@ type CssModules = {
17
17
  resourceFragment: string,
18
18
  ) => boolean);
19
19
  exportLocalsConvention?:
20
- | 'asIs'
21
- | 'camelCase'
22
- | 'camelCaseOnly'
23
- | 'dashes'
24
- | 'dashesOnly';
20
+ 'asIs' | 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly';
25
21
  exportGlobals?: boolean;
26
22
  localIdentName?: string;
27
23
  mode?:
@@ -4,7 +4,6 @@ title: distPath
4
4
 
5
5
  # output.distPath
6
6
 
7
-
8
7
  import CommentTips from '@site-docs/components/output-distpath-warning';
9
8
 
10
9
  <CommentTips />
@@ -8,8 +8,7 @@ title: inlineScripts
8
8
 
9
9
  ```ts
10
10
  type InlineScriptsTest =
11
- | RegExp
12
- | ((params: { size: number; name: string }) => boolean);
11
+ RegExp | ((params: { size: number; name: string }) => boolean);
13
12
 
14
13
  type InlineScripts =
15
14
  | boolean
@@ -8,8 +8,7 @@ title: inlineStyles
8
8
 
9
9
  ```ts
10
10
  type InlineStylesTest =
11
- | RegExp
12
- | ((params: { size: number; name: string }) => boolean);
11
+ RegExp | ((params: { size: number; name: string }) => boolean);
13
12
 
14
13
  type InlineStyles =
15
14
  | boolean
@@ -16,5 +16,5 @@ export default {
16
16
  output: {
17
17
  splitRouteChunks: false,
18
18
  },
19
- }
19
+ };
20
20
  ```
@@ -20,6 +20,7 @@ The SSG feature is closely related to routing. It is recommended to understand t
20
20
  :::
21
21
 
22
22
  :::info
23
+
23
24
  - Use `output.ssg` for single-entry apps.
24
25
  - For multi-entry apps, prefer `output.ssgByEntries`.
25
26
  - If `output.ssg` is `true` and `output.ssgByEntries` is not set, all routes under all entries are treated as SSG routes.
@@ -82,4 +83,3 @@ export default defineConfig({
82
83
  },
83
84
  });
84
85
  ```
85
-
@@ -10,6 +10,7 @@ title: ssgByEntries
10
10
  Configure SSG per entry for multi-entry applications.
11
11
 
12
12
  :::info
13
+
13
14
  - Use `output.ssg` for single-entry apps.
14
15
  - For multi-entry apps, prefer `output.ssgByEntries`.
15
16
  - If `output.ssg` is `true` and `output.ssgByEntries` is not set, all routes under all entries are treated as SSG routes.
@@ -14,10 +14,7 @@ type ForceSplitting = RegExp[] | Record<string, RegExp>;
14
14
 
15
15
  interface BaseChunkSplit {
16
16
  strategy?:
17
- | 'split-by-module'
18
- | 'split-by-experience'
19
- | 'all-in-one'
20
- | 'single-vendor';
17
+ 'split-by-module' | 'split-by-experience' | 'all-in-one' | 'single-vendor';
21
18
  override?: SplitChunks;
22
19
  forceSplitting?: ForceSplitting;
23
20
  }
@@ -50,9 +50,11 @@ import { defineRuntimeConfig } from '@modern-js/runtime';
50
50
  import { myPlugin } from './config/plugin/myPlugin';
51
51
 
52
52
  export default defineRuntimeConfig({
53
- plugins: [myPlugin({
54
- foo: 1,
55
- bar: 2,
56
- })],
53
+ plugins: [
54
+ myPlugin({
55
+ foo: 1,
56
+ bar: 2,
57
+ }),
58
+ ],
57
59
  });
58
60
  ```
@@ -21,10 +21,10 @@ export default defineConfig({
21
21
 
22
22
  :::tip Prerequisites
23
23
  Before enabling RSC, ensure:
24
+
24
25
  1. React and React DOM are upgraded to version 19 (recommended 19.2.4 or above)
25
26
  2. Install the `react-server-dom-rspack@0.0.2` dependency
26
27
 
27
28
  :::
28
29
 
29
30
  For more information about using RSC, see the [React Server Components guide](/guides/basic-features/render/rsc).
30
-
@@ -25,13 +25,12 @@ export default defineConfig({
25
25
 
26
26
  When the value type is `Object`, the following properties can be configured:
27
27
 
28
- | Name | Type | Default | Description |
29
- | ---------------- | ------------------------------------------------------------- | -------------------------------------- | ---------------------------------------------------------------------------- |
30
- | mode | `string` | `stream` | which defaults to using streaming rendering. Configure `string` to use `renderToString` for rendering |
31
- | forceCSR | `boolean` | `false` | which is off by default for forcing CSR rendering. Configure `true` to force CSR by adding `?csr=true` or adding `x-modern-ssr-fallback` header when accessing the page |
32
- | unsafeHeaders | `string[]` | `[]` | For safety reasons, Modern.js does not add excessive content to SSR_DATA. Developers can use this configuration to specify the headers that need to be injected |
33
- | loaderFailureMode| `clientRender \| errorBoundary` | `errorBoundary` | The default configuration is `'errorBoundary'`, when an error occurs in [data loader](/en/guides/basic-features/data/data-fetch.html#data-loader-recommended), it will default to rendering the [`Error`](/guides/basic-features/routes/routes#error-handling) component of the route. When configured as `'clientRender'`, if a loader throws an error, it switch to client-side rendering,you can use it with [Client Loader](/en/guides/basic-features/data/data-fetch.html#client-loader) |
34
-
28
+ | Name | Type | Default | Description |
29
+ | ----------------- | ------------------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
30
+ | mode | `string` | `stream` | which defaults to using streaming rendering. Configure `string` to use `renderToString` for rendering |
31
+ | forceCSR | `boolean` | `false` | which is off by default for forcing CSR rendering. Configure `true` to force CSR by adding `?csr=true` or adding `x-modern-ssr-fallback` header when accessing the page |
32
+ | unsafeHeaders | `string[]` | `[]` | For safety reasons, Modern.js does not add excessive content to SSR_DATA. Developers can use this configuration to specify the headers that need to be injected |
33
+ | loaderFailureMode | `clientRender \| errorBoundary` | `errorBoundary` | The default configuration is `'errorBoundary'`, when an error occurs in [data loader](/en/guides/basic-features/data/data-fetch.html#data-loader-recommended), it will default to rendering the [`Error`](/guides/basic-features/routes/routes#error-handling) component of the route. When configured as `'clientRender'`, if a loader throws an error, it switch to client-side rendering,you can use it with [Client Loader](/en/guides/basic-features/data/data-fetch.html#client-loader) |
35
34
 
36
35
  ```ts title="modern.config.ts"
37
36
  export default defineConfig({
@@ -39,7 +38,7 @@ export default defineConfig({
39
38
  ssr: {
40
39
  forceCSR: true,
41
40
  mode: 'stream',
42
- unsafeHeaders: ['User-Agent']
41
+ unsafeHeaders: ['User-Agent'],
43
42
  },
44
43
  },
45
44
  });
@@ -40,9 +40,9 @@ Add `<appDirectory>/tsconfig.server.json`:
40
40
  "types": ["node"],
41
41
  "esModuleInterop": true,
42
42
  "experimentalDecorators": true,
43
- "emitDecoratorMetadata": true
43
+ "emitDecoratorMetadata": true,
44
44
  },
45
- "include": ["api", "shared", "server", "config", "modern.config.ts"]
45
+ "include": ["api", "shared", "server", "config", "modern.config.ts"],
46
46
  }
47
47
  ```
48
48
 
@@ -21,12 +21,12 @@ const defaultOptions = {
21
21
 
22
22
  `tools.less` modifies the options of [@rsbuild/plugin-less](https://rsbuild.rs/plugins/list/plugin-less). It accepts the full plugin options:
23
23
 
24
- | Option | Description |
25
- | ------------------- | ---------------------------------------------------------------------------------------------- |
24
+ | Option | Description |
25
+ | ------------------- | --------------------------------------------------------------------------------------------------- |
26
26
  | `lessLoaderOptions` | Options passed to [less-loader](https://github.com/webpack-contrib/less-loader), object or function |
27
- | `include` | Files handled by less-loader, defaults to `/\.less$/` |
28
- | `exclude` | Files that less-loader should skip |
29
- | `parallel` | Whether to compile Less modules in worker threads, defaults to `false` |
27
+ | `include` | Files handled by less-loader, defaults to `/\.less$/` |
28
+ | `exclude` | Files that less-loader should skip |
29
+ | `parallel` | Whether to compile Less modules in worker threads, defaults to `false` |
30
30
 
31
31
  ### Modifying less-loader options
32
32
 
@@ -135,7 +135,6 @@ export default {
135
135
  As soon as an object contains a plugin-level key (`lessLoaderOptions`, `include`, `exclude`, ...), the whole object is parsed as plugin options and any loader option in it has no effect. For example, `lessOptions` in `tools.less: { parallel: true, lessOptions: { ... } }` is ignored and must be moved under `lessLoaderOptions`; a hint is printed in development.
136
136
  :::
137
137
 
138
-
139
138
  In earlier versions, `tools.less` took the less-loader options directly, e.g. `tools.less: { lessOptions: {} }` or `tools.less(config, { addExcludes }) {}`. This form still works: Modern.js wraps it into `lessLoaderOptions` and produces exactly the same config as before. A migration hint is printed in development, and the legacy form will be removed in the next major version.
140
139
 
141
140
  ```js
@@ -18,12 +18,12 @@ const defaultOptions = {
18
18
 
19
19
  `tools.sass` modifies the options of [@rsbuild/plugin-sass](https://rsbuild.rs/plugins/list/plugin-sass). It accepts the full plugin options:
20
20
 
21
- | Option | Description |
22
- | ------------------- | ---------------------------------------------------------------------------------------------- |
21
+ | Option | Description |
22
+ | ------------------- | --------------------------------------------------------------------------------------------------- |
23
23
  | `sassLoaderOptions` | Options passed to [sass-loader](https://github.com/webpack-contrib/sass-loader), object or function |
24
- | `include` | Files handled by sass-loader, defaults to `/\.s(?:a|c)ss$/` |
25
- | `exclude` | Files that sass-loader should skip |
26
- | `rewriteUrls` | Whether to rewrite relative URLs in Sass files with resolve-url-loader, defaults to `true` |
24
+ | `include` | Files handled by sass-loader, defaults to `/\.s(?:a\|c)ss$/` |
25
+ | `exclude` | Files that sass-loader should skip |
26
+ | `rewriteUrls` | Whether to rewrite relative URLs in Sass files with resolve-url-loader, defaults to `true` |
27
27
 
28
28
  ### Modifying sass-loader options
29
29
 
@@ -126,7 +126,6 @@ export default {
126
126
  As soon as an object contains a plugin-level key (`sassLoaderOptions`, `include`, `exclude`, ...), the whole object is parsed as plugin options and any loader option in it has no effect. For example, `sassOptions` in `tools.sass: { rewriteUrls: false, sassOptions: { ... } }` is ignored and must be moved under `sassLoaderOptions`; a hint is printed in development.
127
127
  :::
128
128
 
129
-
130
129
  In earlier versions, `tools.sass` took the sass-loader options directly, e.g. `tools.sass: { sassOptions: {} }` or `tools.sass(config, { addExcludes }) {}`. This form still works: Modern.js wraps it into `sassLoaderOptions` and produces exactly the same config as before. A migration hint is printed in development, and the legacy form will be removed in the next major version.
131
130
 
132
131
  ```js
@@ -18,14 +18,14 @@ const defaultOptions = {
18
18
 
19
19
  `tools.svgr` modifies the options of [@rsbuild/plugin-svgr](https://rsbuild.rs/plugins/list/plugin-svgr). It accepts the full plugin options. Set it to `false` to skip registering the SVGR plugin; all `.svg` files are then treated as static assets.
20
20
 
21
- | Option | Description |
22
- | ----------------- | ---------------------------------------------------------------------------------------------------- |
21
+ | Option | Description |
22
+ | ----------------- | ---------------------------------------------------------------------------------------------------------- |
23
23
  | `svgrOptions` | Options passed to [SVGR](https://react-svgr.com/docs/options/), such as `exportType`, `icon`, `svgoConfig` |
24
- | `parallel` | Whether to transform SVG files in worker threads, defaults to `false` |
25
- | `exclude` | SVG files that SVGR should skip |
26
- | `excludeImporter` | Importer files whose SVG imports should skip SVGR |
27
- | `query` | Query that triggers the SVGR transform, defaults to `/react/` |
28
- | `mixedImport` | Whether a module may import both the URL and the React component, defaults to `true` |
24
+ | `parallel` | Whether to transform SVG files in worker threads, defaults to `false` |
25
+ | `exclude` | SVG files that SVGR should skip |
26
+ | `excludeImporter` | Importer files whose SVG imports should skip SVGR |
27
+ | `query` | Query that triggers the SVGR transform, defaults to `/react/` |
28
+ | `mixedImport` | Whether a module may import both the URL and the React component, defaults to `true` |
29
29
 
30
30
  ### Merge rules
31
31
 
@@ -265,11 +265,7 @@ import { defineConfig } from '@modern-js/app-tools';
265
265
  import { xxPlugin } from '@modern-js/plugin-xx';
266
266
 
267
267
  export default defineConfig({
268
- plugins: [
269
- xxPlugin({
270
- /** Add parameters here */
271
- }),
272
- ],
268
+ plugins: [xxPlugin({/** Add parameters here */})],
273
269
  });
274
270
  ```
275
271
 
@@ -9,6 +9,7 @@ Cross-project invocation consists of **producer** and **consumer** sides. The pr
9
9
 
10
10
  Enable cross-project invocation via configuration. Projects with BFF capabilities enabled can act as BFF producers, or you can create standalone BFF applications.
11
11
  When executing `dev` or `build`, the following artifacts for consumers will be automatically generated:
12
+
12
13
  - API functions under the `dist/client` directory
13
14
  - Runtime configuration functions under the `dist/runtime` directory
14
15
  - Interface exports defined in `exports` field of `package.json`
@@ -24,7 +25,7 @@ Ensure the current project has BFF enabled with API files defined under `api/lam
24
25
  export default defineConfig({
25
26
  bff: {
26
27
  crossProject: true,
27
- }
28
+ },
28
29
  });
29
30
  ```
30
31
 
@@ -88,9 +89,9 @@ import { configure as innerConfigure } from '@modern-js/plugin-bff/client';
88
89
  import axios from 'axios';
89
90
 
90
91
  configure({
91
- setDomain() {
92
- return 'https://your-bff-api.com';
93
- },
92
+ setDomain() {
93
+ return 'https://your-bff-api.com';
94
+ },
94
95
  });
95
96
 
96
97
  innerConfigure({
@@ -18,7 +18,6 @@ import DefaultBrowserslist from '@site-docs/components/default-browserslist';
18
18
 
19
19
  <DefaultBrowserslist />
20
20
 
21
-
22
21
  When the `overrideBrowserslist` configuration is not specified in the project, this `.browserslistrc` file will take effect.
23
22
 
24
23
  ### Method 2: Configure via package.json
@@ -68,7 +68,7 @@ i18nPlugin({
68
68
  localeDetectionByEntry: {
69
69
  admin: {
70
70
  localePathRedirect: false, // admin does not use path prefixes
71
- languages: ['en'], // admin only supports English
71
+ languages: ['en'], // admin only supports English
72
72
  },
73
73
  mobile: {
74
74
  languages: ['zh', 'en', 'ja'], // mobile supports more languages
@@ -10,14 +10,14 @@ title: API Reference
10
10
 
11
11
  ### Return Value
12
12
 
13
- | Field | Type | Description |
14
- | --- | --- | --- |
15
- | `language` | `string` | Current language code |
16
- | `changeLanguage` | `(lang: string) => Promise<void>` | Switches language |
17
- | `supportedLanguages` | `string[]` | Supported language list, from `localeDetection.languages` |
18
- | `isLanguageSupported` | `(lang: string) => boolean` | Checks whether a language is in the supported list |
19
- | `isResourcesReady` | `boolean` | Whether translation resources for the current language have finished loading |
20
- | `i18nInstance` | `I18nInstance` | i18next instance for advanced scenarios |
13
+ | Field | Type | Description |
14
+ | --------------------- | --------------------------------- | ---------------------------------------------------------------------------- |
15
+ | `language` | `string` | Current language code |
16
+ | `changeLanguage` | `(lang: string) => Promise<void>` | Switches language |
17
+ | `supportedLanguages` | `string[]` | Supported language list, from `localeDetection.languages` |
18
+ | `isLanguageSupported` | `(lang: string) => boolean` | Checks whether a language is in the supported list |
19
+ | `isResourcesReady` | `boolean` | Whether translation resources for the current language have finished loading |
20
+ | `i18nInstance` | `I18nInstance` | i18next instance for advanced scenarios |
21
21
 
22
22
  ### Basic Usage
23
23
 
@@ -85,13 +85,13 @@ A route link component with a locale prefix.
85
85
 
86
86
  ### Props
87
87
 
88
- | Prop | Type | Required | Description |
89
- | --- | --- | --- | --- |
90
- | `to` | `string` | Yes | Target path. Do not include the locale prefix |
91
- | `children` | `React.ReactNode` | Yes | Link content |
92
- | `replace` | `boolean` | No | Uses `history.replace` instead of `push` |
93
- | `state` | `any` | No | State passed to the target route |
94
- | Other Link props | - | No | Inherited from the `Link` component in `@modern-js/runtime/router` |
88
+ | Prop | Type | Required | Description |
89
+ | ---------------- | ----------------- | -------- | ------------------------------------------------------------------ |
90
+ | `to` | `string` | Yes | Target path. Do not include the locale prefix |
91
+ | `children` | `React.ReactNode` | Yes | Link content |
92
+ | `replace` | `boolean` | No | Uses `history.replace` instead of `push` |
93
+ | `state` | `any` | No | State passed to the target route |
94
+ | Other Link props | - | No | Inherited from the `Link` component in `@modern-js/runtime/router` |
95
95
 
96
96
  ### Usage
97
97
 
@@ -166,11 +166,11 @@ Type of the custom backend loader function:
166
166
  type I18nSdkLoader = (options: I18nSdkLoadOptions) => Promise<Resources>;
167
167
 
168
168
  interface I18nSdkLoadOptions {
169
- lng?: string; // Single language code
170
- ns?: string; // Single namespace
171
- lngs?: string[]; // Multiple language codes
172
- nss?: string[]; // Multiple namespaces
173
- all?: boolean; // Load all resources
169
+ lng?: string; // Single language code
170
+ ns?: string; // Single namespace
171
+ lngs?: string[]; // Multiple language codes
172
+ nss?: string[]; // Multiple namespaces
173
+ all?: boolean; // Load all resources
174
174
  }
175
175
 
176
176
  type Resources = {
@@ -185,14 +185,14 @@ type Resources = {
185
185
  ```ts
186
186
  interface LanguageDetectorOptions {
187
187
  order?: string[];
188
- lookupQuerystring?: string; // Default: 'lng'
189
- lookupCookie?: string; // Default: 'i18next'
190
- lookupLocalStorage?: string; // Default: 'i18nextLng'
188
+ lookupQuerystring?: string; // Default: 'lng'
189
+ lookupCookie?: string; // Default: 'i18next'
190
+ lookupLocalStorage?: string; // Default: 'i18nextLng'
191
191
  lookupSession?: string;
192
- lookupHeader?: string; // Default: 'accept-language'
192
+ lookupHeader?: string; // Default: 'accept-language'
193
193
  lookupFromPathIndex?: number; // Default: 0
194
194
  caches?: false | string[];
195
- cookieMinutes?: number; // Default: 525600 (1 year)
195
+ cookieMinutes?: number; // Default: 525600 (1 year)
196
196
  cookieExpirationDate?: Date;
197
197
  cookieDomain?: string;
198
198
  }
@@ -212,8 +212,8 @@ import { useTranslation } from 'react-i18next';
212
212
  import { useModernI18n } from '@modern-js/plugin-i18n/runtime';
213
213
 
214
214
  function App() {
215
- const { t } = useTranslation(); // Translate text
216
- const { language, changeLanguage } = useModernI18n(); // Switch language
215
+ const { t } = useTranslation(); // Translate text
216
+ const { language, changeLanguage } = useModernI18n(); // Switch language
217
217
 
218
218
  return (
219
219
  <div>
@@ -231,5 +231,11 @@ You can also get the i18next instance from `useModernI18n` and call capabilities
231
231
  const { i18nInstance } = useModernI18n();
232
232
 
233
233
  // Dynamically add translation resources.
234
- i18nInstance.addResourceBundle('zh', 'translation', { key: 'Value' }, true, true);
234
+ i18nInstance.addResourceBundle(
235
+ 'zh',
236
+ 'translation',
237
+ { key: 'Value' },
238
+ true,
239
+ true,
240
+ );
235
241
  ```
@@ -63,8 +63,8 @@ function ButtonGroup() {
63
63
  const { t } = useTranslation('common', { keyPrefix: 'button' });
64
64
  return (
65
65
  <>
66
- <button>{t('submit')}</button> {/* common:button.submit */}
67
- <button>{t('cancel')}</button> {/* common:button.cancel */}
66
+ <button>{t('submit')}</button> {/* common:button.submit */}
67
+ <button>{t('cancel')}</button> {/* common:button.cancel */}
68
68
  </>
69
69
  );
70
70
  }
@@ -94,9 +94,9 @@ The quality of translation key names directly affects maintenance cost. Recommen
94
94
  ```
95
95
 
96
96
  ```tsx
97
- t('page.title')
98
- t('form.username.label')
99
- t('form.submit', { defaultValue: 'Save' }) // defaultValue prevents showing the key string when the key is missing.
97
+ t('page.title');
98
+ t('form.username.label');
99
+ t('form.submit', { defaultValue: 'Save' }); // defaultValue prevents showing the key string when the key is missing.
100
100
  ```
101
101
 
102
102
  ## Plurals
@@ -121,9 +121,9 @@ i18next automatically selects the correct plural form based on the `count` param
121
121
  ```
122
122
 
123
123
  ```tsx
124
- t('item', { count: 0 }) // "没有条目" / "No items"
125
- t('item', { count: 1 }) // "没有条目" / "1 item" (Chinese usually has only one form)
126
- t('item', { count: 5 }) // "5 个条目" / "5 items"
124
+ t('item', { count: 0 }); // "没有条目" / "No items"
125
+ t('item', { count: 1 }); // "没有条目" / "1 item" (Chinese usually has only one form)
126
+ t('item', { count: 5 }); // "5 个条目" / "5 items"
127
127
  ```
128
128
 
129
129
  Different languages have different plural rules. English has singular and plural, while Russian has one/few/many forms. i18next automatically matches CLDR rules based on the language code.
@@ -152,8 +152,8 @@ Nested structures can clearly reflect UI hierarchy and are accessed with dots:
152
152
  ```
153
153
 
154
154
  ```tsx
155
- t('modal.confirm.title')
156
- t('modal.confirm.actions.ok')
155
+ t('modal.confirm.title');
156
+ t('modal.confirm.actions.ok');
157
157
  ```
158
158
 
159
159
  Avoid nesting deeper than 4 levels. Excessive depth makes key names long and hard to maintain.
@@ -199,8 +199,8 @@ Use `, format` in translation files to specify the formatting type:
199
199
  ```
200
200
 
201
201
  ```tsx
202
- t('price', { value: 99.5 }) // "当前价格:¥99.50" (zh) / "$99.50" (en)
203
- t('expiry', { date: new Date() }) // "到期日:2025年5月12日" (zh)
202
+ t('price', { value: 99.5 }); // "当前价格:¥99.50" (zh) / "$99.50" (en)
203
+ t('expiry', { date: new Date() }); // "到期日:2025年5月12日" (zh)
204
204
  ```
205
205
 
206
206
  ## Error Handling
@@ -237,7 +237,7 @@ if (!i18n.isInitialized) return null;
237
237
  Provide fallback text with `defaultValue` to prevent key strings from appearing in the UI:
238
238
 
239
239
  ```tsx
240
- t('missing.key', { defaultValue: 'Default text' })
240
+ t('missing.key', { defaultValue: 'Default text' });
241
241
  ```
242
242
 
243
243
  In development, you can enable `saveMissing` to output missing keys to the console for debugging:
@@ -281,8 +281,8 @@ Referencing JSON file types directly is less likely to drift from actual transla
281
281
 
282
282
  ```tsx
283
283
  const { t } = useTranslation();
284
- t('welcome'); // TypeScript autocomplete
285
- t('nonExistent'); // TypeScript error
284
+ t('welcome'); // TypeScript autocomplete
285
+ t('nonExistent'); // TypeScript error
286
286
  ```
287
287
 
288
288
  :::tip Large projects