@modern-js/main-doc 0.0.0-next-1678795030145 → 0.0.0-next-1678861353129
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/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @modern-js/main-doc
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-1678861353129
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
fix: 修复文档站 info 不生效问题
|
|
10
10
|
|
|
11
|
-
- @modern-js/builder-doc@0.0.0-next-
|
|
11
|
+
- @modern-js/builder-doc@0.0.0-next-1678861353129
|
|
12
12
|
|
|
13
13
|
## 2.8.0
|
|
14
14
|
|
|
@@ -8,12 +8,14 @@ In Modern.js, SSR also works out of the box. Developers do not need to write com
|
|
|
8
8
|
|
|
9
9
|
Enabling SSR is very easy, just set ['server.ssr'](/configure/app/server/ssr) to `true`:
|
|
10
10
|
|
|
11
|
-
```
|
|
12
|
-
{
|
|
11
|
+
```ts title="modern.config.ts"
|
|
12
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
13
|
+
|
|
14
|
+
export default defineConfig({
|
|
13
15
|
"server": {
|
|
14
|
-
"ssr": true
|
|
15
|
-
}
|
|
16
|
-
}
|
|
16
|
+
"ssr": true,
|
|
17
|
+
},
|
|
18
|
+
})
|
|
17
19
|
```
|
|
18
20
|
|
|
19
21
|
## SSR Data Fetch
|
|
@@ -293,14 +295,16 @@ Be sure to filter the `host` field if you really need to pass through all reques
|
|
|
293
295
|
|
|
294
296
|
Modern.js supports streaming rendering in React 18. Opt in it with the following configuration:
|
|
295
297
|
|
|
296
|
-
```
|
|
297
|
-
{
|
|
298
|
+
```ts title="modern.config.ts"
|
|
299
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
300
|
+
|
|
301
|
+
export default defineConfig({
|
|
298
302
|
"server": {
|
|
299
303
|
"ssr": {
|
|
300
|
-
"mode": "stream"
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
+
"mode": "stream",
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
})
|
|
304
308
|
```
|
|
305
309
|
|
|
306
310
|
The streaming SSR of Modern.js is implemented based on React Router, and the main APIs involved are:
|
|
@@ -383,7 +387,7 @@ export default ({ params }: LoaderFunctionArgs) => {
|
|
|
383
387
|
|
|
384
388
|
Use the `Await` component to render the data returned asynchronously from the Data Loader. For example:
|
|
385
389
|
|
|
386
|
-
```
|
|
390
|
+
```tsx title='page.tsx'
|
|
387
391
|
import { Await, useLoaderData } from '@modern-js/runtime/router';
|
|
388
392
|
import { Suspense } from 'react';
|
|
389
393
|
import type { Data } from './page.loader';
|
|
@@ -425,8 +429,7 @@ So, here we import like this: `import type { Data } from './page.loader'`;
|
|
|
425
429
|
|
|
426
430
|
You can also get the asynchronous data returned by Data Loader through `useAsyncValue`. For example:
|
|
427
431
|
|
|
428
|
-
```
|
|
429
|
-
```ts title='page.tsx'
|
|
432
|
+
```tsx title='page.tsx'
|
|
430
433
|
import { useAsyncValue } from '@modern-js/runtime/router';
|
|
431
434
|
|
|
432
435
|
// skip some codes
|
|
@@ -480,7 +483,7 @@ export default () => {
|
|
|
480
483
|
|
|
481
484
|
Then use `useAsyncError` to get the error, and assign the component used to render the error to the `errorElement` property of the `Await` component:
|
|
482
485
|
|
|
483
|
-
```
|
|
486
|
+
```tsx title='page.ts'
|
|
484
487
|
import { Await, useAsyncError, useLoaderData } from '@modern-js/runtime/router';
|
|
485
488
|
import { Suspense } from 'react';
|
|
486
489
|
|
package/package.json
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "0.0.0-next-
|
|
14
|
+
"version": "0.0.0-next-1678861353129",
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"registry": "https://registry.npmjs.org/",
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@modern-js/builder-doc": "0.0.0-next-
|
|
20
|
+
"@modern-js/builder-doc": "0.0.0-next-1678861353129"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"ts-node": "^10",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"fs-extra": "^10",
|
|
26
26
|
"@types/node": "^16",
|
|
27
27
|
"@types/fs-extra": "^9",
|
|
28
|
-
"@modern-js/builder-doc": "0.0.0-next-
|
|
28
|
+
"@modern-js/builder-doc": "0.0.0-next-1678861353129"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "npx ts-node ./scripts/sync.ts"
|
|
@@ -8,12 +8,14 @@ sidebar_position: 3
|
|
|
8
8
|
|
|
9
9
|
启用 SSR 非常简单,只需要设置 [`server.ssr`](/configure/app/server/ssr) 为 `true` 即可:
|
|
10
10
|
|
|
11
|
-
```
|
|
12
|
-
{
|
|
11
|
+
```ts title="modern.config.ts"
|
|
12
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
13
|
+
|
|
14
|
+
export default defineConfig({
|
|
13
15
|
"server": {
|
|
14
|
-
"ssr": true
|
|
15
|
-
}
|
|
16
|
-
}
|
|
16
|
+
"ssr": true,
|
|
17
|
+
},
|
|
18
|
+
})
|
|
17
19
|
```
|
|
18
20
|
|
|
19
21
|
## SSR 时的数据获取
|
|
@@ -282,14 +284,16 @@ export const loader = () => {
|
|
|
282
284
|
|
|
283
285
|
Modern.js 支持了 React 18 的流式渲染,可以通过如下配置启用:
|
|
284
286
|
|
|
285
|
-
```
|
|
286
|
-
{
|
|
287
|
+
```ts title="modern.config.ts"
|
|
288
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
289
|
+
|
|
290
|
+
export default defineConfig({
|
|
287
291
|
"server": {
|
|
288
292
|
"ssr": {
|
|
289
|
-
"mode": "stream"
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
+
"mode": "stream",
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
})
|
|
293
297
|
```
|
|
294
298
|
|
|
295
299
|
Modern.js 的流式渲染基于 React Router 实现,主要涉及 API 有:
|
|
@@ -372,7 +376,7 @@ export default ({ params }: LoaderFunctionArgs) => {
|
|
|
372
376
|
|
|
373
377
|
通过 `Await` 组件,可以获取到 Data Loader 中异步返回的数据,然后进行渲染。例如:
|
|
374
378
|
|
|
375
|
-
```
|
|
379
|
+
```tsx title='page.tsx'
|
|
376
380
|
import { Await, useLoaderData } from '@modern-js/runtime/router';
|
|
377
381
|
import { Suspense } from 'react';
|
|
378
382
|
import type { Data } from './page.loader';
|
|
@@ -413,8 +417,8 @@ export default Page;
|
|
|
413
417
|
|
|
414
418
|
也可以通过 `useAsyncValue` 获取 Data Loader 返回的异步数据。例如:
|
|
415
419
|
|
|
416
|
-
|
|
417
|
-
```
|
|
420
|
+
|
|
421
|
+
```tsx title='page.tsx'
|
|
418
422
|
import { useAsyncValue } from '@modern-js/runtime/router';
|
|
419
423
|
|
|
420
424
|
// 省略部分代码
|
|
@@ -468,7 +472,7 @@ export default () => {
|
|
|
468
472
|
|
|
469
473
|
然后通过 `useAsyncError` 获取错误,并将用于渲染错误信息的组件赋值给 `Await` 组件的 `errorElement` 属性:
|
|
470
474
|
|
|
471
|
-
```
|
|
475
|
+
```tsx title='page.ts'
|
|
472
476
|
import { Await, useAsyncError, useLoaderData } from '@modern-js/runtime/router';
|
|
473
477
|
import { Suspense } from 'react';
|
|
474
478
|
|
|
@@ -25,7 +25,7 @@ Modern.js 提供了快速生成 Mock 数据的功能,能够让前端独立自
|
|
|
25
25
|
`config/mock/index.ts` 文件只需要导出一个包含所有 Mock API 的对象,对象的属性由请求配置 `method` 和 `url` 组成,对应的属性值可以为 `Object`、`Array`、`Function`:
|
|
26
26
|
|
|
27
27
|
```js
|
|
28
|
-
|
|
28
|
+
export default {
|
|
29
29
|
/* 属性为具体的 method 和 请求 url,值为 object 或 array 作为请求的结果 */
|
|
30
30
|
'GET /api/getInfo': { data: [1, 2, 3, 4] },
|
|
31
31
|
|