@modern-js/main-doc 2.61.0 → 2.62.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.
@@ -11,6 +11,7 @@ Transform the import path, which can be used to modularly import the subpath of
11
11
 
12
12
  ```ts
13
13
  type TransformImport =
14
+ | false
14
15
  | Array<{
15
16
  libraryName: string;
16
17
  libraryDirectory?: string;
@@ -61,3 +62,29 @@ When you add configurations for `antd` or `@arco-design/web-react`, the priority
61
62
  import RsbuildConig from '@site-docs-en/components/rsbuild-config-tooltip';
62
63
 
63
64
  <RsbuildConig />
65
+
66
+ ### Disable Default Config
67
+
68
+ You can manually set `transformImport: false` to disable the default config.
69
+
70
+ ```js
71
+ export default {
72
+ source: {
73
+ transformImport: false,
74
+ },
75
+ };
76
+ ```
77
+
78
+ You can also use the [function usage](https://rsbuild.dev/config/source/transform-import#function-type) of `transformImport` to modify the default configuration.
79
+
80
+ ```js
81
+ export default {
82
+ source: {
83
+ transformImport: (imports) => {
84
+ return imports.filter(data => data.libraryName !== 'antd');
85
+ },
86
+ },
87
+ };
88
+ ```
89
+
90
+ For example, if you use `externals` to avoid bundling antd, because `transformImport` will convert the imported path of antd by default, the matching path changes and externals cannot take effect. At this time, you can disable `transformImport` to avoid this problem.
@@ -113,7 +113,29 @@ If a Client Loader is defined for the route, it will be used to re-fetch the dat
113
113
 
114
114
  ### Component Rendering Error
115
115
 
116
- If a component throws an error during rendering, Modern.js automatically falls back to CSR mode and re-fetches the data. If re-rendering fails again, the `<ErrorBoundary>` component will be displayed.
116
+ If the Data Loader executes correctly but the component rendering fails, SSR rendering will partially or completely fail, as shown in the following code:
117
+
118
+ ```tsx
119
+ import { Await, useLoaderData } from '@modern-js/runtime/router';
120
+ import { Suspense } from 'react';
121
+
122
+ const Page = () => {
123
+ const data = useLoaderData();
124
+ const isNode = typeof window === 'undefined';
125
+ const undefinedVars = data.unDefined;
126
+ const definedVars = data.defined;
127
+
128
+ return (
129
+ <div>
130
+ {isNode ? undefinedVars.msg : definedVars.msg}
131
+ </div>
132
+ );
133
+ };
134
+
135
+ export default Page;
136
+ ```
137
+
138
+ In this case, Modern.js will fallback the page to CSR and use the existing data from the Data Loader to render. If the rendering still fails, the `<ErrorBoundary>` component will be rendered.
117
139
 
118
140
  :::tip
119
141
  The behavior of component rendering errors is unaffected by `loaderFailureMode` and will not execute the Client Loader on the browser side.
@@ -12,7 +12,7 @@ In this document, you can learn about the main technology stack involved in the
12
12
 
13
13
  Modern.js uses [React 18](https://react.dev/) to build user interfaces and is also compatible with React 17.
14
14
 
15
- Rsbuild supports building Vue applications. If you need to use Vue, you can refer to ["Rsbuild - Vue"](https://rsbuild.dev/guide/framework/vue3).
15
+ Rsbuild supports building Vue applications. If you need to use Vue, you can refer to ["Rsbuild - Vue"](https://rsbuild.dev/guide/framework/vue).
16
16
 
17
17
  ## Routing
18
18
 
@@ -11,6 +11,7 @@ configName: source.transformImport
11
11
 
12
12
  ```ts
13
13
  type TransformImport =
