Skip to content

label-has-associated-control documentation source? #773

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

Open
kand opened this issue Feb 16, 2021 · 3 comments
Open

label-has-associated-control documentation source? #773

kand opened this issue Feb 16, 2021 · 3 comments

Comments

@kand
Copy link

kand commented Feb 16, 2021

In the documentation for label-has-associated-control, it says the following:

IDs shouldn't be generated in the browser, so that server and client rendering are deterministic. Render-time uuids aren't just a hack, they're actually broken and should never be used.

To restate, every ID needs to be deterministic, on the server and the client, and guaranteed to be unique on the page. EG: For each input, a required ID prop can be passed down from as far up the tree as possible to guarantee uniqueness.

Is there a source for the claim that "they're actually broken"? If you're using a UUID that's sufficiently unique what are the possible issues with this approach?

@ljharb
Copy link
Member

ljharb commented Feb 16, 2021

This was added in #530, and #528 outlines a number of the issues with them.

The issue is that uniqueness is irrelevant - you need determinism, and nothing generated on the client is guaranteed to be both unique and also deterministic.

@kand
Copy link
Author

kand commented Feb 16, 2021

Is this only an issue with server + client side rendering? Is this part of an accessibility spec and/or do screen readers have an issue with non-deterministic IDs? I'm discussing this rule among teammates and not able to find a concrete reason we can't use IDs generated on the front end and/or back end since, for our purposes, it's primarily for just connecting labels to their form elements.

Thanks!

@ljharb
Copy link
Member

ljharb commented Feb 16, 2021

It's primarily an issue with server + client rendering, but that is required for a11y anyways. In particular, you want your server HTML to match what your client renders, which means the IDs should be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants