-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/renovate
- Loading branch information
Showing
10 changed files
with
157 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@modern-js/runtime': minor | ||
'@modern-js/server-core': minor | ||
--- | ||
|
||
feat: support <NoSSRCache> Component, only use ssr.mode='string' | ||
|
||
feat: 支持 <NoSSRCache> 组件, 仅在 ssr.mode 为 'string'的时候生效 |
48 changes: 48 additions & 0 deletions
48
packages/document/main-doc/docs/en/apis/app/runtime/ssr/no-ssr-cache.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: NoSSRCache | ||
--- | ||
# NoSSRCache | ||
|
||
With the NoSSRCache component, Modern.js does not cache the server-side rendering (SSR) results of the current page. | ||
|
||
:::note | ||
This component is currently only available if `ssr.mode` is `string`. | ||
::: | ||
|
||
## Usage | ||
|
||
```tsx | ||
import { NoSSRCache } from '@modern-js/runtime/ssr'; | ||
|
||
export default () => { | ||
return ( | ||
<div> | ||
<NoSSRCache /> | ||
... | ||
</div> | ||
); | ||
} | ||
``` | ||
|
||
## Example | ||
|
||
In the following code, after using `useLoaderData` to fetch data, the current page is cached or not based on the data fetched. For this case, use `NoSSRCache`: | ||
|
||
```tsx | ||
import { useLoaderData } from '@modern-js/runtim/router'; | ||
import { NoSSRCache } from '@modern-js/runtime/ssr'; | ||
|
||
function User() { | ||
const { data } = useLoaderData(); | ||
return ( | ||
<div> | ||
{ !data ? <NoSSRCache /> : null } | ||
... | ||
</div> | ||
); | ||
} | ||
``` | ||
|
||
## Scene | ||
|
||
This can be used if you need to decide whether the current page needs to cache the server-side rendering (SSR) results based on the current page fetching the data (e.g., whether the request was successful or whether a field exists in the returned result). |
48 changes: 48 additions & 0 deletions
48
packages/document/main-doc/docs/zh/apis/app/runtime/ssr/no-ssr-cache.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: NoSSRCache | ||
--- | ||
# NoSSRCache | ||
|
||
使用了 NoSSRCache 组件后,Modern.js 不会将当前页面的服务器端渲染(SSR)结果进行缓存。 | ||
|
||
:::note | ||
该组件目前仅在 `ssr.mode` 为 `string` 的情况可以使用。 | ||
::: | ||
|
||
## 使用姿势 | ||
|
||
```tsx | ||
import { NoSSRCache } from '@modern-js/runtime/ssr'; | ||
|
||
export default () => { | ||
return ( | ||
<div> | ||
<NoSSRCache /> | ||
... | ||
</div> | ||
); | ||
} | ||
``` | ||
|
||
## 示例 | ||
|
||
下列代码中,使用 `useLoaderData` 获取数据后,根据请求数据的结果决定是否缓存当前页面的服务端渲染结果。针对这种情况可以使用 `NoSSRCache` 组件: | ||
|
||
```tsx | ||
import { useLoaderData } from '@modern-js/runtim/router'; | ||
import { NoSSRCache } from '@modern-js/runtime/ssr'; | ||
|
||
function User() { | ||
const { data } = useLoaderData(); | ||
return ( | ||
<div> | ||
{ !data ? <NoSSRCache /> : null } | ||
... | ||
</div> | ||
); | ||
} | ||
``` | ||
|
||
## 使用场景 | ||
|
||
如果需要根据当前页面获取数据的情况(比如是否请求成功或者返回结果中是否存在某个字段),决定是否需要将当前页面的服务端渲染(SSR)结果进行缓存,则可以使用这种方式来解决。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { PreRender } from './prerender'; | ||
export { NoSSR } from './nossr'; | ||
export { NoSSRCache } from './no-ssr-cache'; |
10 changes: 10 additions & 0 deletions
10
packages/runtime/plugin-runtime/src/core/server/react/no-ssr-cache/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import { Helmet } from '../../../../exports/head'; | ||
|
||
export const NoSSRCache = () => { | ||
return ( | ||
<Helmet> | ||
<meta name="no-ssr-cache" /> | ||
</Helmet> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
tests/integration/ssr/fixtures/base/src/routes/no-ssr-cache/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Outlet } from '@modern-js/runtime/router'; | ||
import { NoSSRCache } from '@modern-js/runtime/ssr'; | ||
|
||
export default function Layout() { | ||
return ( | ||
<div> | ||
No SSR Cache layout | ||
<NoSSRCache /> | ||
{<Outlet />} | ||
</div> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/integration/ssr/fixtures/base/src/routes/no-ssr-cache/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Outlet } from '@modern-js/runtime/router'; | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
No SSR Cache | ||
<Outlet /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters