Skip to content

Conversation

@lunaleaps
Copy link
Contributor

@lunaleaps lunaleaps commented Oct 20, 2023

Flesh out reference docs for 'use client' by adding more thorough explanation and usage examples

Preview

@github-actions
Copy link

github-actions bot commented Oct 20, 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! 🙌

<Intro>

`'use client'` marks source files whose components execute on the client.
`'use client'` marks which components render on the client.
Copy link
Member

Choose a reason for hiding this comment

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

(I realize this is a draft so not reviewing in detail but wanted to note one high-level thing…)

thought: is there a way we can be clear up top that this marks the boundary between server and client components? ideally people should realize that you need serializable props and that you don't need to mark every file deep down. it's great you have FancyText but I think it could be a bit clearer throughout

(obviously my intro text you replaced did not even try to clarify this! oops. what you wrote here is a clear improvement)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to try and highlight the concept of boundary more

@lunaleaps lunaleaps requested a review from davidmccabe October 25, 2023 17:53
Co-authored-by: Soichiro Miki <smiki-tky@umin.ac.jp>
Copy link
Contributor

@davidmccabe davidmccabe left a comment

Choose a reason for hiding this comment

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

This is a great doc. Some suggestions. I'll get to the Usage section later this afternoon.

### `'use client'` {/*use-client*/}

Add `'use client';` at the very top of a file to mark that the file (including any child components it uses) executes on the client, regardless of where it's imported.
Add `'use client'` at the top of a file to mark the module and its transitive dependencies as client code.
Copy link
Contributor

Choose a reason for hiding this comment

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

This use of "transitive dependencies" is correct but my brain erroneously interpreted it as "transitive dependents" instead. I wonder if we could say something like "and any other modules it imports".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that weakens the definition though because 'any other module it imports' may be only interpreted as one level

}
```

2. A "component" can also refer to a **component callsite** of its definition.
Copy link
Contributor

Choose a reason for hiding this comment

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

A "component" can also refer to a component instance created by using the component as an element within some other component.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we use the word "callsite" elsewhere. Technically speaking they aren't callsites as the component function is not called. They are technically elements but might more clearly be referred to as instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've heard conflicting thoughts on this from @eps1lon as I originally had them as instances. There was mention it may be confused with the runtime instance.
Before callsite, I used "use", like "component usages"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll go back to usage for now

@davidmccabe
Copy link
Contributor

I think reading through the Usage section here has swayed me away from capitalizing Client Component.

Luna Wei and others added 2 commits October 27, 2023 14:12
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.

6 participants