-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Generate unique ids within each React island #6976
Generate unique ids within each React island #6976
Conversation
🦋 Changeset detectedLatest commit: af4ed8c The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
d19c05a
to
d81f017
Compare
@ematipico Most of the comments you've raised related to the context implementation, so I wanted to tackle them in one thread. I literally copy and pasted the context file from the preact adapter. Of course, the original was in typescript, so I removed the typings, which likely added a lot more of the context you're requesting here. (Unfortunatley, the react adapter only compiles the index file, and I wanted to keep the changes to a minimum to help get this issue resolved promptly.) I'm happy to make changes, my thoughts:
I think you're right on most points, I just tried to keep the code as close to the original, figuring if that had already been accepted, it must be the preferred standard 😅 |
f8c32ae
to
d420c0e
Compare
d420c0e
to
b3fdf56
Compare
React's useId hook generates unique IDs by incrementing down the component tree. When multiple react roots are on a single page, these IDs can collide. React provides an option, `identifierPrefix` to prefix ids per root. Using preact adapters context solution, increment an ID per component rendered on a request, preventing collisions.
b3fdf56
to
af4ed8c
Compare
Sorry @SudoCat for my pedantic comments! I looked at the PR with almost no context and knowledge of the existing code 😅 |
No worries at all! Your pedantry aligns well with my own. I'm very grateful for a prompt review, anything to help get this accessibility issue fixed and shipped 🎉 |
Resolves #6849
React's useId hook generates unique IDs by incrementing down the component tree. When multiple react roots are on a single page, these IDs can collide. React provides an option,
identifierPrefix
to prefix ids per root.Using preact adapters context solution, increment an ID per component rendered on a request, preventing collisions.
Changes
prefix
identifierPrefix
optionindetifierPrefix
Testing
Docs
Unsure if documentation is needed; shouldn't change anything for users - something that didn't work properly will now work as intended.
/cc @withastro/maintainers-docs for feedback!