You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/rsc/server-components.md
+33-33Lines changed: 33 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -5,28 +5,28 @@ canary: true
5
5
6
6
<Intro>
7
7
8
-
Server Components are a new type of Component that renders ahead of time, before bundling, in an environment separate from your client app or SSR server.
8
+
サーバコンポーネントは新しいタイプのコンポーネントです。クライアントアプリケーションや SSR サーバとは別の環境で、バンドル前に事前にレンダーされます。
9
9
10
10
</Intro>
11
11
12
-
This separate environment is the "server" in React Server Components. Server Components can run once at build time on your CI server, or they can be run for each request using a web server.
12
+
React Server Components の "server" とはこの別の環境を指しています。サーバコンポーネントは、CI サーバでビルド時に一度だけ実行することも、ウェブサーバを使用してリクエストごとに実行することもできます。
13
13
14
14
<InlineToc />
15
15
16
16
<Note>
17
17
18
-
#### How do I build support for Server Components? {/*how-do-i-build-support-for-server-components*/}
While React Server Components in React 19 are stable and will not break between major versions, the underlying APIs used to implement a React Server Components bundler or framework do not follow semver and may break between minors in React 19.x.
20
+
React 19 の React Server Components は安定しており、マイナーバージョン間での破壊的変更はありませんが、サーバコンポーネントのバンドラやフレームワークを実装するために使用される基盤となる API は semver に従いません。React 19.x のマイナーバージョン間で変更が生じる可能性があります。
21
21
22
-
To support React Server Components as a bundler or framework, we recommend pinning to a specific React version, or using the Canary release. We will continue working with bundlers and frameworks to stabilize the APIs used to implement React Server Components in the future.
22
+
React Server Components をバンドラやフレームワークでサポートする場合は、特定の React バージョンに固定するか、Canary リリースを使用することをお勧めします。React Server Components を実装するために使用される API を安定化させるため、今後もバンドラやフレームワークと連携を続けていきます。
23
23
24
24
</Note>
25
25
26
-
### Server Components without a Server {/*server-components-without-a-server*/}
27
-
Server components can run at build time to read from the filesystem or fetch static content, so a web server is not required. For example, you may want to read static data from a content management system.
This pattern means users need to download and parse an additional 75K (gzipped) of libraries, and wait for a second request to fetch the data after the page loads, just to render static content that will not change for the lifetime of the page.
importmarkedfrom'marked'; // Not included in bundle
@@ -69,34 +69,34 @@ async function Page({page}) {
69
69
}
70
70
```
71
71
72
-
The rendered output can then be server-side rendered (SSR) to HTML and uploaded to a CDN. When the app loads, the client will not see the original `Page`component, or the expensive libraries for rendering the markdown. The client will only see the rendered output:
72
+
このレンダー出力は、サーバサイドレンダリング (SSR) で HTML に変換され、CDN にアップロードできます。アプリがロードされる際、クライアントには元の `Page`コンポーネントの存在や、Markdown をレンダーするための高コストなライブラリの存在は見えません。レンダーされた出力が見えるだけです。
73
73
74
74
```js
75
75
<div><!-- html for markdown --></div>
76
76
```
77
77
78
-
This means the content is visible during first page load, and the bundle does not include the expensive libraries needed to render the static content.
### Server Components with a Server {/*server-components-with-a-server*/}
97
-
Server Components can also run on a web server during a request for a page, letting you access your data layer without having to build an API. They are rendered before your application is bundled, and can pass data and JSX as props to Client Components.
With Server Components, you can read the data and render it in the component:
148
+
サーバコンポーネントを使用することで、コンポーネントの中で直接データを読み取ってレンダーできます。
149
149
150
150
```js
151
151
importdbfrom'./database';
@@ -169,7 +169,7 @@ async function Author({id}) {
169
169
}
170
170
```
171
171
172
-
The bundler then combines the data, rendered Server Components and dynamic Client Components into a bundle. Optionally, that bundle can then be server-side rendered (SSR) to create the initial HTML for the page. When the page loads, the browser does not see the original `Note`and`Author`components; only the rendered output is sent to the client:
172
+
この後バンドラは、データ、レンダー済みのサーバコンポーネント、および動的なクライアントコンポーネントをバンドルとして結合します。オプションとして、そのバンドルをサーバサイドレンダリング (SSR) して、ページの初期 HTML を作成できます。ページがロードされると、ブラウザには元の `Note`および`Author`コンポーネントの存在は見えません。クライアントにはレンダーされた出力のみが送信されます。
173
173
174
174
```js
175
175
<div>
@@ -178,24 +178,24 @@ The bundler then combines the data, rendered Server Components and dynamic Clien
178
178
</div>
179
179
```
180
180
181
-
Server Components can be made dynamic by re-fetching them from a server, where they can access the data and render again. This new application architecture combines the simple “request/response” mental model of server-centric Multi-Page Apps with the seamless interactivity of client-centric Single-Page Apps, giving you the best of both worlds.
Server Components are not sent to the browser, so they cannot use interactive APIs like `useState`. To add interactivity to Server Components, you can compose them with Client Component using the `"use client"`directive.
185
+
サーバコンポーネントはブラウザに送信されないため、`useState` のようなインタラクティブな API を使用できません。サーバコンポーネントにインタラクティビティを追加するには、`"use client"`ディレクティブを使用してクライアントコンポーネントと組み合わせます。
186
186
187
187
<Note>
188
188
189
-
#### There is no directive for Server Components. {/*there-is-no-directive-for-server-components*/}
A common misunderstanding is that Server Components are denoted by `"use server"`, but there is no directive for Server Components. The `"use server"` directive is used for Server Actions.
In the following example, the `Notes`Server Component imports an `Expandable`Client Component that uses state to toggle its `expanded`state:
198
+
以下の例では、サーバコンポーネントである `Notes`がクライアントコンポーネントである `Expandable`をインポートしており、そこで state を使用して `expanded`をトグルしています。
199
199
```js
200
200
// Server Component
201
201
importExpandablefrom'./Expandable';
@@ -232,7 +232,7 @@ export default function Expandable({children}) {
232
232
}
233
233
```
234
234
235
-
This works by first rendering `Notes`as a Server Component, and then instructing the bundler to create a bundle for the Client Component `Expandable`. In the browser, the Client Components will see output of the Server Components passed as props:
Server Components introduce a new way to write Components using async/await. When you `await`in an async component, React will suspend and wait for the promise to resolve before resuming rendering. This works across server/client boundaries with streaming support for Suspense.
You can even create a promise on the server, and await it on the client:
259
+
サーバでプロミスを作成し、それをクライアント側で待機することすら可能です。
260
260
261
261
```js
262
262
// Server Component
@@ -292,6 +292,6 @@ function Comments({commentsPromise}) {
292
292
}
293
293
```
294
294
295
-
The `note`content is important data for the page to render, so we `await`it on the server. The comments are below the fold and lower-priority, so we start the promise on the server, and wait for it on the client with the `use` API. This will Suspend on the client, without blocking the `note`content from rendering.
295
+
`note`の内容はページをレンダーするために重要なデータなので、サーバ側で `await`します。コメントは折りたたまれており優先度が低いため、サーバではプロミスを開始だけして、クライアントで `use` API を使用してそれを待機します。これによりクライアント側でサスペンドが起きますが、`note`の内容のレンダーをブロックしないで済みます。
296
296
297
-
Since async components are [not supported on the client](#why-cant-i-use-async-components-on-the-client), we await the promise with `use`.
0 commit comments