Skip to content

Edits for new "use client" content #6401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 3, 2023

Conversation

sophiebits
Copy link
Member

No description provided.

Copy link

github-actions bot commented Nov 2, 2023

Size changes

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

// ...
return
<Link />
// ...
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found this syntax awkward. changed to a Button because I couldn't think of a variable name for the link

@@ -179,7 +178,7 @@ First, let's clarify that the term "component" is not very precise. Here are jus
```js
// This is a definition of a component
function MyComponent() {
return <p>My Component</p>
return <p>My Component</p>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed from tabs (which render as 4 spaces) to spaces (2)


For simplicity, we talk about Server Components, but the same principles apply to all code in your app that is server run.

#### Advantages {/*advantages*/}
#### Advantages of Server Components {/*advantages*/}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only made minor edits here but I don't love this section in its current form. I think of this less as advantages/disadvantages and more that in many cases they are for different things! more like

  • unique capabilities of server components
  • unique capabilities of client components
  • when to prefer one or the other if you don't need either one

</Diagram>

In the module dependency tree of the example app, the `'use client'` directive in `InspirationGenerator.js` marks that module and all of its transitive dependencies as client modules. It creates a subtree of client modules with `InspirationGenerator.js` as the root.

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), opting-out of evaluating any code imported from client-marked code.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole part is still a bit confusing for SSR particularly

return <Counter initialValue={initialValue} />
}
```

For example, the parent component of the Client Component `CounterContainer` does not require `'use client'` as it is not interactive and does not use state. In addition, `CounterContainer` must be a Server Component as it reads from the local file system on the server. This is possible because Server Components, unlike Client Components, can be async functions.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will support async functions on the client so this isn't why

Copy link
Contributor

@lunaleaps lunaleaps Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have async components on client?
Edit: Oh I see, future-tense

@@ -332,13 +333,15 @@ export default function FancyText({title, text}) {
}
```

In this case, it is discouraged to use the `'use client'` directive as it prematurely forces all component usages of `FancyText` to be rendered on the client, which comes at a performance cost. As demonstrated in the earlier Inspirations app example, `FancyText` is used as both a Server or Client Component, depending on where it is imported and used.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(first sentence was overly prescriptive)


### Using client APIs {/*using-client-apis*/}

Your React app may use client-specific APIs which are dependent on your targeted client. For the browser, some example client APIs include web storage, audio and video manipulation, and device hardware, among [others](https://developer.mozilla.org/en-US/docs/Web/API).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you were trying to be agnostic to web vs native here? but I think it was a bit confusing in practice and better to be clearer

(most of our docs are written with web in mind; I think we probably need a bigger rethink terminology-wise before we could truly update them to be agnostic)

@@ -350,26 +353,27 @@ export default function Circle() {
useLayoutEffect(() => {
const canvas = ref.current;
const context = canvas.getContext('2d');
context.reset();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

effects can run multiple times :) like with offscreen in the future (and also because [] deps aren't specified here)

could've put this in the unmount but I put it here

Co-authored-by: Luna <lunaleaps@gmail.com>
Copy link
Member Author

@sophiebits sophiebits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty

@sophiebits sophiebits merged commit a8790ca into reactjs:main Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants