@modern-js/main-doc 2.66.0 → 2.66.1-alpha.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 (61) hide show
  1. package/docs/en/apis/app/hooks/src/app.mdx +20 -34
  2. package/docs/en/apis/app/hooks/src/modern.runtime.mdx +9 -0
  3. package/docs/en/apis/app/runtime/app/define-config.mdx +6 -0
  4. package/docs/en/apis/app/runtime/web-server/hook.mdx +5 -0
  5. package/docs/en/apis/app/runtime/web-server/middleware.mdx +2 -23
  6. package/docs/en/components/enable-micro-frontend.mdx +20 -3
  7. package/docs/en/components/micro-runtime-config.mdx +12 -13
  8. package/docs/en/components/reduck-notify.mdx +27 -0
  9. package/docs/en/components/runtime-cli-config.mdx +0 -0
  10. package/docs/en/configure/app/runtime/0-intro.mdx +66 -90
  11. package/docs/en/configure/app/usage.mdx +93 -69
  12. package/docs/en/guides/advanced-features/web-server.mdx +38 -102
  13. package/docs/en/guides/basic-features/render/_meta.json +1 -1
  14. package/docs/en/guides/basic-features/render/before-render.mdx +115 -0
  15. package/docs/en/guides/basic-features/routes.mdx +0 -95
  16. package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +3 -5
  17. package/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +4 -2
  18. package/docs/en/guides/topic-detail/model/auto-actions.mdx +0 -4
  19. package/docs/en/guides/topic-detail/model/computed-state.mdx +0 -5
  20. package/docs/en/guides/topic-detail/model/define-model.mdx +0 -4
  21. package/docs/en/guides/topic-detail/model/faq.mdx +0 -5
  22. package/docs/en/guides/topic-detail/model/manage-effects.mdx +0 -5
  23. package/docs/en/guides/topic-detail/model/model-communicate.mdx +0 -5
  24. package/docs/en/guides/topic-detail/model/performance.mdx +0 -4
  25. package/docs/en/guides/topic-detail/model/quick-start.mdx +5 -7
  26. package/docs/en/guides/topic-detail/model/redux-integration.mdx +0 -4
  27. package/docs/en/guides/topic-detail/model/typescript-best-practice.mdx +0 -4
  28. package/docs/en/guides/topic-detail/model/use-model.mdx +0 -5
  29. package/docs/en/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -4
  30. package/docs/zh/apis/app/hooks/src/app.mdx +18 -26
  31. package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +9 -0
  32. package/docs/zh/apis/app/runtime/app/define-config.mdx +5 -0
  33. package/docs/zh/apis/app/runtime/web-server/hook.mdx +4 -0
  34. package/docs/zh/apis/app/runtime/web-server/middleware.mdx +2 -23
  35. package/docs/zh/components/enable-micro-frontend.mdx +19 -12
  36. package/docs/zh/components/micro-runtime-config.mdx +3 -3
  37. package/docs/zh/components/reduck-notify.mdx +27 -0
  38. package/docs/zh/components/runtime-cli-config.mdx +0 -0
  39. package/docs/zh/configure/app/runtime/0-intro.mdx +71 -86
  40. package/docs/zh/configure/app/usage.mdx +44 -21
  41. package/docs/zh/guides/advanced-features/web-server.mdx +35 -97
  42. package/docs/zh/guides/basic-features/render/_meta.json +1 -1
  43. package/docs/zh/guides/basic-features/render/before-render.mdx +115 -0
  44. package/docs/zh/guides/basic-features/routes.mdx +0 -95
  45. package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +3 -5
  46. package/docs/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +4 -2
  47. package/docs/zh/guides/topic-detail/model/auto-actions.mdx +0 -4
  48. package/docs/zh/guides/topic-detail/model/computed-state.mdx +0 -4
  49. package/docs/zh/guides/topic-detail/model/define-model.mdx +1 -4
  50. package/docs/zh/guides/topic-detail/model/faq.mdx +0 -5
  51. package/docs/zh/guides/topic-detail/model/manage-effects.mdx +0 -4
  52. package/docs/zh/guides/topic-detail/model/model-communicate.mdx +1 -4
  53. package/docs/zh/guides/topic-detail/model/performance.mdx +0 -4
  54. package/docs/zh/guides/topic-detail/model/quick-start.mdx +7 -8
  55. package/docs/zh/guides/topic-detail/model/redux-integration.mdx +0 -4
  56. package/docs/zh/guides/topic-detail/model/typescript-best-practice.mdx +0 -4
  57. package/docs/zh/guides/topic-detail/model/use-model.mdx +0 -5
  58. package/docs/zh/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -4
  59. package/package.json +1 -1
  60. package/docs/en/configure/app/server/enable-framework-ext.mdx +0 -49
  61. package/docs/zh/configure/app/server/enable-framework-ext.mdx +0 -49
