Skip to content

Add basic reference pages for use client and server #5976

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
Jun 30, 2023

Conversation

sophiebits
Copy link
Member

I guess this turned into a bit more of an FAQ but I think it's useful to have this written down in a canonical place.

@github-actions
Copy link

github-actions bot commented Apr 28, 2023

Size changes

📦 Next.js Bundle Analysis for react-dev

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

One Page Changed Size

The following page changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/[[...markdownPath]] 76.79 KB (🟡 +40 B) 179.94 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

I guess this turned into a bit more of an FAQ but I think it's useful to have this written down in a canonical place.
Copy link
Member

@rickhanlonii rickhanlonii 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 great, @sophiebits do you think we should add some kind of indicator that this is a "canary" feature? Approving because we can follow up to add that.

* It's not necessary to add `'use client'` to every file that uses client-only React features, only the files that are imported from server component files. `'use client'` denotes the _boundary_ between server-only and client code; any components further down the tree will automatically be executed on the client. In order to be rendered from server components, components exported from `'use client'` files must have serializable props.
* When a `'use client'` file is imported from a server file, the imported values can be rendered as a React component or passed via props to a client component. Any other use will throw an exception.
* When a `'use client'` file is imported from another client file, the directive has no effect. This allows you to write client-only components that are simultaneously usable from server and client components.
push down
Copy link
Contributor

Choose a reason for hiding this comment

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

typo?

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, fixed

@sophiebits
Copy link
Member Author

do you think we should add some kind of indicator that this is a "canary" feature?

This is what the Note at the top is for; don’t think it’s enough?

@sophiebits
Copy link
Member Author

¯\_(ツ)_/¯ I think this is better than nothing


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

Add `'use server';` at the very top of an async function to mark that the function can be executed by the client.
Copy link
Member Author

Choose a reason for hiding this comment

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

hm. I meant that it can be imported + triggered by the client

@rickhanlonii
Copy link
Member

Yeah, I think I was looking for it to mention the "canary" specifically with a link to the versioning policy.

@sophiebits
Copy link
Member Author

For most APIs we’ll add I agree (probably with a specific version number noted) but for these specifically I’m not sure it’s helpful because checking the version won’t tell you if you’re already using an RSC framework and upgrading to canary won’t help you if you’re not.

@sophiebits
Copy link
Member Author

(Not opposed to adding it here for consistency though once we have a standard pattern!)

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.

5 participants