@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
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
title: upload/
|
|
3
3
|
sidebar_position: 4
|
|
4
4
|
---
|
|
5
|
+
|
|
5
6
|
# upload/
|
|
6
7
|
|
|
7
8
|
Any static assets can be placed in the `upload/` directory.
|
|
@@ -30,9 +31,7 @@ In React components, you can add this prefix through [Environment Variables](/gu
|
|
|
30
31
|
|
|
31
32
|
```tsx
|
|
32
33
|
export default () => {
|
|
33
|
-
return
|
|
34
|
-
<img src={`${process.env.ASSET_PREFIX}/upload/banner.png`}></img>
|
|
35
|
-
);
|
|
34
|
+
return <img src={`${process.env.ASSET_PREFIX}/upload/banner.png`}></img>;
|
|
36
35
|
};
|
|
37
36
|
```
|
|
38
37
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
title: '*.[server|node].tsx'
|
|
3
3
|
sidebar_position: 8
|
|
4
4
|
---
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
# \*.[server|node].tsx
|
|
6
7
|
|
|
7
8
|
Used in the application project to place server-side code. When `*.tsx` and `*.[server|node].tsx` coexist, SSR will prefer to use the `*.[server|node].tsx` file instead of the `*.tsx` file when rendering on the server.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: createRoot
|
|
3
3
|
---
|
|
4
|
+
|
|
4
5
|
# createRoot
|
|
5
6
|
|
|
6
7
|
It is used to create the root component provided by Modern.js, which will automatically register Runtime plugins and complete the initialization of Runtime plugins.
|
|
@@ -14,7 +15,9 @@ import { createRoot } from '@modern-js/runtime/react';
|
|
|
14
15
|
## Function Signature
|
|
15
16
|
|
|
16
17
|
```ts
|
|
17
|
-
export function createRoot(
|
|
18
|
+
export function createRoot(
|
|
19
|
+
UserApp?: React.ComponentType | null,
|
|
20
|
+
): React.ComponentType<any>;
|
|
18
21
|
```
|
|
19
22
|
|
|
20
23
|
### Parameters
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: render
|
|
3
3
|
---
|
|
4
|
+
|
|
4
5
|
# render
|
|
5
6
|
|
|
6
7
|
It is used to render project components.
|
|
@@ -16,7 +17,10 @@ render(<ModernRoot />);
|
|
|
16
17
|
## Function Signature
|
|
17
18
|
|
|
18
19
|
```ts
|
|
19
|
-
export function render(
|
|
20
|
+
export function render(
|
|
21
|
+
App: React.ReactElement,
|
|
22
|
+
id?: HTMLElement | string,
|
|
23
|
+
): Promise<any>;
|
|
20
24
|
```
|
|
21
25
|
|
|
22
26
|
### Parameters
|
|
@@ -33,7 +37,7 @@ import { render } from '@modern-js/runtime/browser';
|
|
|
33
37
|
const ModernRoot = createRoot();
|
|
34
38
|
|
|
35
39
|
async function beforeRender() {
|
|
36
|
-
|
|
40
|
+
// todo
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
beforeRender().then(() => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: RuntimeContext
|
|
3
3
|
---
|
|
4
|
+
|
|
4
5
|
# RuntimeContext
|
|
5
6
|
|
|
6
7
|
`RuntimeContext` is a React Context used to get Runtime context information in components. This Context can be accessed through React's `use` or `useContext` API.
|
|
@@ -19,7 +20,7 @@ import { RuntimeContext } from '@modern-js/runtime';
|
|
|
19
20
|
|
|
20
21
|
export function App() {
|
|
21
22
|
const runtimeContext = use(RuntimeContext); // You can also use useContext(RuntimeContext)
|
|
22
|
-
return <div>Hello World</div
|
|
23
|
+
return <div>Hello World</div>;
|
|
23
24
|
}
|
|
24
25
|
```
|
|
25
26
|
|
|
@@ -53,21 +54,21 @@ type TRuntimeContext = {
|
|
|
53
54
|
```ts
|
|
54
55
|
type RequestContext = {
|
|
55
56
|
request: {
|
|
56
|
-
params: Record<string, string>;
|
|
57
|
-
pathname: string;
|
|
58
|
-
query: Record<string, string>;
|
|
59
|
-
headers: IncomingHttpHeaders;
|
|
60
|
-
host: string;
|
|
61
|
-
url: string;
|
|
62
|
-
referer?: string;
|
|
63
|
-
userAgent?: string;
|
|
64
|
-
cookie?: string;
|
|
65
|
-
cookieMap?: Record<string, string>;
|
|
57
|
+
params: Record<string, string>; // Route parameters
|
|
58
|
+
pathname: string; // Pathname
|
|
59
|
+
query: Record<string, string>; // Query parameters
|
|
60
|
+
headers: IncomingHttpHeaders; // Request headers
|
|
61
|
+
host: string; // Hostname
|
|
62
|
+
url: string; // Full URL
|
|
63
|
+
referer?: string; // Referrer page
|
|
64
|
+
userAgent?: string; // User agent
|
|
65
|
+
cookie?: string; // Cookie string
|
|
66
|
+
cookieMap?: Record<string, string>; // Cookie map object
|
|
66
67
|
};
|
|
67
68
|
response: {
|
|
68
|
-
setHeader: (key: string, value: string) => void;
|
|
69
|
-
status: (code: number) => void;
|
|
70
|
-
locals: Record<string, any>;
|
|
69
|
+
setHeader: (key: string, value: string) => void; // Set response header (server-side only)
|
|
70
|
+
status: (code: number) => void; // Set status code (server-side only)
|
|
71
|
+
locals: Record<string, any>; // Local data
|
|
71
72
|
};
|
|
72
73
|
};
|
|
73
74
|
```
|
|
@@ -91,11 +92,11 @@ function App() {
|
|
|
91
92
|
|
|
92
93
|
if (isBrowser === true) {
|
|
93
94
|
// Browser-side execution logic
|
|
94
|
-
console.log('browser render')
|
|
95
|
+
console.log('browser render');
|
|
95
96
|
} else {
|
|
96
97
|
// Server-side execution logic
|
|
97
98
|
// Note: Functions like logger need to be injected into context through Runtime plugins
|
|
98
|
-
console.log('server render')
|
|
99
|
+
console.log('server render');
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
```
|
|
@@ -157,4 +158,3 @@ export default function MyComponent() {
|
|
|
157
158
|
return <div>{message}</div>;
|
|
158
159
|
}
|
|
159
160
|
```
|
|
160
|
-
|
|
@@ -136,8 +136,10 @@ export default ErrorBoundary;
|
|
|
136
136
|
```ts
|
|
137
137
|
declare function Link(props: LinkProps): React.ReactElement;
|
|
138
138
|
|
|
139
|
-
interface LinkProps
|
|
140
|
-
|
|
139
|
+
interface LinkProps extends Omit<
|
|
140
|
+
React.AnchorHTMLAttributes<HTMLAnchorElement>,
|
|
141
|
+
'href'
|
|
142
|
+
> {
|
|
141
143
|
replace?: boolean;
|
|
142
144
|
state?: any;
|
|
143
145
|
to: To;
|
|
@@ -158,12 +160,13 @@ A `<Link>` is an element that lets the user navigate to another page by clicking
|
|
|
158
160
|
```ts
|
|
159
161
|
declare function NavLink(props: NavLinkProps): React.ReactElement;
|
|
160
162
|
|
|
161
|
-
interface NavLinkProps
|
|
162
|
-
|
|
163
|
+
interface NavLinkProps extends Omit<
|
|
164
|
+
LinkProps,
|
|
165
|
+
'className' | 'style' | 'children'
|
|
166
|
+
> {
|
|
163
167
|
caseSensitive?: boolean;
|
|
164
168
|
children?:
|
|
165
|
-
| React.ReactNode
|
|
166
|
-
| ((props: { isActive: boolean }) => React.ReactNode);
|
|
169
|
+
React.ReactNode | ((props: { isActive: boolean }) => React.ReactNode);
|
|
167
170
|
className?: string | ((props: { isActive: boolean }) => string | undefined);
|
|
168
171
|
end?: boolean;
|
|
169
172
|
style?:
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
title: Modern.js v3 Release
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
# Modern.js v3 Release: Focused on web framework, embracing ecosystem development
|
|
7
6
|
|
|
8
7
|
> Published on 2025.02.06
|
|
@@ -45,10 +44,10 @@ Modern.js 3.0 integrates React Server Component, supporting both CSR and SSR pro
|
|
|
45
44
|
|
|
46
45
|
React Server Components (RSC) are a new type of component that allows **component logic to execute entirely on the server**, streaming the rendered UI directly to the client. Compared to traditional client components, Server Components offer the following benefits:
|
|
47
46
|
|
|
48
|
-
| Feature
|
|
49
|
-
|
|
|
50
|
-
| Zero Client Bundle Size | Component code is not included in the client JS bundle — it only executes on the server, speeding up initial page load and rendering
|
|
51
|
-
| Higher Cohesion
|
|
47
|
+
| Feature | Description |
|
|
48
|
+
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
49
|
+
| Zero Client Bundle Size | Component code is not included in the client JS bundle — it only executes on the server, speeding up initial page load and rendering |
|
|
50
|
+
| Higher Cohesion | Components can directly access databases, call internal APIs, and read local files, improving development efficiency |
|
|
52
51
|
| Progressive Enhancement | Can be seamlessly mixed with client components, selectively offloading interactive logic to the client while maintaining high performance and supporting complex interactions |
|
|
53
52
|
|
|
54
53
|
It's important to clarify that RSC and SSR are **fundamentally different concepts**:
|
|
@@ -68,7 +67,7 @@ In Modern.js 3.0, simply enable RSC in the configuration:
|
|
|
68
67
|
export default defineConfig({
|
|
69
68
|
server: {
|
|
70
69
|
rsc: true,
|
|
71
|
-
}
|
|
70
|
+
},
|
|
72
71
|
});
|
|
73
72
|
```
|
|
74
73
|
|
|
@@ -76,7 +75,14 @@ export default defineConfig({
|
|
|
76
75
|
Once enabled, all route components will default to Server Components. Some components in your project may not be able to run on the server — you can add the `'use client'` directive to those components to preserve their original behavior, and then migrate gradually.
|
|
77
76
|
:::
|
|
78
77
|
|
|
79
|
-
<video
|
|
78
|
+
<video
|
|
79
|
+
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/nuvjhpqnuvr/rsc.mp4"
|
|
80
|
+
controls
|
|
81
|
+
autoplay
|
|
82
|
+
loop
|
|
83
|
+
muted
|
|
84
|
+
style={{ width: '100%', borderRadius: 8 }}
|
|
85
|
+
/>
|
|
80
86
|
|
|
81
87
|
#### RSC Features in Modern.js 3.0
|
|
82
88
|
|
|
@@ -157,7 +163,7 @@ import('./module').then(({ value }) => {
|
|
|
157
163
|
});
|
|
158
164
|
|
|
159
165
|
// Destructuring in function body
|
|
160
|
-
import('./module').then(
|
|
166
|
+
import('./module').then(mod => {
|
|
161
167
|
const { value } = mod;
|
|
162
168
|
console.log(value);
|
|
163
169
|
});
|
|
@@ -237,7 +243,10 @@ In practice, we found that some projects need to extend the Web Server — for e
|
|
|
237
243
|
In Modern.js 3.0, we rebuilt the Web Server using [Hono](https://hono.dev) and officially opened up server middleware and plugin capabilities. Developers can use Hono middleware to meet their needs:
|
|
238
244
|
|
|
239
245
|
```ts title="server/modern.server.ts"
|
|
240
|
-
import {
|
|
246
|
+
import {
|
|
247
|
+
defineServerConfig,
|
|
248
|
+
type MiddlewareHandler,
|
|
249
|
+
} from '@modern-js/server-runtime';
|
|
241
250
|
|
|
242
251
|
const timingMiddleware: MiddlewareHandler = async (c, next) => {
|
|
243
252
|
const start = Date.now();
|
|
@@ -250,8 +259,8 @@ const htmlMiddleware: MiddlewareHandler = async (c, next) => {
|
|
|
250
259
|
await next();
|
|
251
260
|
const html = await c.res.text();
|
|
252
261
|
const modified = html.replace(
|
|
253
|
-
|
|
254
|
-
'<head><meta name="generator" content="Modern.js">'
|
|
262
|
+
'<head>',
|
|
263
|
+
'<head><meta name="generator" content="Modern.js">',
|
|
255
264
|
);
|
|
256
265
|
c.res = c.body(modified, { status: c.res.status, headers: c.res.headers });
|
|
257
266
|
};
|
|
@@ -322,13 +331,13 @@ In Modern.js, we recommend using convention-based routing to organize code. Howe
|
|
|
322
331
|
Therefore, Modern.js 3.0 provides full config-based routing support, which can be used alongside convention-based routing or independently.
|
|
323
332
|
|
|
324
333
|
```ts title="src/modern.routes.ts"
|
|
325
|
-
import { defineRoutes } from
|
|
334
|
+
import { defineRoutes } from '@modern-js/runtime/config-routes';
|
|
326
335
|
|
|
327
336
|
export default defineRoutes(({ route, layout, page }) => {
|
|
328
337
|
return [
|
|
329
|
-
route(
|
|
330
|
-
route(
|
|
331
|
-
route(
|
|
338
|
+
route('home.tsx', '/'),
|
|
339
|
+
route('about.tsx', 'about'),
|
|
340
|
+
route('blog.tsx', 'blog/:id'),
|
|
332
341
|
];
|
|
333
342
|
});
|
|
334
343
|
```
|
|
@@ -414,19 +423,19 @@ For render cache usage, see the docs: [Render Cache](/guides/basic-features/rend
|
|
|
414
423
|
The new version provides a `cache` function that offers finer-grained data-level control compared to render cache. When multiple data requests depend on the same data, `cache` can avoid duplicate requests:
|
|
415
424
|
|
|
416
425
|
```ts title="server/loader.ts"
|
|
417
|
-
import { cache } from
|
|
418
|
-
import { fetchUserData, fetchUserProjects, fetchUserTeam } from
|
|
426
|
+
import { cache } from '@modern-js/runtime/cache';
|
|
427
|
+
import { fetchUserData, fetchUserProjects, fetchUserTeam } from './api';
|
|
419
428
|
|
|
420
429
|
// Cache user data to avoid duplicate requests
|
|
421
430
|
const getUser = cache(fetchUserData);
|
|
422
431
|
|
|
423
432
|
const getProjects = async () => {
|
|
424
|
-
const user = await getUser(
|
|
433
|
+
const user = await getUser('test-user');
|
|
425
434
|
return fetchUserProjects(user.id);
|
|
426
435
|
};
|
|
427
436
|
|
|
428
437
|
const getTeam = async () => {
|
|
429
|
-
const user = await getUser(
|
|
438
|
+
const user = await getUser('test-user'); // Reuses cache, no duplicate request
|
|
430
439
|
return fetchUserTeam(user.id);
|
|
431
440
|
};
|
|
432
441
|
|
|
@@ -445,14 +454,14 @@ For more on data cache usage, see the docs: [Data Cache](/guides/basic-features/
|
|
|
445
454
|
|
|
446
455
|
Through practice, we have developed multi-dimensional fallback strategies:
|
|
447
456
|
|
|
448
|
-
| Type
|
|
449
|
-
|
|
|
450
|
-
| Error Fallback
|
|
451
|
-
| Render Error
|
|
452
|
-
| Business Fallback | Loader throws `throw Response`
|
|
453
|
-
| Client Loader
|
|
454
|
-
| Forced Fallback
|
|
455
|
-
| Forced Fallback
|
|
457
|
+
| Type | Trigger | Fallback Behavior | Use Case |
|
|
458
|
+
| ----------------- | -------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------- |
|
|
459
|
+
| Error Fallback | Data Loader execution error | Triggers ErrorBoundary | Data request error handling |
|
|
460
|
+
| Render Error | Server-side rendering error | Falls back to CSR, reusing existing data for rendering | SSR error handling |
|
|
461
|
+
| Business Fallback | Loader throws `throw Response` | Triggers ErrorBoundary with corresponding HTTP status code | 404, permission checks, and other business scenarios |
|
|
462
|
+
| Client Loader | Configure Client Loader | Bypasses SSR, requests data source directly | Scenarios requiring client-side data fetching |
|
|
463
|
+
| Forced Fallback | Query parameter `?__csr=true` | Skips SSR, returns CSR page | Debugging, temporary fallback |
|
|
464
|
+
| Forced Fallback | Request header `x-modern-ssr-fallback` | Skips SSR, returns CSR page | Gateway-level fallback control |
|
|
456
465
|
|
|
457
466
|
---
|
|
458
467
|
|
|
@@ -36,13 +36,6 @@ nvm alias default 22
|
|
|
36
36
|
nvm use 22
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
### Install pnpm
|
|
40
|
-
|
|
41
|
-
```sh
|
|
42
|
-
# Enable pnpm with corepack, only available on Node.js >= `v14.19.0`
|
|
43
|
-
corepack enable
|
|
44
|
-
```
|
|
45
|
-
|
|
46
39
|
### Install Dependencies
|
|
47
40
|
|
|
48
41
|
```sh
|
|
@@ -57,28 +50,6 @@ What this will do:
|
|
|
57
50
|
|
|
58
51
|
> A full rebuild of all packages is generally not required after this. If a new feature you are developing requires an updated version of another package, it is usually sufficient to build the changed dependencies.
|
|
59
52
|
|
|
60
|
-
### Set Git Email
|
|
61
|
-
|
|
62
|
-
Please make sure you have your email set up in `<https://github.com/settings/emails>`. This will be needed later when you want to submit a pull request.
|
|
63
|
-
|
|
64
|
-
Check that your git client is already configured the email:
|
|
65
|
-
|
|
66
|
-
```sh
|
|
67
|
-
git config --list | grep email
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
Set the email to global config:
|
|
71
|
-
|
|
72
|
-
```sh
|
|
73
|
-
git config --global user.email "SOME_EMAIL@example.com"
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
Set the email for local repo:
|
|
77
|
-
|
|
78
|
-
```sh
|
|
79
|
-
git config user.email "SOME_EMAIL@example.com"
|
|
80
|
-
```
|
|
81
|
-
|
|
82
53
|
## Making Changes and Building
|
|
83
54
|
|
|
84
55
|
Once you have set up the local development environment in your forked repo, we can start development.
|
|
@@ -132,7 +103,7 @@ Modern.js uses [Rstest](https://rstest.rs/) for unit tests across the repository
|
|
|
132
103
|
Before submitting a pull request, it's important to make sure that the changes haven't introduced any regressions or bugs. You can run the unit tests for the project by executing the following command:
|
|
133
104
|
|
|
134
105
|
```sh
|
|
135
|
-
pnpm run test
|
|
106
|
+
pnpm run test:ut
|
|
136
107
|
```
|
|
137
108
|
|
|
138
109
|
Alternatively, you can run the unit tests of single package using the `--filter` option:
|
|
@@ -145,10 +116,11 @@ pnpm run --filter @modern-js/some-package test
|
|
|
145
116
|
|
|
146
117
|
In addition to the unit tests, the Modern.js also includes end-to-end (E2E) tests, which checks the functionality of the application as a whole.
|
|
147
118
|
|
|
148
|
-
|
|
119
|
+
Run the framework integration tests and Builder E2E tests with the following commands:
|
|
149
120
|
|
|
150
121
|
```sh
|
|
151
|
-
pnpm run test:
|
|
122
|
+
pnpm run test:framework
|
|
123
|
+
pnpm run test:builder
|
|
152
124
|
```
|
|
153
125
|
|
|
154
126
|
If you need to run a specified test, you can add keywords to filter:
|
|
@@ -160,7 +132,7 @@ npx rstest copy-assets
|
|
|
160
132
|
|
|
161
133
|
## Linting
|
|
162
134
|
|
|
163
|
-
To help maintain consistency and readability
|
|
135
|
+
To help maintain consistency and readability across the codebase, we use [Rstack CLI](https://rstack.rs/) for linting and formatting.
|
|
164
136
|
|
|
165
137
|
You can run the Linter by executing the following command:
|
|
166
138
|
|
|
@@ -168,6 +140,14 @@ You can run the Linter by executing the following command:
|
|
|
168
140
|
pnpm run lint
|
|
169
141
|
```
|
|
170
142
|
|
|
143
|
+
Run the formatter from the repository root:
|
|
144
|
+
|
|
145
|
+
```sh
|
|
146
|
+
pnpm run format
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Append a file or directory path to either command to limit its scope.
|
|
150
|
+
|
|
171
151
|
## Benchmarking
|
|
172
152
|
|
|
173
153
|
You can input `!bench-framework` or `!bench-module` in the comment area of the PR to do benchmarking on `@modern-js/app-tools` and `@modern-js/module-tools` respectively (you need to have Collaborator and above permissions).
|
|
@@ -249,6 +229,8 @@ pnpm run prepare
|
|
|
249
229
|
pnpm run bump
|
|
250
230
|
```
|
|
251
231
|
|
|
232
|
+
After Changesets updates the package versions, this command synchronizes internal `peerDependencies` ranges to `workspace:^<dependency version>` to satisfy the changeset validation.
|
|
233
|
+
|
|
252
234
|
5. Commit the version change.
|
|
253
235
|
|
|
254
236
|
```sh
|
|
@@ -1 +1 @@
|
|
|
1
|
-
After local develop, you can refer to the [Deployment](/guides/basic-features/deploy.html) section to deploy the project to the server.
|
|
1
|
+
After local develop, you can refer to the [Deployment](/guides/basic-features/deploy.html) section to deploy the project to the server.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
:::tip Entry scanning logic
|
|
2
|
+
|
|
2
3
|
- If `src/` itself meets entry criteria → Single-entry application
|
|
3
4
|
- If `src/` does not meet criteria → Scan subdirectories under `src/` → Multi-entry application
|
|
4
5
|
- In single-entry applications, the default entry name is `index`
|
|
5
6
|
|
|
6
7
|
:::
|
|
7
|
-
|
|
@@ -38,19 +38,18 @@ npx @modern-js/create@latest myapp
|
|
|
38
38
|
|
|
39
39
|
⚡ Start the development server:
|
|
40
40
|
|
|
41
|
-
pnpm
|
|
41
|
+
pnpm dev
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Now, the project structure is as follows:
|
|
45
45
|
|
|
46
46
|
```
|
|
47
47
|
.
|
|
48
|
-
├── biome.json
|
|
49
48
|
├── modern.config.ts
|
|
50
49
|
├── package.json
|
|
51
50
|
├── README.md
|
|
51
|
+
├── rstack.config.mts
|
|
52
52
|
├── src
|
|
53
|
-
│ ├── modern-app-env.d.ts
|
|
54
53
|
│ ├── modern.runtime.ts
|
|
55
54
|
│ └── routes
|
|
56
55
|
│ ├── index.css
|
|
@@ -58,3 +57,10 @@ Now, the project structure is as follows:
|
|
|
58
57
|
│ └── page.tsx
|
|
59
58
|
└── tsconfig.json
|
|
60
59
|
```
|
|
60
|
+
|
|
61
|
+
New standalone projects use [Rstack CLI](https://rstack.rs/) for linting and formatting:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pnpm check
|
|
65
|
+
pnpm format
|
|
66
|
+
```
|
|
@@ -3,15 +3,18 @@ import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
|
3
3
|
|
|
4
4
|
export default defineRuntimeConfig({
|
|
5
5
|
masterApp: {
|
|
6
|
-
apps: [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
apps: [
|
|
7
|
+
{
|
|
8
|
+
name: 'Table',
|
|
9
|
+
entry: 'http://localhost:8081',
|
|
10
|
+
// activeWhen: '/table'
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'Dashboard',
|
|
14
|
+
entry: 'http://localhost:8082',
|
|
15
|
+
// activeWhen: '/dashboard'
|
|
16
|
+
},
|
|
17
|
+
],
|
|
15
18
|
},
|
|
16
19
|
});
|
|
17
20
|
```
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Before getting started, you will need to install [Node.js](https://nodejs.org/), and ensure that your Node.js version is not lower than
|
|
1
|
+
Before getting started, you will need to install [Node.js](https://nodejs.org/), and ensure that your Node.js version is not lower than v22.18.0. **We recommend using the LTS version of Node.js 22.**
|
|
2
2
|
|
|
3
3
|
You can check the currently used Node.js version with the following command:
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ You can check the currently used Node.js version with the following command:
|
|
|
6
6
|
node -v
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
If you do not have Node.js installed in your current environment, or the installed version
|
|
9
|
+
If you do not have Node.js installed in your current environment, or the installed version does not meet this requirement, you can use [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz/fnm) to install the required version.
|
|
10
10
|
|
|
11
11
|
Here is an example of how to install the Node.js 22 LTS version via nvm:
|
|
12
12
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|