mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-24 04:33:10 +00:00
Capitalize Client in "client modules" (#6419)
Summary of changes: See <https://github.com/reactjs/react.dev/pull/6417> Co-authored-by: xuan.huang <xuan.huang@bytedance.com>
This commit is contained in:
@@ -51,14 +51,14 @@ As dependencies of `RichTextEditor`, `formatDate` and `Button` will also be eval
|
||||
* When a `'use client'` module is imported from another client-rendered module, the directive has no effect.
|
||||
* When a component module contains a `'use client'` directive, any usage of that component is guaranteed to be a Client Component. However, a component can still be evaluated on the client even if it does not have a `'use client'` directive.
|
||||
* A component usage is considered a Client Component if it is defined in module with `'use client'` directive or when it is a transitive dependency of a module that contains a `'use client'` directive. Otherwise, it is a Server Component.
|
||||
* Code that is marked for client evaluation is not limited to components. All code that is a part of the client module sub-tree is sent to and run by the client.
|
||||
* Code that is marked for client evaluation is not limited to components. All code that is a part of the Client module sub-tree is sent to and run by the client.
|
||||
* When a server evaluated module imports values from a `'use client'` module, the values must either be a React component or [supported serializable prop values](#passing-props-from-server-to-client-components) to be passed to a Client Component. Any other use case will throw an exception.
|
||||
|
||||
### How `'use client'` marks client code {/*how-use-client-marks-client-code*/}
|
||||
|
||||
In a React app, components are often split into separate files, or [modules](/learn/importing-and-exporting-components#exporting-and-importing-a-component).
|
||||
|
||||
For apps that use React Server Components, the app is server-rendered by default. `'use client'` introduces a server-client boundary in the [module dependency tree](/learn/understanding-your-ui-as-a-tree#the-module-dependency-tree), effectively creating a subtree of client modules.
|
||||
For apps that use React Server Components, the app is server-rendered by default. `'use client'` introduces a server-client boundary in the [module dependency tree](/learn/understanding-your-ui-as-a-tree#the-module-dependency-tree), effectively creating a subtree of Client modules.
|
||||
|
||||
To better illustrate this, consider the following React Server Components app.
|
||||
|
||||
@@ -145,7 +145,7 @@ export default [
|
||||
|
||||
</Sandpack>
|
||||
|
||||
In the module dependency tree of this example app, the `'use client'` directive in `InspirationGenerator.js` marks that module and all of its transitive dependencies as client modules. The subtree starting at `InspirationGenerator.js` is now marked as client modules.
|
||||
In the module dependency tree of this example app, the `'use client'` directive in `InspirationGenerator.js` marks that module and all of its transitive dependencies as Client modules. The subtree starting at `InspirationGenerator.js` is now marked as Client modules.
|
||||
|
||||
<Diagram name="use_client_module_dependency" height={250} width={545} alt="A tree graph with the top node representing the module 'App.js'. 'App.js' has three children: 'Copyright.js', 'FancyText.js', and 'InspirationGenerator.js'. 'InspirationGenerator.js' has two children: 'FancyText.js' and 'inspirations.js'. The nodes under and including 'InspirationGenerator.js' have a yellow background color to signify that this sub-graph is client-rendered due to the 'use client' directive in 'InspirationGenerator.js'.">
|
||||
`'use client'` segments the module dependency tree of the React Server Components app, marking `InspirationGenerator.js` and all of its dependencies as client-rendered.
|
||||
@@ -237,7 +237,7 @@ With `'use client'`, you can determine when components are Client Components. As
|
||||
For simplicity, we talk about Server Components, but the same principles apply to all code in your app that is server run.
|
||||
|
||||
#### Advantages of Server Components {/*advantages*/}
|
||||
* Server Components can reduce the amount of code sent and run by the client. Only client modules are bundled and evaluated by the client.
|
||||
* Server Components can reduce the amount of code sent and run by the client. Only Client modules are bundled and evaluated by the client.
|
||||
* Server Components benefit from running on the server. They can access the local filesystem and may experience low latency for data fetches and network requests.
|
||||
|
||||
#### Limitations of Server Components {/*limitations*/}
|
||||
|
||||
Reference in New Issue
Block a user