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

Bug: useId generated the same ID on server-side for 2 different mounted components when Promise/Suspense is involved #29021

Open
Ang-YC opened this issue May 8, 2024 · 0 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@Ang-YC
Copy link

Ang-YC commented May 8, 2024

React version: 18.3.1

(Also tested on React 19 and seems like it is fixed)

Steps To Reproduce

  1. Create 2 components: Parent and Child, where both components will throw Promise (eg. data fetching)
  2. Call useId on both Parent and Child, and observes they have the same ID generated

Sample code:

const Child = ({ parentId }: { parentId: string }) => {
  const id = useId();
  useAsync(2); // Just assume it is a hook that will throw Promise in first call
  return (
    <ul>
      <li>Parent: {parentId}</li>
      <li>Child: {id}</li>
    </ul>
  );
};

const Parent = () => {
  const id = useId();
  useAsync(1); // Just assume it is a hook that will throw Promise in first call
  return <Child parentId={id} />;
};

Generated HTML:

<ul>
  <li>Parent: <!-- -->:R0:</li>
  <li>Child: <!-- -->:R0:</li>
</ul>

Link to code example: https://codesandbox.io/p/sandbox/react-server-duplicate-useid-nllf55

The current behavior

The ID generated on both mounted components are the same

<ul>
  <li>Parent: <!-- -->:R0:</li>
  <li>Child: <!-- -->:R0:</li>
</ul>

The expected behavior

The ID generated on both mounted components should be different

<ul>
  <li>Parent: <!-- -->:R0:</li>
  <li>Child: <!-- -->:R1:</li>
</ul>
@Ang-YC Ang-YC added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

1 participant