Skip to content
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

Add note about useId being allowed in non-async Server Components #7715

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hernan-yadiel
Copy link

I remember seeing this PR that mentions that useId is allowed in non-async Server Components. However, nowhere in the documentation mentions this fact.

@facebook-github-bot
Copy link
Collaborator

Hi @hernan-yadiel!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@hernan-yadiel hernan-yadiel changed the title Add note about useId being allowed in non-async SCs Add note about useId being allowed in non-async Server Components Apr 3, 2025
@facebook-github-bot
Copy link
Collaborator

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

`useId` is allowed in non-async [Server Components](/reference/rsc/server-components).

</RSC>

Copy link
Member

Choose a reason for hiding this comment

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

Can you move this to the caveats? And instead word it as something like "useId currently cannot be used in async server components". And there should be a troubleshooting item for the lint error with an explanation, but that can be added separately.

Copy link
Author

Choose a reason for hiding this comment

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

Sure! No problem!

Copy link
Author

Choose a reason for hiding this comment

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

I moved the note to caveats.

Where should I add the troubleshooting item you mentioned? That's on the react hooks eslint package, right?

@@ -46,6 +46,8 @@ function PasswordField() {

* `useId` **should not be used to generate keys** in a list. [Keys should be generated from your data.](/learn/rendering-lists#where-to-get-your-key)

* `useId` currently cannot be used in [async Server Components](/reference/rsc/server-components#async-components-with-server-components).
Copy link
Author

Choose a reason for hiding this comment

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

Initially, I thought about wording it to highlight that useId is the only hook allowed in Server Components. But then I realized this wording assumes that hooks are disallowed in Server Components. Somehow I thought this was just another React Hooks Rule, or another Server Components rule, when actually that’s not exactly the case. I think this assumption is common among devs, maybe because all of them are not allowed in SCs (except from useId which it wasn't even documented).

My main concern is that if React later introduces more hooks usable in both Server and Client Components, explaining “some hooks are allowed on server components, others aren't” might get tricky.

I can't think of a clear solution, but perhaps labeling hooks differently could help clarify this distinction. For example, “Interactive Hooks” vs. “Non-Interactive Hooks” (or simply “Hooks”).

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