@modern-js/main-doc 3.9.2 → 3.10.0
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.
- package/docs/en/apis/app/hooks/api/lambda.mdx +2 -1
- package/docs/en/apis/app/hooks/config/html.mdx +1 -0
- package/docs/en/apis/app/hooks/config/mock.mdx +1 -0
- package/docs/en/apis/app/hooks/config/public.mdx +1 -0
- package/docs/en/apis/app/hooks/config/upload.mdx +2 -3
- package/docs/en/apis/app/hooks/modern-config.mdx +1 -0
- package/docs/en/apis/app/hooks/shared.mdx +1 -0
- package/docs/en/apis/app/hooks/src/modern.runtime.mdx +1 -0
- package/docs/en/apis/app/hooks/src/routes.mdx +1 -0
- package/docs/en/apis/app/hooks/src/server.mdx +2 -1
- package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +1 -0
- package/docs/en/apis/app/runtime/core/create-root.mdx +4 -1
- package/docs/en/apis/app/runtime/core/render.mdx +6 -2
- package/docs/en/apis/app/runtime/core/runtime-context.mdx +17 -17
- package/docs/en/apis/app/runtime/router/router.mdx +9 -6
- package/docs/en/apis/app/runtime/ssr/no-ssr.mdx +1 -0
- package/docs/en/apis/app/runtime/utility/head.mdx +1 -0
- package/docs/en/apis/app/runtime/utility/loadable.mdx +1 -0
- package/docs/en/community/blog/v3-release-note.mdx +36 -27
- package/docs/en/community/contributing-guide.mdx +15 -33
- package/docs/en/components/default-browserslist.mdx +0 -1
- package/docs/en/components/deploy-command.mdx +1 -1
- package/docs/en/components/deploy.mdx +1 -1
- package/docs/en/components/entry-scan-logic.mdx +1 -1
- package/docs/en/components/init-app.mdx +9 -3
- package/docs/en/components/international/custom-instance-code.mdx +0 -1
- package/docs/en/components/micro-runtime-config.mdx +12 -9
- package/docs/en/components/nodeVersion.mdx +2 -2
- package/docs/en/components/rsc-deploy-tip.mdx +0 -1
- package/docs/en/components/ssr-monitor.mdx +1 -1
- package/docs/en/configure/app/bff/cross-project.mdx +2 -2
- package/docs/en/configure/app/bff/prefix.mdx +1 -1
- package/docs/en/configure/app/dev/lazy-compilation.mdx +17 -1
- package/docs/en/configure/app/dev/start-url.mdx +0 -1
- package/docs/en/configure/app/output/css-modules.mdx +1 -5
- package/docs/en/configure/app/output/disable-svgr.mdx +4 -0
- package/docs/en/configure/app/output/dist-path.mdx +0 -1
- package/docs/en/configure/app/output/inline-scripts.mdx +1 -2
- package/docs/en/configure/app/output/inline-styles.mdx +1 -2
- package/docs/en/configure/app/output/split-route-chunks.mdx +1 -1
- package/docs/en/configure/app/output/ssg.mdx +1 -1
- package/docs/en/configure/app/output/ssgByEntries.mdx +1 -0
- package/docs/en/configure/app/output/svg-default-export.mdx +4 -0
- package/docs/en/configure/app/performance/chunk-split.mdx +1 -4
- package/docs/en/configure/app/runtime/plugins.mdx +6 -4
- package/docs/en/configure/app/server/rsc.mdx +1 -1
- package/docs/en/configure/app/server/ssr.mdx +7 -8
- package/docs/en/configure/app/server/tsconfig-path.mdx +2 -2
- package/docs/en/configure/app/tools/less.mdx +94 -19
- package/docs/en/configure/app/tools/sass.mdx +87 -18
- package/docs/en/configure/app/tools/svgr.mdx +93 -0
- package/docs/en/configure/app/usage.mdx +1 -5
- package/docs/en/guides/advanced-features/bff/cross-project.mdx +5 -4
- package/docs/en/guides/advanced-features/compatibility.mdx +0 -1
- package/docs/en/guides/advanced-features/international/advanced.mdx +1 -1
- package/docs/en/guides/advanced-features/international/api.mdx +34 -28
- package/docs/en/guides/advanced-features/international/best-practices.mdx +15 -15
- package/docs/en/guides/advanced-features/international/configuration.mdx +37 -37
- package/docs/en/guides/advanced-features/international/locale-detection.mdx +37 -28
- package/docs/en/guides/advanced-features/international/resource-loading.mdx +19 -17
- package/docs/en/guides/advanced-features/international/routing.mdx +8 -6
- package/docs/en/guides/advanced-features/international.mdx +8 -8
- package/docs/en/guides/advanced-features/server-monitor/logger.mdx +5 -5
- package/docs/en/guides/advanced-features/server-monitor/metrics.mdx +8 -8
- package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +1 -3
- package/docs/en/guides/advanced-features/source-build.mdx +1 -1
- package/docs/en/guides/advanced-features/web-server.mdx +3 -3
- package/docs/en/guides/basic-features/data/data-fetch.mdx +1 -3
- package/docs/en/guides/basic-features/data/data-write.mdx +24 -28
- package/docs/en/guides/basic-features/debug/mock.mdx +2 -2
- package/docs/en/guides/basic-features/debug/using-storybook.mdx +5 -6
- package/docs/en/guides/basic-features/html.mdx +2 -3
- package/docs/en/guides/basic-features/output-files.mdx +1 -1
- package/docs/en/guides/basic-features/render/overview.mdx +12 -12
- package/docs/en/guides/basic-features/render/rsc.mdx +16 -9
- package/docs/en/guides/basic-features/render/ssr-cache.mdx +5 -5
- package/docs/en/guides/basic-features/render/ssr.mdx +8 -12
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +2 -1
- package/docs/en/guides/basic-features/routes/config-routes.mdx +60 -59
- package/docs/en/guides/basic-features/static-assets/svg-assets.mdx +29 -17
- package/docs/en/guides/basic-features/testing/playwright.mdx +14 -8
- package/docs/en/guides/basic-features/testing/rstest.mdx +6 -4
- package/docs/en/guides/get-started/ai-coding-agents.mdx +6 -6
- package/docs/en/guides/get-started/introduction.mdx +0 -1
- package/docs/en/guides/topic-detail/module-federation/deploy.mdx +2 -2
- package/docs/en/guides/topic-detail/module-federation/introduce.mdx +0 -1
- package/docs/en/guides/upgrade/config.mdx +12 -0
- package/docs/en/guides/upgrade/other.mdx +4 -4
- package/docs/en/guides/upgrade/tailwindcss.mdx +0 -1
- package/docs/en/guides/upgrade/web-server.md +34 -17
- package/docs/en/index.md +1 -0
- package/docs/en/plugin/cli-plugins/api.mdx +23 -23
- package/docs/en/plugin/cli-plugins/life-cycle.mdx +2 -0
- package/docs/en/plugin/introduction.mdx +6 -6
- package/docs/en/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
- package/docs/en/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
- package/docs/en/plugin/plugin-system.mdx +19 -26
- package/docs/en/plugin/runtime-plugins/life-cycle.mdx +2 -0
- package/docs/en/plugin/server-plugins/api.mdx +11 -14
- package/docs/en/plugin/server-plugins/life-cycle.mdx +2 -0
- package/docs/zh/apis/app/hooks/api/lambda.mdx +1 -1
- package/docs/zh/apis/app/hooks/config/html.mdx +1 -0
- package/docs/zh/apis/app/hooks/config/mock.mdx +1 -0
- package/docs/zh/apis/app/hooks/config/public.mdx +1 -0
- package/docs/zh/apis/app/hooks/config/upload.mdx +2 -3
- package/docs/zh/apis/app/hooks/modern-config.mdx +1 -0
- package/docs/zh/apis/app/hooks/shared.mdx +1 -0
- package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +1 -0
- package/docs/zh/apis/app/hooks/src/routes.mdx +1 -0
- package/docs/zh/apis/app/hooks/src/server.mdx +2 -1
- package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +1 -1
- package/docs/zh/apis/app/runtime/core/create-root.mdx +4 -1
- package/docs/zh/apis/app/runtime/core/render.mdx +6 -3
- package/docs/zh/apis/app/runtime/core/runtime-context.mdx +17 -17
- package/docs/zh/apis/app/runtime/router/router.mdx +10 -6
- package/docs/zh/apis/app/runtime/ssr/no-ssr.mdx +1 -0
- package/docs/zh/apis/app/runtime/utility/head.mdx +1 -0
- package/docs/zh/apis/app/runtime/utility/loadable.mdx +1 -0
- package/docs/zh/community/blog/v3-release-note.mdx +38 -29
- package/docs/zh/community/contributing-guide.mdx +16 -34
- package/docs/zh/components/default-browserslist.mdx +0 -1
- package/docs/zh/components/deploy-command.mdx +1 -1
- package/docs/zh/components/deploy.mdx +1 -1
- package/docs/zh/components/entry-scan-logic.mdx +1 -1
- package/docs/zh/components/init-app.mdx +9 -3
- package/docs/zh/components/international/custom-instance-code.mdx +0 -1
- package/docs/zh/components/international/install-command.mdx +0 -1
- package/docs/zh/components/micro-runtime-config.mdx +12 -9
- package/docs/zh/components/nodeVersion.mdx +2 -2
- package/docs/zh/components/rsc-deploy-tip.mdx +0 -1
- package/docs/zh/components/ssr-monitor.mdx +1 -1
- package/docs/zh/configure/app/bff/cross-project.mdx +2 -2
- package/docs/zh/configure/app/bff/prefix.mdx +1 -1
- package/docs/zh/configure/app/dev/lazy-compilation.mdx +17 -1
- package/docs/zh/configure/app/html/crossorigin.mdx +0 -1
- package/docs/zh/configure/app/html/favicon.mdx +0 -1
- package/docs/zh/configure/app/output/convert-to-rem.mdx +0 -1
- package/docs/zh/configure/app/output/css-modules.mdx +1 -5
- package/docs/zh/configure/app/output/disable-svgr.mdx +4 -0
- package/docs/zh/configure/app/output/inline-scripts.mdx +1 -2
- package/docs/zh/configure/app/output/inline-styles.mdx +1 -2
- package/docs/zh/configure/app/output/source-map.mdx +0 -2
- package/docs/zh/configure/app/output/split-route-chunks.mdx +1 -1
- package/docs/zh/configure/app/output/ssg.mdx +1 -0
- package/docs/zh/configure/app/output/ssgByEntries.mdx +1 -1
- package/docs/zh/configure/app/output/svg-default-export.mdx +4 -0
- package/docs/zh/configure/app/performance/chunk-split.mdx +1 -4
- package/docs/zh/configure/app/resolve/dedupe.mdx +0 -1
- package/docs/zh/configure/app/runtime/plugins.mdx +6 -4
- package/docs/zh/configure/app/server/rsc.mdx +1 -1
- package/docs/zh/configure/app/server/ssr.mdx +6 -7
- package/docs/zh/configure/app/server/tsconfig-path.mdx +2 -2
- package/docs/zh/configure/app/tools/less.mdx +93 -19
- package/docs/zh/configure/app/tools/sass.mdx +87 -16
- package/docs/zh/configure/app/tools/svgr.mdx +93 -0
- package/docs/zh/configure/app/usage.mdx +1 -5
- package/docs/zh/guides/advanced-features/bff.mdx +1 -0
- package/docs/zh/guides/advanced-features/international/advanced.mdx +1 -1
- package/docs/zh/guides/advanced-features/international/api.mdx +28 -27
- package/docs/zh/guides/advanced-features/international/best-practices.mdx +15 -15
- package/docs/zh/guides/advanced-features/international/configuration.mdx +38 -36
- package/docs/zh/guides/advanced-features/international/locale-detection.mdx +37 -28
- package/docs/zh/guides/advanced-features/international/resource-loading.mdx +20 -16
- package/docs/zh/guides/advanced-features/international/routing.mdx +6 -4
- package/docs/zh/guides/advanced-features/international.mdx +9 -9
- package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +4 -6
- package/docs/zh/guides/advanced-features/server-monitor/metrics.mdx +9 -10
- package/docs/zh/guides/advanced-features/source-build.mdx +1 -1
- package/docs/zh/guides/advanced-features/web-server.mdx +3 -3
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +1 -3
- package/docs/zh/guides/basic-features/data/data-write.mdx +25 -31
- package/docs/zh/guides/basic-features/debug/mock.mdx +2 -2
- package/docs/zh/guides/basic-features/debug/using-storybook.mdx +5 -5
- package/docs/zh/guides/basic-features/env-vars.mdx +0 -1
- package/docs/zh/guides/basic-features/html.mdx +2 -3
- package/docs/zh/guides/basic-features/render/overview.mdx +12 -13
- package/docs/zh/guides/basic-features/render/rsc.mdx +16 -9
- package/docs/zh/guides/basic-features/render/ssr.mdx +8 -17
- package/docs/zh/guides/basic-features/routes/config-routes.mdx +61 -59
- package/docs/zh/guides/basic-features/static-assets/svg-assets.mdx +29 -17
- package/docs/zh/guides/basic-features/testing/playwright.mdx +15 -10
- package/docs/zh/guides/basic-features/testing/rstest.mdx +6 -4
- package/docs/zh/guides/get-started/ai-coding-agents.mdx +7 -7
- package/docs/zh/guides/topic-detail/module-federation/deploy.mdx +2 -2
- package/docs/zh/guides/upgrade/config.mdx +12 -0
- package/docs/zh/guides/upgrade/other.md +4 -11
- package/docs/zh/guides/upgrade/overview.mdx +1 -4
- package/docs/zh/guides/upgrade/tailwindcss.mdx +0 -1
- package/docs/zh/guides/upgrade/web-server.md +34 -19
- package/docs/zh/index.md +1 -0
- package/docs/zh/plugin/cli-plugins/api.mdx +24 -24
- package/docs/zh/plugin/cli-plugins/life-cycle.mdx +2 -0
- package/docs/zh/plugin/introduction.mdx +6 -6
- package/docs/zh/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
- package/docs/zh/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
- package/docs/zh/plugin/plugin-system.mdx +19 -26
- package/docs/zh/plugin/runtime-plugins/life-cycle.mdx +2 -0
- package/docs/zh/plugin/server-plugins/api.mdx +11 -14
- package/docs/zh/plugin/server-plugins/life-cycle.mdx +2 -0
- package/package.json +11 -13
- package/{rspress.config.ts → rstack.config.mts} +7 -10
- package/src/components/Footer/styles.module.scss +1 -1
- package/src/components/SolutionCards/index.module.scss +3 -1
|
@@ -8,15 +8,15 @@ When SSR is enabled, we need to monitor server-side phase durations and have the
|
|
|
8
8
|
|
|
9
9
|
Based on server-side runtime logic, Modern.js provides the following metric events:
|
|
10
10
|
|
|
11
|
-
| Key | Description
|
|
12
|
-
| ------------------------ |
|
|
13
|
-
| server-handle-request | Modern.js Server request handling duration
|
|
11
|
+
| Key | Description |
|
|
12
|
+
| ------------------------ | --------------------------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| server-handle-request | Modern.js Server request handling duration |
|
|
14
14
|
| ssr-render-shell | [SSR] When using Streaming SSR, React renders a shell for early streaming. This marks shell rendering completion time |
|
|
15
|
-
| ssr-render-html | [SSR] Time taken by React to render component tree to HTML (typically under 50ms)
|
|
16
|
-
| server-middleware | Total execution time of Modern.js custom server middlewares
|
|
17
|
-
| server-loader | Server-side Data Loader total duration
|
|
18
|
-
| server-loader-#id | Individual Data Loader durations on server-side
|
|
19
|
-
| server-loader-navigation | Server-side Data Loader duration during client navigation
|
|
15
|
+
| ssr-render-html | [SSR] Time taken by React to render component tree to HTML (typically under 50ms) |
|
|
16
|
+
| server-middleware | Total execution time of Modern.js custom server middlewares |
|
|
17
|
+
| server-loader | Server-side Data Loader total duration |
|
|
18
|
+
| server-loader-#id | Individual Data Loader durations on server-side |
|
|
19
|
+
| server-loader-navigation | Server-side Data Loader duration during client navigation |
|
|
20
20
|
|
|
21
21
|
Modern.js server workflow diagram:
|
|
22
22
|
|
|
@@ -129,9 +129,7 @@ const myMonitorPlugin = (): ServerPlugin => ({
|
|
|
129
129
|
console.log(`[${event.payload.level}] ${event.payload.message}`);
|
|
130
130
|
} else if (event.type === 'timing') {
|
|
131
131
|
// Handle timing events
|
|
132
|
-
console.log(
|
|
133
|
-
`Timing: ${event.payload.name} = ${event.payload.dur}ms`,
|
|
134
|
-
);
|
|
132
|
+
console.log(`Timing: ${event.payload.name} = ${event.payload.dur}ms`);
|
|
135
133
|
} else if (event.type === 'counter') {
|
|
136
134
|
// Handle counter events
|
|
137
135
|
console.log(`Counter: ${event.payload.name}`);
|
|
@@ -50,13 +50,13 @@ After creating the file, you can write custom logic in this file.
|
|
|
50
50
|
|
|
51
51
|
3. Include `server` directory in `tsconfig.json`
|
|
52
52
|
|
|
53
|
-
```
|
|
53
|
+
```jsonc
|
|
54
54
|
{
|
|
55
55
|
// ...
|
|
56
56
|
"include": [
|
|
57
57
|
// ...
|
|
58
|
-
"server"
|
|
59
|
-
]
|
|
58
|
+
"server",
|
|
59
|
+
],
|
|
60
60
|
}
|
|
61
61
|
```
|
|
62
62
|
|
|
@@ -24,9 +24,7 @@ Modern.js recommends managing routes using [conventional routing](/guides/basic-
|
|
|
24
24
|
In the `routes/user/page.data.ts` file, you can export a Data Loader function:
|
|
25
25
|
|
|
26
26
|
```ts title="routes/user/page.data.ts"
|
|
27
|
-
export type ProfileData = {
|
|
28
|
-
/* some types */
|
|
29
|
-
};
|
|
27
|
+
export type ProfileData = {/* some types */};
|
|
30
28
|
|
|
31
29
|
export const loader = async (): Promise<ProfileData> => {
|
|
32
30
|
const res = await fetch('https://api/user/profile');
|
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
useFetcher,
|
|
43
43
|
useLoaderData,
|
|
44
44
|
useParams,
|
|
45
|
-
Outlet
|
|
45
|
+
Outlet,
|
|
46
46
|
} from '@modern-js/runtime/router';
|
|
47
47
|
|
|
48
48
|
export default () => {
|
|
@@ -50,23 +50,21 @@ export default () => {
|
|
|
50
50
|
const { submit } = useFetcher();
|
|
51
51
|
const editUser = () => {
|
|
52
52
|
const newUser = {
|
|
53
|
-
name: 'Modern.js'
|
|
54
|
-
}
|
|
53
|
+
name: 'Modern.js',
|
|
54
|
+
};
|
|
55
55
|
return submit(newUser, {
|
|
56
56
|
method: 'post',
|
|
57
57
|
encType: 'application/json',
|
|
58
|
-
})
|
|
59
|
-
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
60
|
return (
|
|
61
61
|
<div>
|
|
62
62
|
<button onClick={editUser}>edit user</button>
|
|
63
|
-
<div className="user-profile">
|
|
64
|
-
{userInfo}
|
|
65
|
-
</div>
|
|
63
|
+
<div className="user-profile">{userInfo}</div>
|
|
66
64
|
<Outlet context={userInfo}></Outlet>
|
|
67
65
|
</div>
|
|
68
|
-
)
|
|
69
|
-
}
|
|
66
|
+
);
|
|
67
|
+
};
|
|
70
68
|
```
|
|
71
69
|
|
|
72
70
|
After executing `submit`, the defined `action` function will be triggered. You can get the submitted data from the [parameters](/guides/basic-features/data/data-write.html#parameters) in the `action` function and ultimately send the data to the server.
|
|
@@ -123,17 +121,18 @@ useSubmit:
|
|
|
123
121
|
|
|
124
122
|
```ts
|
|
125
123
|
const submit = useSubmit();
|
|
126
|
-
submit(null, { method:
|
|
124
|
+
submit(null, { method: 'post', action: '/logout' });
|
|
127
125
|
```
|
|
128
126
|
|
|
129
127
|
useFetcher:
|
|
130
128
|
|
|
131
129
|
```ts
|
|
132
130
|
const { submit } = useFetcher();
|
|
133
|
-
submit(null, { method:
|
|
131
|
+
submit(null, { method: 'post', action: '/logout' });
|
|
134
132
|
```
|
|
135
133
|
|
|
136
134
|
The `submit` function takes two parameters. The first parameter is the `formData` passed to the server. The second parameter is an optional object where:
|
|
135
|
+
|
|
137
136
|
- `method` corresponds to the form submission method. In most data writing scenarios, you can set the `method` to `post`.
|
|
138
137
|
- `action` specifies the route component to trigger the Data Action. If not provided, it defaults to the current route component's action. For example, executing submit in `user/page.tsx` or its sub-components will trigger the action defined in `user/page.data.ts`.
|
|
139
138
|
|
|
@@ -151,7 +150,7 @@ For example, `FormData`:
|
|
|
151
150
|
|
|
152
151
|
```ts
|
|
153
152
|
let formData = new FormData();
|
|
154
|
-
formData.append(
|
|
153
|
+
formData.append('cheese', 'gouda');
|
|
155
154
|
submit(formData);
|
|
156
155
|
// In the action, you can get the data by request.json
|
|
157
156
|
```
|
|
@@ -160,7 +159,7 @@ or `URLSearchParams`:
|
|
|
160
159
|
|
|
161
160
|
```ts
|
|
162
161
|
let searchParams = new URLSearchParams();
|
|
163
|
-
searchParams.append(
|
|
162
|
+
searchParams.append('cheese', 'gouda');
|
|
164
163
|
submit(searchParams);
|
|
165
164
|
// In the action, you can get the data by request.json
|
|
166
165
|
```
|
|
@@ -168,10 +167,10 @@ submit(searchParams);
|
|
|
168
167
|
or any value that the `URLSearchParams` constructor accepts:
|
|
169
168
|
|
|
170
169
|
```ts
|
|
171
|
-
submit(
|
|
170
|
+
submit('cheese=gouda&toasted=yes');
|
|
172
171
|
submit([
|
|
173
|
-
[
|
|
174
|
-
[
|
|
172
|
+
['cheese', 'gouda'],
|
|
173
|
+
['toasted', 'yes'],
|
|
175
174
|
]);
|
|
176
175
|
// In the action, you can get the data by request.json
|
|
177
176
|
```
|
|
@@ -180,11 +179,11 @@ By default, if the first parameter of the `submit` function is an object, the co
|
|
|
180
179
|
|
|
181
180
|
```ts
|
|
182
181
|
submit(
|
|
183
|
-
{ key:
|
|
182
|
+
{ key: 'value' },
|
|
184
183
|
{
|
|
185
|
-
method:
|
|
186
|
-
encType:
|
|
187
|
-
}
|
|
184
|
+
method: 'post',
|
|
185
|
+
encType: 'application/x-www-form-urlencoded',
|
|
186
|
+
},
|
|
188
187
|
);
|
|
189
188
|
|
|
190
189
|
// In the action, you can get the data by request.formData
|
|
@@ -193,14 +192,11 @@ submit(
|
|
|
193
192
|
You can also specify the encoding type via the second parameter:
|
|
194
193
|
|
|
195
194
|
```tsx
|
|
196
|
-
submit(
|
|
197
|
-
{ key: "value" },
|
|
198
|
-
{ method: "post", encType: "application/json" }
|
|
199
|
-
);
|
|
195
|
+
submit({ key: 'value' }, { method: 'post', encType: 'application/json' });
|
|
200
196
|
|
|
201
197
|
submit('{"key":"value"}', {
|
|
202
|
-
method:
|
|
203
|
-
encType:
|
|
198
|
+
method: 'post',
|
|
199
|
+
encType: 'application/json',
|
|
204
200
|
});
|
|
205
201
|
|
|
206
202
|
// In the action, you can get the data by request.json
|
|
@@ -209,7 +205,7 @@ submit('{"key":"value"}', {
|
|
|
209
205
|
or submit plain text:
|
|
210
206
|
|
|
211
207
|
```ts
|
|
212
|
-
submit(
|
|
208
|
+
submit('value', { method: 'post', encType: 'text/plain' });
|
|
213
209
|
// In the action, you can get the data by request.text
|
|
214
210
|
```
|
|
215
211
|
|
|
@@ -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
|
# Using Storybook
|
|
8
8
|
|
|
@@ -33,17 +33,16 @@ You need to install `@rsbuild/core` in your project, otherwise the plugin may no
|
|
|
33
33
|
## Configure `.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
|
-
|
|
47
46
|
## BFF Integrated Calls in Storybook
|
|
48
47
|
|
|
49
48
|
When you want to call BFF APIs directly in Storybook components (for example `/api/**`), start the BFF service and configure a proxy in Storybook's dev server to avoid CORS issues.
|
|
@@ -56,7 +55,7 @@ Add the following scripts to `package.json` to start the BFF server and Storyboo
|
|
|
56
55
|
{
|
|
57
56
|
"scripts": {
|
|
58
57
|
"dev:api": "modern dev --api-only",
|
|
59
|
-
"storybook": "BFF_PROXY=1 storybook dev -p 6006 --no-open"
|
|
58
|
+
"storybook": "BFF_PROXY=1 storybook dev -p 6006 --no-open"
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
```
|
|
@@ -19,9 +19,8 @@ For example, consider the following directory structure:
|
|
|
19
19
|
├── entry-a
|
|
20
20
|
│ ├── Document.tsx
|
|
21
21
|
│ └── routes
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
└── modern-app-env.d.ts
|
|
22
|
+
└── entry-b
|
|
23
|
+
└── routes
|
|
25
24
|
```
|
|
26
25
|
|
|
27
26
|
`entry-a` will use the `Document.tsx` file under the current entry as the template. If there is no `Document.tsx` file under the current entry, like `entry-b`, it will look for the `Document.tsx` file under the root directory.
|
|
@@ -8,21 +8,21 @@ Modern.js supports multiple rendering modes, and different rendering modes are s
|
|
|
8
8
|
|
|
9
9
|
## Rendering Mode Quick Reference
|
|
10
10
|
|
|
11
|
-
| Rendering Mode
|
|
12
|
-
|
|
13
|
-
| **CSR**
|
|
14
|
-
| **SSR**
|
|
15
|
-
| **Streaming SSR** | Renders and returns progressively, displaying initial UI faster
|
|
16
|
-
| **RSC**
|
|
17
|
-
| **SSG**
|
|
11
|
+
| Rendering Mode | Characteristics | Use Cases |
|
|
12
|
+
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
|
|
13
|
+
| **CSR** | Executes JavaScript in the browser to render pages | Applications with strong interactivity and low SEO requirements |
|
|
14
|
+
| **SSR** | Pre-renders complete HTML pages on the server | Websites with high requirements for first-screen performance and SEO |
|
|
15
|
+
| **Streaming SSR** | Renders and returns progressively, displaying initial UI faster | Applications requiring faster first-screen perception speed (**Default SSR mode**) |
|
|
16
|
+
| **RSC** | Components render on the server, reducing client JS size; high cohesion between data and component logic, reducing state passing | Projects pursuing optimal performance and needing to reduce client-side code |
|
|
17
|
+
| **SSG** | Generates static pages at build time, can be cached by CDN | Websites with relatively static content, such as blogs and documentation sites |
|
|
18
18
|
|
|
19
19
|
## Performance Comparison
|
|
20
20
|
|
|
21
|
-
| Rendering Technology
|
|
22
|
-
|
|
23
|
-
| **SSR**
|
|
24
|
-
| **Streaming SSR**
|
|
25
|
-
| **Streaming SSR + RSC** | Reduces client JS size
|
|
21
|
+
| Rendering Technology | Core Advantages | Main Bottlenecks |
|
|
22
|
+
| ----------------------- | ------------------------------------------------------ | ------------------------------------------------ |
|
|
23
|
+
| **SSR** | Server-side pre-rendering, beneficial for SEO | Must wait for all data to load before responding |
|
|
24
|
+
| **Streaming SSR** | Renders and returns progressively, faster first screen | JS bundle size is still large |
|
|
25
|
+
| **Streaming SSR + RSC** | Reduces client JS size | - |
|
|
26
26
|
|
|
27
27
|
## How to Choose
|
|
28
28
|
|
|
@@ -239,12 +239,12 @@ In RSC projects, you have two ways to fetch data: directly in Server Components,
|
|
|
239
239
|
|
|
240
240
|
### Comparison of Two Data Fetching Approaches
|
|
241
241
|
|
|
242
|
-
| Feature
|
|
243
|
-
|
|
|
244
|
-
| Avoid Request Waterfall | Requires manual optimization
|
|
245
|
-
| Component Cohesion
|
|
246
|
-
| Maintainability
|
|
247
|
-
| Type Safety
|
|
242
|
+
| Feature | Fetching in Server Component | Fetching in Data Loader |
|
|
243
|
+
| ----------------------- | ------------------------------------ | ---------------------------------------- |
|
|
244
|
+
| Avoid Request Waterfall | Requires manual optimization | ✅ Automatically parallel execution |
|
|
245
|
+
| Component Cohesion | ✅ Data and UI in the same place | Data logic separated into separate files |
|
|
246
|
+
| Maintainability | ✅ Easier to understand and maintain | Requires maintaining additional files |
|
|
247
|
+
| Type Safety | ✅ Natural type inference | Requires manual type management |
|
|
248
248
|
|
|
249
249
|
**Generally, we recommend fetching data in Server Components**, because waterfall requests have less performance impact on the server, and this approach makes components more cohesive, with data fetching logic and UI rendering in the same place, making it easier to understand and maintain. However, if your page has multiple independent data sources and you want to completely avoid request waterfall issues, Data Loader's parallel execution feature will be more advantageous.
|
|
250
250
|
|
|
@@ -268,7 +268,11 @@ In Modern.js RSC projects, Server Components can receive data returned by Data L
|
|
|
268
268
|
|
|
269
269
|
```tsx title="routes/user/page.tsx"
|
|
270
270
|
// Server Component receives loaderData through props
|
|
271
|
-
export default function UserPage({
|
|
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 can also receive loaderData through props
|
|
279
|
-
export default function UserPage({
|
|
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
|
```
|
|
@@ -515,7 +523,6 @@ When using React 19, you no longer need to use Helmet. We recommend directly usi
|
|
|
515
523
|
|
|
516
524
|
import DeployTip from '@site-docs/components/rsc-deploy-tip';
|
|
517
525
|
|
|
518
|
-
|
|
519
526
|
<DeployTip />
|
|
520
527
|
|
|
521
528
|
## Common Issues
|
|
@@ -193,9 +193,9 @@ When rendering cache is enabled, Modern.js identifies the cache status of the cu
|
|
|
193
193
|
|
|
194
194
|
The `x-render-cache` header can have the following values:
|
|
195
195
|
|
|
196
|
-
| Name | Description
|
|
197
|
-
| ------- |
|
|
198
|
-
| hit | Cache hit, returned cache content
|
|
196
|
+
| Name | Description |
|
|
197
|
+
| ------- | ----------------------------------------------------------------------------------- |
|
|
198
|
+
| hit | Cache hit, returned cache content |
|
|
199
199
|
| stale | Cache hit, but data is stale, returned cache content and re-rendered asynchronously |
|
|
200
|
-
| expired | Cache expired, re-rendered and returned new content
|
|
201
|
-
| miss | Cache missed
|
|
200
|
+
| expired | Cache expired, re-rendered and returned new content |
|
|
201
|
+
| miss | Cache missed |
|
|
@@ -90,7 +90,7 @@ export async function loader({ params }) {
|
|
|
90
90
|
const data = await res.json();
|
|
91
91
|
return {
|
|
92
92
|
message: data.message,
|
|
93
|
-
}
|
|
93
|
+
};
|
|
94
94
|
}
|
|
95
95
|
```
|
|
96
96
|
|
|
@@ -125,11 +125,7 @@ const Page = () => {
|
|
|
125
125
|
const undefinedVars = data.unDefined;
|
|
126
126
|
const definedVars = data.defined;
|
|
127
127
|
|
|
128
|
-
return
|
|
129
|
-
<div>
|
|
130
|
-
{isNode ? undefinedVars.msg : definedVars.msg}
|
|
131
|
-
</div>
|
|
132
|
-
);
|
|
128
|
+
return <div>{isNode ? undefinedVars.msg : definedVars.msg}</div>;
|
|
133
129
|
};
|
|
134
130
|
|
|
135
131
|
export default Page;
|
|
@@ -214,7 +210,7 @@ document.addEventListener('load', () => {
|
|
|
214
210
|
console.log('document load');
|
|
215
211
|
});
|
|
216
212
|
|
|
217
|
-
export const doSomething = () => {}
|
|
213
|
+
export const doSomething = () => {};
|
|
218
214
|
```
|
|
219
215
|
|
|
220
216
|
Directly referencing this in a component will cause SSR to throw errors, even if you use environment variables to conditionally load the code. The side effects in the dependency will still execute.
|
|
@@ -226,8 +222,8 @@ export const Page = () => {
|
|
|
226
222
|
if (process.env.MODERN_TARGET === 'browser') {
|
|
227
223
|
doSomething();
|
|
228
224
|
}
|
|
229
|
-
return <div>Hello World</div
|
|
230
|
-
}
|
|
225
|
+
return <div>Hello World</div>;
|
|
226
|
+
};
|
|
231
227
|
```
|
|
232
228
|
|
|
233
229
|
Modern.js supports distinguishing between SSR and CSR bundles by using `.server.` suffix files. You can create `.ts` and `.server.ts` files with the same name to create a proxy:
|
|
@@ -243,12 +239,12 @@ export const doSomething: any = () => {};
|
|
|
243
239
|
Import `./a` in the file, and the SSR bundle will prioritize the `.server.ts` files, while the CSR bundle will prioritize the `.ts` files.
|
|
244
240
|
|
|
245
241
|
```tsx title="routes/page.tsx"
|
|
246
|
-
import { doSomething } from './a'
|
|
242
|
+
import { doSomething } from './a';
|
|
247
243
|
|
|
248
244
|
export const Page = () => {
|
|
249
245
|
doSomething();
|
|
250
|
-
return <div>Hello World</div
|
|
251
|
-
}
|
|
246
|
+
return <div>Hello World</div>;
|
|
247
|
+
};
|
|
252
248
|
```
|
|
253
249
|
|
|
254
250
|
## Common Issues
|
|
@@ -245,7 +245,8 @@ Set the header in your middleware to choose the behavior dynamically:
|
|
|
245
245
|
```ts title="middleware example"
|
|
246
246
|
export const middleware = async (ctx, next) => {
|
|
247
247
|
const ua = ctx.req.header('user-agent') || '';
|
|
248
|
-
const shouldWaitAll =
|
|
248
|
+
const shouldWaitAll =
|
|
249
|
+
/Lighthouse|Googlebot/i.test(ua) || ctx.req.path === '/marketing';
|
|
249
250
|
|
|
250
251
|
// Write a boolean string: true -> onAllReady, false -> onShellReady
|
|
251
252
|
ctx.req.headers.set('x-should-stream-all', String(shouldWaitAll));
|