@@ -1,44 +1,30 @@
1
- ---
2
- title: App.[tj]sx
3
- sidebar_position: 1
4
- ---
5
1
  # App.[tj]sx
6
2
 
7
- The identifier for the entry points when the application uses [Self-controlled Routing](/guides/concept/entries.html#self-controlled-routing).
3
+ The entry identifier when using [Self-controlled Routing](/guides/concept/entries.html#self-controlled-routing) in the application.
8
4
 
9
- `App.[tj]sx` is not the actual entry. Modern.js will generate the real entry for application. The content is roughly as follows:
5
+ `App.[tj]sx` is not the actual application entry; Modern.js will automatically generate the real entry file, which is roughly as follows:
10
6
 
11
7
  ```js
12
- import React from 'react';
13
- import ReactDOM from 'react-dom/client';
14
- import { createApp, bootstrap } from '@modern-js/runtime';
15
- // App.[jt]sx
8
+ // runtime-global-context
9
+ import { setGlobalContext } from '@modern-js/runtime/context';
16
10
  import App from '@_modern_js_src/App';
17
- // runtime plugin
18
- import { router } from '@modern-js/runtime/plugins';
19
-
20
- const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
21
- const MOUNT_ID = 'root';
22
-
23
- let AppWrapper = null;
24
-
25
- function render() {
26
- AppWrapper = createApp({
27
- plugins: [
28
- router({...{"serverBase":["/"]}, ...App.config?.router}),
29
- ]
30
- })(App)
31
- if (IS_BROWSER) {
32
- bootstrap(AppWrapper, MOUNT_ID, null, ReactDOM);
33
- }
34
- return AppWrapper
35
- }
36
-
37
- AppWrapper = render();
38
- export default AppWrapper;
11
+
12
+ setGlobalContext({
13
+ App,
14
+ });
15
+
16
+ // index.tsx
17
+ import './runtime-global-context';
18
+ import { createRoot } from '@modern-js/runtime/react';
19
+ import { render } from '@modern-js/runtime/browser';
20
+
21
+ const ModernRoot = createRoot();
22
+
23
+ render(<ModernRoot />, 'root');
39
24
  ```
40
25
 
41
- :::note
42
- In the multi-entry scenario, each entry can have its own `App.[jt]sx`. See [Entries](/guides/concept/entries) for details.
26
+ When `createRoot` is executed, it will retrieve the registered Global App and generate the actual React component.
43
27
 
28
+ :::note
29
+ In scenarios with multiple entry points, each entry can have its own independent `App.[jt]sx`. For more details, see [Entry Points](/guides/concept/entries).
44
30
  :::
@@ -0,0 +1,9 @@
1
+ ---
2
+ title: modern.runtime.[tj]s
3
+ sidebar_position: 4
4
+ ---
5
+ # modern.runtime.[tj]s
6
+
7
+ The Modern.js Runtime configuration file allows for personalized configuration of the Runtime capabilities for the current project.
8
+
9
+ For specific usage of the configuration, please refer to [Runtime Configuration](/configure/app/runtime/0-intro.html).
@@ -3,8 +3,14 @@ title: defineConfig
3
3
  ---
4
4
  # defineConfig
5
5
 
6
+ :::warning
7
+
8
+ Soon to be deprecated. It is recommended to use `src/modern.runtime.ts` to define Runtime configurations, which supports both static and dynamic configurations. Please refer to the plugin [Runtime Configuration](/configure/app/runtime/0-intro.html).
9
+
6
10
  For dynamically configuring applications runtime features.
7
11
 
12
+ :::
13
+
8
14
  ## Usage
9
15
 
10
16
  ```ts
@@ -6,6 +6,11 @@ title: Hook
6
6
 
7
7
  Used to extend Modern.js built-in Web Server, all page requests are handled by these hooks.
8
8
 
9
+ :::warning
10
+ It is recommended to use [UnstableMiddleware](/apis/app/runtime/web-server/unstable_middleware) to handle page requests.
11
+
12
+ :::
13
+
9
14
  :::note
10
15
  For more detail, see [Extend Web Server](/guides/advanced-features/web-server).
11
16
 
@@ -6,9 +6,9 @@ title: Middleware
6
6
 
7
7
  Used to extend the built-in Web Server of Modern.js, unlike [Hook](/apis/app/runtime/web-server/hook), Middleware can directly operate Node's origin request and response, and can be extended using the framework plugin.
8
8
 
9
- :::note
9
+ :::warning
10
10
 
11
- In the next major release, Modern.js will use new middleware to replace this approach.
11
+ Middleware will be removed in the next major version.
12
12
 
13
13
  It is recommended to use [UnstableMiddleware](/apis/app/runtime/web-server/unstable_middleware) to handle page requests.
14
14
 
@@ -118,24 +118,3 @@ export const Middleware = () => async (ctx, next) => {
118
118
  ctx.response.locals.rpc = createRpcInstance();
119
119
  };
120
120
  ```
121
-
122
- ### Framework Extension
123
-
124
- Middleware can also use runtime framework extensions like BFF.
125
-
126
- When using framework runtime extensions, type information is exported from `@modern-js/runtime/{namespace}`. Middleware can use framework syntax, such as framework middleware writing, the following is pseudo-code:
127
-
128
- ```ts
129
- import { SomeType } from '@modern-js/runtime/{namespace}';
130
-
131
- export const middleware: SomeType = (ctx, next) => {
132
- console.log(ctx.url);
133
- next();
134
- };
135
- ```
136
-
137
- By default, the framework extension capability of Web Server is turned off after installing the framework extension plugin. If you want to use the framework extension, you can turn it on through ['server.enableFrameworkExt'](/configure/app/server/enable-framework-ext.html).
138
-
139
- :::info
140
- The type name exported by the framework extension may not 'Middleware', but is named by the framework extension plugin.
141
- :::
@@ -1,13 +1,30 @@
1
- ```js title="modern.config.ts"
1
+ ```ts title="modern.config.ts"
2
2
  import { appTools, defineConfig } from '@modern-js/app-tools';
3
3
  import { garfishPlugin } from '@modern-js/plugin-garfish';
4
4
 
5
5
  export default defineConfig({
6
6
  runtime: {
7
7
  router: true,
8
- state: true,
9
- masterApp: true,
10
8
  },
11
9
  plugins: [appTools(), garfishPlugin()],
12
10
  });
11
+
12
+ ```
13
+
14
+ ```ts title="src/modern.runtime.ts"
15
+ import { defineRuntimeConfig } from '@modern-js/runtime';
16
+
17
+ export default defineRuntimeConfig({
18
+ masterApp: {
19
+ apps: [{
20
+ name: 'Table',
21
+ entry: 'http://localhost:8081',
22
+ // activeWhen: '/table'
23
+ }, {
24
+ name: 'Dashboard',
25
+ entry: 'http://localhost:8082'
26
+ // activeWhen: '/dashboard'
27
+ }]
28
+ },
29
+ });
13
30
  ```
@@ -1,18 +1,17 @@
1
- ```js title="src/App.tsx"
2
- import { defineConfig } from '@modern-js/runtime';
1
+ ```ts title="src/modern.runtime.ts"
2
+ import { defineRuntimeConfig } from '@modern-js/runtime';
3
3
 
4
- defineConfig(App, {
4
+ export default defineRuntimeConfig({
5
5
  masterApp: {
6
- apps: [
7
- {
8
- name: 'DashBoard',
9
- entry: 'http://127.0.0.1:8081/',
10
- },
11
- {
12
- name: 'TableList',
13
- entry: 'http://localhost:8082',
14
- },
15
- ],
6
+ apps: [{
7
+ name: 'Table',
8
+ entry: 'http://localhost:8081',
9
+ // activeWhen: '/table'
10
+ }, {
11
+ name: 'Dashboard',
12
+ entry: 'http://localhost:8082'
13
+ // activeWhen: '/dashboard'
14
+ }]
16
15
  },
17
16
  });
18
17
  ```
@@ -0,0 +1,27 @@
1
+ :::warning
2
+ Starting from `MAJOR_VERSION.67.0`, Modern.js no longer provides Reduck state management capabilities by default. If you need to use Reduck, you must install and register the state plugin.
3
+
4
+ **Installation Steps**
5
+
6
+ 1. Install the `@modern-js/plugin-state` dependency:
7
+
8
+ ```bash
9
+ pnpm add @modern-js/plugin-state
10
+ ```
11
+
12
+ 2. Register the state plugin:
13
+
14
+ ```ts title="modern.config.ts"
15
+ import { defineConfig } from '@modern-js/app-tools';
16
+ import { statePlugin } from '@modern-js/plugin-state';
17
+
18
+ export default defineConfig({
19
+ ...,
20
+ plugins: [
21
+ ...,
22
+ statePlugin(),
23
+ ],
24
+ });
25
+ ```
26
+
27
+ :::
File without changes
@@ -1,119 +1,95 @@
1
- ---
2
- title: Overview
3
- sidebar_position: 1
4
- ---
1
+ # Introduce
5
2
 
6
- # Overview
3
+ Modern.js runtime configuration should be centralized in the `src/modern.runtime.ts` file.
7
4
 
8
- This section describes configuration of the Runtime plugin.
9
-
10
- ## Configuration
11
-
12
- ### runtime
13
-
14
- - **Type:** `Object`
15
-
16
- The runtime is configured as follows:
5
+ :::info
6
+ If this file doesn't exist in your project yet, create it with the following command:
17
7
 
18
- #### Base
8
+ ```bash
9
+ touch src/modern.runtime.ts
10
+ ```
11
+ :::
19
12
 
20
- Configure in `modern.config.ts`:
13
+ ## Basic Configuration
21
14
 
22
- ```ts title="modern.config.ts"
23
- import { defineConfig } from '@modern-js/app-tools';
15
+ ```tsx
16
+ import { defineRuntimeConfig } from '@modern-js/runtime';
24
17
 
25
- export default defineConfig({
26
- runtime: {
27
- state: true,
28
- router: true,
18
+ export default defineRuntimeConfig({
19
+ router: {
20
+ // Router configuration
21
+ },
22
+ state: {
23
+ // State management configuration
29
24
  },
25
+ // Other runtime modules...
30
26
  });
31
27
  ```
32
28
 
33
- #### DefineConfig
34
-
35
- Configure using [`defineConfig`](/apis/app/runtime/app/define-config) API:
36
-
37
- :::info
38
- When there is a function in the runtime configuration, it can only be configured this way.
39
-
40
- :::
29
+ ## Multi-Entry Configuration
41
30
 
42
- import { Tabs, Tab as TabItem } from "@theme";
31
+ For multi-entry applications, `defineRuntimeConfig` can accept a function that returns specific configurations based on the entry name:
43
32
 
44
- <Tabs>
45
- <TabItem value="layout" label="Conventional Routing" default>
33
+ ```tsx
34
+ import { defineRuntimeConfig } from '@modern-js/runtime';
46
35
 
47
- ```tsx title="src/routes/layout.tsx"
48
- import type { AppConfig } from '@modern-js/runtime';
49
-
50
- export const config = (): AppConfig => {
51
- return {
52
- router: {
53
- supportHtml5History: false
54
- }
36
+ export default defineRuntimeConfig((entryName) => {
37
+ if (entryName === 'main') {
38
+ return {
39
+ router: {
40
+ // Router configuration for "main" entry
41
+ },
42
+ state: {
43
+ // State management configuration for "main" entry
44
+ },
45
+ };
55
46
  }
56
- };
57
- ```
58
-
59
- </TabItem>
60
-
61
- <TabItem value="app" label="Self-controlled Routing">
62
-
63
- ```ts title="src/App.tsx"
64
- import { defineConfig } from '@modern-js/runtime';
65
-
66
- const App = () => {
67
- /** */
68
- };
69
47
 
70
- defineConfig(App, {
71
- router: {
72
- supportHtml5History: false,
73
- },
48
+ // Configuration for other entries
49
+ return {
50
+ masterApp: {
51
+ // Micro-frontend configuration example
52
+ },
53
+ };
74
54
  });
75
-
76
- export default App;
77
55
  ```
56
+ :::tip
57
+ Using the `src/modern.runtime.ts` configuration approach does not support exporting asynchronous functions, which is related to the rendering method of Modern.js. If you need to add asynchronous logic, please use the **[Runtime Plugin](/plugin/introduction.html#runtime-plugin)**.
58
+ :::
78
59
 
79
- </TabItem>
80
- </Tabs>
81
-
82
- :::info
83
- Using runtime configuration, you can solve the problem that runtime plugin configuration needs to be at runtime to get specific content.
60
+ :::warning
61
+ Using the `src/modern.runtime.ts` configuration approach requires Modern.js version **MAJOR_VERSION.66.0** or higher.
62
+ :::
84
63
 
85
- Runtime plugin runtime configuration and configuration directly in `modern.config.ts` are merged by default, and runtime configuration takes precedence.
64
+ import RuntimeCliConfig from '@site-docs/components/runtime-cli-config';
86
65
 
87
- :::
66
+ <RuntimeCliConfig />
88
67
 
89
- :::warning
90
- The `defineConfig` API only accepts the specific configuration of Runtime plugins. Enabling the plugin is determined through `modern.config.ts` configuration."
68
+ ## Configuration Evolution
91
69
 
92
- :::
70
+ Before MAJOR_VERSION.66.0, runtime configurations were scattered across multiple locations:
93
71
 
94
- ### runtimeByEntries
72
+ 1. The `runtime` and `runtimeByEntries` fields in `modern.config.ts`
73
+ 2. The `App.config` or the `config` function exported from `layout` files for each entry
95
74
 
96
- - **Type:** `Object`
75
+ To improve maintainability, Modern.js introduced the unified `src/modern.runtime.ts` configuration entry.
97
76
 
98
- #### Introduction
77
+ ### Legacy Configuration (Compatible but Not Recommended)
99
78
 
100
- Add the runtime configuration according to the entry. The option attribute is consistent with the runtime. The specified value will be replaced and merged with the content of the runtime attribute.
79
+ ```ts
80
+ // modern.config.ts
81
+ export default {
82
+ runtime: { /* ... */ },
83
+ runtimeByEntries: { /* ... */ },
84
+ };
101
85
 
102
- ```ts title="modern.config.ts"
103
- import { defineConfig } from '@modern-js/app-tools';
86
+ // App.config
87
+ App.config = {/* ... */}
104
88
 
105
- export default defineConfig({
106
- runtime: {
107
- state: false,
108
- },
109
- runtimeByEntries: {
110
- entry1: {
111
- state: true, // { state: true }
112
- },
113
- entry2: {
114
- // { state: false, router: true }
115
- router: true,
116
- },
117
- },
118
- });
89
+ // layout file
90
+ export const config = () => { /* Dynamic configuration logic */ };
119
91
  ```
92
+
93
+ ### Migration Recommendation
94
+
95
+ We strongly recommend migrating all runtime configurations to `src/modern.runtime.ts`. Although the legacy configuration approach is still compatible, it is planned to be gradually deprecated in future versions. A unified configuration entry prevents scattered configurations and significantly improves project maintainability.