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
{{ message }}
Repository navigation
Commit 87695fd
Browse filesBrowse the repository at this point in the historyBrowse files
During server rendering, `use(browser())`stops rendering the component and leaves the closest [`<Suspense>`](/reference/react/Suspense) boundary's fallback in its place. In the browser, `use(browser())`returns`undefined`, so the component renders normally.
* **optional** `reason`: A string or function that explains why the content needs to render in the browser. The string or the function's return value becomes the `cause` of the `Error` passed to [`onBrowserBailout`](#reporting-browser-only-rendering-on-the-server). React calls a reason function each time a server renderer encounters the value returned by `browser`, but does not call it in the browser. If creating the reason is expensive, pass a function such as `() =>newError(...)`.
`browser`returns an opaque value that you can pass to `use`in a component or use as the reason when [aborting a server render](#aborting-pending-server-rendering-for-the-browser). In the browser, passing this value to `use`returns`undefined`.
You can use this instead of checking `typeofwindow`, waiting for an [`Effect`](/reference/react/useEffect) to set mounted state, or using a framework option to disable server rendering.
61
+
これは、`typeofwindow` を確認する、マウント済み state が[エフェクト](/reference/react/useEffect)で設定されるまで待機する、フレームワークのオプションでサーバレンダリングを無効にする、といったテクニックの代わりに使用できるものです。
62
62
63
-
Click **Reload** to see the loading fallback in the initial HTML. After hydration, React displays the draft loaded from `localStorage`.
63
+
以下の例で **Reload** をクリックすると、初期 HTML 内のローディングフォールバックを確認できます。ハイドレーション後、React は `localStorage` から読み込んだ下書きを表示します。
64
64
65
65
<Sandpack>
66
66
@@ -206,7 +206,7 @@ iframe {
206
206
207
207
<Note>
208
208
209
-
`use(browser())`must be called from a Client Component. If your framework uses Server Components by default, add the [`'use client'`](/reference/rsc/use-client) directive to that file or move the call to a child Client Component:
Like other calls to [`use`](/reference/react/use), `use(browser())`can be called inside a conditional statement or after an early return. This lets a Component or custom Hook opt out of server rendering based on a condition, such as the value of a prop.
For example, this `useTimeZone`Hook accepts an optional default value. When provided, React renders the default value in the initial HTML and in the browser. Without a default value, the Component suspends during server rendering and shows the device's local time zone in the browser.
232
+
例えば、以下の `useTimeZone`フックは、省略可能なデフォルト値を受け取ります。React はデフォルト値が渡されるとその値を初期 HTML とブラウザで表示します。デフォルト値がない場合、コンポーネントはサーバレンダリング中にサスペンドし、ブラウザではデバイスのローカルタイムゾーンを表示します。
233
233
234
-
Click **Reload** to see the loading fallback before the user's time zone appears.
@@ -391,13 +391,13 @@ function ProductDetails({ productId, initialData }) {
391
391
}
392
392
```
393
393
394
-
With `initialData`, React renders the Component to HTML on the server. Without it, React leaves the closest [`<Suspense>`](/reference/react/Suspense) boundary's fallback in the HTML. In the browser, `useQuery`can fetch the data or read it from its client cache as usual.
394
+
`initialData` がある場合、React はサーバでコンポーネントを HTML にレンダーします。ない場合は、最も近い [`<Suspense>`](/reference/react/Suspense) バウンダリのフォールバックを HTML に残します。ブラウザでは、`useQuery`が通常通りデータを取得したり、クライアント側のキャッシュから読み取ったりできます。
395
395
396
396
---
397
397
398
-
### Reporting browser-only rendering on the server {/*reporting-browser-only-rendering-on-the-server*/}
Pass an `onBrowserBailout`callback to the server renderer to report browser-only rendering. When React leaves a Suspense fallback for the browser, it does not call the server renderer's `onError`callback or [`hydrateRoot`'s `onRecoverableError`](/reference/react-dom/client/hydrateRoot#error-logging-in-production) callback. This example also passes a reason, which is available as the reported error's `cause`:
The reason function can return any value. Return a new `Error`to give the cause its own stack without creating the `Error`in the browser. React does not serialize the reason into the HTML.
436
+
理由を生成する関数は、どのような値でも返せます。新しい `Error`を返す関数を使えば、原因を表すエラーに独自スタックを持たせつつ、ブラウザでは `Error`を作成しないようにできます。React は理由を HTML にシリアライズしません。
437
437
438
-
If there is no Suspense boundary to provide a fallback, the server render fails. React reports the failure through the renderer's usual error callbacks instead of `onBrowserBailout`.
If you call a server rendering API directly, you can stop waiting for pending content and let the browser finish rendering it. Pass the value returned by `browser`as the reason when aborting the server render. React then leaves pending Suspense boundaries in their fallback state and renders their content in the browser:
444
+
サーバレンダリング API を直接呼び出している場合、まだ完了していないコンテンツの待機をやめて、ブラウザにレンダー完了を引き継がせることが可能です。サーバでのレンダーを中止する際に、`browser`の返した値を理由として渡してください。すると React は、まだ完了していないサスペンスバウンダリをフォールバックの状態のまま残し、そのコンテンツをブラウザでレンダーします。
A`browser`abort reason does not trigger the server renderer's `onError`callback or `hydrateRoot`'s `onRecoverableError`callback. Instead, the server renderer reports each recovered Suspense boundary to `onBrowserBailout`.
For server rendering APIs that accept an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal), pass `browser()` as the reason to [`AbortController.abort`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort).
462
+
[`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) を受け取るサーバレンダリング API では、[`AbortController.abort`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort) に中止の理由として `browser()` を渡してください。
0 commit comments