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
docs: rewrite Client/Server definitions with symmetrical framing
Separate component type (module boundaries) from rendering (framework
decides where code runs). Define Client Components as code sent to the
client, optionally prerendered to HTML ahead of time.
Addresses maintainer feedback on #8489 from @gaearon.
Copy file name to clipboardExpand all lines: src/content/reference/rsc/use-client.md
+9-5Lines changed: 9 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -151,18 +151,22 @@ In the module dependency tree of this example app, the `'use client'` directive
151
151
`'use client'` segments the module dependency tree of the React Server Components app, marking `InspirationGenerator.js` and all of its dependencies as client-rendered.
152
152
</Diagram>
153
153
154
-
During render, the framework will server-render the root component and continue through the [render tree](/learn/understanding-your-ui-as-a-tree#the-render-tree). Client Components are also pre-rendered on the server to HTML. Their module source code is bundled for the client separately from Server Components.
154
+
There are two separate concepts to understand: **component type** and **rendering**.
155
155
156
-
The rendered HTML is sent to the client. The client downloads the client bundles and hydrates Client Components, attaching event handlers and other client-only behavior.
156
+
**Component type** is determined by the React tree and module boundaries. When the framework walks the [render tree](/learn/understanding-your-ui-as-a-tree#the-render-tree), each component usage is either a Client Component or a Server Component based on whether its module is marked with `'use client'` or is a transitive dependency of one.
157
+
158
+
**Rendering** is where and when those component usages are evaluated and turned into output (such as HTML). This is determined by the framework and the render pass. Server Components are evaluated on the server. Client Components are sent to the client as executable code. Frameworks may also prerender Client Components to HTML ahead of time so the page can display before client code loads.
159
+
160
+
On the client, the framework downloads the Client Component bundles and hydrates any prerendered Client Components, attaching event handlers and other client-only behavior.
157
161
158
162
<Diagramname="use_client_render_tree"height={250}width={500}alt="A tree graph where each node represents a component and its children as child components. The top-level node is labelled 'App' and it has two child components 'InspirationGenerator' and 'FancyText'. 'InspirationGenerator' has two child components, 'FancyText' and 'Copyright'. Both 'InspirationGenerator' and its child component 'FancyText' are marked to be client-rendered.">
159
163
The render tree for the React Server Components app. `InspirationGenerator` and its child component `FancyText` are components exported from client-marked code and considered Client Components.
160
164
</Diagram>
161
165
162
166
We introduce the following definitions:
163
167
164
-
***Client Components** are component usages whose module is marked with `'use client'` or is a transitive dependency of one. They can be pre-rendered on the server and are hydrated on the client.
165
-
***Server Components** are component usages that are not Client Components. They are rendered on the server only.
168
+
***Client Components** are component usages whose module is marked with `'use client'` or is a transitive dependency of one. Their code is sent to the client. They may also be prerendered to HTML ahead of time.
169
+
***Server Components** are component usages that are not Client Components. They run only on the server and are never sent to the client as executable code.
166
170
167
171
Working through the example app, `App`, `FancyText` and `Copyright` are considered Server Components. As `InspirationGenerator.js` and its transitive dependencies are marked as client code, the component usages `InspirationGenerator` and its child `FancyText` are Client Components.
168
172
@@ -206,7 +210,7 @@ Back to the question of `FancyText`, we see that the component definition does _
206
210
207
211
The usage of `FancyText` as a child of `App`, marks that usage as a Server Component. When `FancyText` is imported and called under `InspirationGenerator`, that usage of `FancyText` is a Client Component as `InspirationGenerator` contains a `'use client'` directive.
208
212
209
-
This means that the component definition for `FancyText`will both be evaluated on the server and also downloaded by the client to render its Client Component usage.
213
+
This means that the component definition for `FancyText`is evaluated for its Server Component usage during the initial render, and its code is also sent to the client to render its Client Component usage.
0 commit comments