Skip to content

Commit c231048

Browse files
committed
Use Canary markers in browser guidance
1 parent 166fd5b commit c231048

4 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎src/content/reference/react-dom/client/hydrateRoot.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ export default function App() {
319319
320320
This way the initial render pass will render the same content as the server, avoiding mismatches, but an additional pass will happen synchronously right after hydration.
321321
322-
Use this approach when you need to render different content on the server and in the browser. If a component should render only in the browser, call [`use(browser())`](/reference/react/use#use-browser) in Canary instead of waiting for an Effect.
322+
Use this approach when you need to render different content on the server and in the browser.
323+
324+
<Canary>If a component should render only in the browser, call [`use(browser())`](/reference/react/use#use-browser) instead of waiting for an Effect.</Canary>
323325
324326
<Pitfall>
325327

‎src/content/reference/react/Suspense.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,8 +2372,6 @@ function Chat() {
23722372
23732373
The server HTML will include the loading indicator. It will be replaced by the `Chat` component on the client.
23742374
2375-
If you're using Canary, call [`use(browser())`](/reference/react/use#use-browser) instead of throwing an error to mark a component as browser-only.
2376-
23772375
---
23782376
23792377
### <CanaryBadge /> Providing a fallback for browser-only content {/*providing-a-fallback-for-browser-only-content*/}

‎src/content/reference/react/apis.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ In addition to [Hooks](/reference/react/hooks) and [Components](/reference/react
2727

2828
To read a value from a resource, use this API:
2929

30-
* [`use`](/reference/react/use) lets you read the value of a resource like a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or [context](/learn/passing-data-deeply-with-context). In Canary, [`use(browser())`](/reference/react/use#use-browser) marks a component as browser-only during server rendering.
30+
* [`use`](/reference/react/use) lets you read the value of a resource like a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or [context](/learn/passing-data-deeply-with-context).
31+
* <CanaryBadge /> [`use(browser())`](/reference/react/use#use-browser) marks a component as browser-only during server rendering.
3132
```js
3233
function MessageComponent({ messagePromise }) {
3334
const message = use(messagePromise);

‎src/content/reference/react/useLayoutEffect.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,9 @@ However, if you're running into this problem, you have a few different options:
734734
735735
- Replace `useLayoutEffect` with [`useEffect`.](/reference/react/useEffect) This tells React that it's okay to display the initial render result without blocking the paint (because the original HTML will become visible before your Effect runs).
736736
737-
- Alternatively, [mark your component as client-only.](/reference/react/Suspense#providing-a-fallback-for-server-errors-and-client-only-content) This tells React to replace its content up to the closest [`<Suspense>`](/reference/react/Suspense) boundary with a loading fallback (for example, a spinner or a glimmer) during server rendering. If you're using Canary, call [`use(browser())`](/reference/react/use#use-browser) instead of throwing an error.
737+
- <CanaryBadge /> Alternatively, call [`use(browser())`](/reference/react/use#use-browser) to mark the component as browser-only. React will replace its content up to the closest [`<Suspense>`](/reference/react/Suspense) boundary with a loading fallback (for example, a spinner or a glimmer) during server rendering.
738+
739+
- Alternatively, [mark your component as client-only.](/reference/react/Suspense#providing-a-fallback-for-server-errors-and-client-only-content) This tells React to replace its content up to the closest `<Suspense>` boundary with a loading fallback during server rendering.
738740
739741
- Alternatively, you can render a component with `useLayoutEffect` only after hydration. Keep a boolean `isMounted` state that's initialized to `false`, and set it to `true` inside a `useEffect` call. Your rendering logic can then be like `return isMounted ? <RealContent /> : <FallbackContent />`. On the server and during the hydration, the user will see `FallbackContent` which should not call `useLayoutEffect`. Then React will replace it with `RealContent` which runs on the client only and can include `useLayoutEffect` calls.
740742

0 commit comments

Comments
 (0)