14
+ | false
14
15
  | Array<{
15
16
  libraryName: string;
16
17
  libraryDirectory?: string;
@@ -61,3 +62,29 @@ const defaultArcoConfig = [
61
62
  import RsbuildConig from '@site-docs/components/rsbuild-config-tooltip';
62
63
 
63
64
  <RsbuildConig />
65
+
66
+ ### 禁用默认配置
67
+
68
+ 你可以手动设置 `transformImport: false` 来关掉 transformImport 的默认行为。
69
+
70
+ ```js
71
+ export default {
72
+ source: {
73
+ transformImport: false,
74
+ },
75
+ };
76
+ ```
77
+
78
+ 你也可以使用 `transformImport` 的 [function 用法](https://rsbuild.dev/zh/config/source/transform-import#function-%E7%B1%BB%E5%9E%8B) 对默认配置进行自定义修改。
79
+
80
+ ```js
81
+ export default {
82
+ source: {
83
+ transformImport: (imports) => {
84
+ return imports.filter(data => data.libraryName !== 'antd');
85
+ },
86
+ },
87
+ };
88
+ ```
89
+
90
+ 比如,当你使用了 `externals` 来避免打包 antd 时,由于 `transformImport` 默认会转换 antd 的引用路径,导致匹配的路径发生了变化,因此 externals 无法正确生效,此时你可以设置关闭 `transformImport` 来避免该问题。
@@ -118,7 +118,29 @@ Modern.js 也支持通过 [`server.ssr`](/configure/app/server/ssr) 配置项中
118
118
 
119
119
  ### 组件渲染报错
120
120
 
121
- 当组件渲染报错时,Modern.js 会自动降级到 CSR 模式,并重新发起数据请求。如果重新渲染仍然出错,则展示 `<ErrorBoundary>` 组件。
121
+ 如果 Data Loader 执行正常,但组件渲染报错时,SSR 渲染将会部分或完全失败,例如以下代码:
122
+
123
+ ```tsx
124
+ import { Await, useLoaderData } from '@modern-js/runtime/router';
125
+ import { Suspense } from 'react';
126
+
127
+ const Page = () => {
128
+ const data = useLoaderData();
129
+ const isNode = typeof window === 'undefined';
130
+ const undefinedVars = data.unDefined;
131
+ const definedVars = data.defined;
132
+
133
+ return (
134
+ <div>
135
+ {isNode ? undefinedVars.msg : definedVars.msg}
136
+ </div>
137
+ );
138
+ };
139
+
140
+ export default Page;
141
+ ```
142
+
143
+ 此时,Modern.js 会将页面降级为 CSR,并利用 Data Loader 中已有的数据渲染。如果重新渲染仍然出错,则展示 `<ErrorBoundary>` 组件。
122
144
 
123
145
  :::tip
124
146
  组件渲染报错的行为,不会受到 `loaderFailureMode` 的影响,也不会在浏览器端执行 Client Loader。
@@ -12,7 +12,7 @@ Modern.js 框架默认集成了一些社区中流行的库和开发工具。
12
12
 
13
13
  Modern.js 使用 [React 18](https://react.dev/) 来构建用户界面,同时也兼容 React 17。
14
14
 
15
- Modern.js 底层的 Rsbuild 支持构建 Vue 应用,如果你需要使用 Vue,可以参考 [Rsbuild - Vue](https://rsbuild.dev/zh/guide/framework/vue3)。
15
+ Modern.js 底层的 Rsbuild 支持构建 Vue 应用,如果你需要使用 Vue,可以参考 [Rsbuild - Vue](https://rsbuild.dev/zh/guide/framework/vue)。
16
16
 
17
17
  ## 路由
18
18
 
package/package.json CHANGED
@@ -15,17 +15,17 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.61.0",
18
+ "version": "2.62.1",
19
19
  "publishConfig": {
20
20
  "registry": "https://registry.npmjs.org/",
21
21
  "access": "public",
22
22
  "provenance": true
23
23
  },
24
24
  "dependencies": {
25
- "@modern-js/sandpack-react": "2.61.0"
25
+ "@modern-js/sandpack-react": "2.62.1"
26
26
  },
27
27
  "devDependencies": {
28
- "@rspress/shared": "1.35.3",
28
+ "@rspress/shared": "1.35.4",
29
29
  "@types/fs-extra": "9.0.13",
30
30
  "@types/node": "^16",
31
31
  "classnames": "^2",
@@ -33,7 +33,7 @@
33
33
  "fs-extra": "^10",
34
34
  "react": "^18.3.1",
35
35
  "react-dom": "^18.3.1",
36
- "rspress": "1.35.3",
36
+ "rspress": "1.35.4",
37
37
  "ts-node": "^10.9.1",
38
38
  "typescript": "^5"
39
39
  },