-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Feat: Add lifecycle callback to useId
#8630
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
base: main
Are you sure you want to change the base?
Conversation
cleanupCallback
to useId
useId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change seems fine, though having a more concrete use case would be good
I know GC doesn't get called in jsdom (at least not easily) wonder if we should start mocking the FinalizationRegistry so we can get some tests around this as it's growing in complexity
@snowystinger Let me elaborate on a specific use case - I began work on #7240, starting with unifying the labeling across all collection components. This PR will unify the id generation of nodes, in order to make them predictable from a parent collection builder. The result will be the For backwards compatibility, this is a problem for To tidy it all up, we need this additional callback on PS: Having a predictable id generation for nodes will allow us to connect adjecent collections, such as a tablist's tabs, with presentational nodes that are rendered around listbox items in a tabbed // => Carousel's renderer wraps items with <div role="presentation" id="<tabpanel-id>" />
<Carousel>
<Button slot="previous" />
<Button slot="next" />
<ListBox>
<ListBoxItem id="1" />
</ListBox>
<TabList>
<Tab id="1" />
</TabList>
</Carousel> |
Thanks for the explanation. I have a feeling the team will want to discuss this Carousel API, it's a bit unusual. If you're planning on trying to contribute it, it'd be best to outline your plan in an RFC so we can discuss it there and reach agreement. |
@snowystinger Got it, for now I‘m only focusing on making non breaking changes to the primitives, aka hooks and state, to get them where they would need to be in order to support building a component like this on top. Some of these changes address open issues or make sense regardless of whether the carousel makes it or not, so I’m spinning these out into separate PRs, to be reviewed independently. For the component layer or implementation specific changes, I will keep in mind to open an RFC before PRs 👍 Do you think this change here is good to go? |
bringing up with the team |
Not sure I quite understand. Usually in React you want state to be owned by a parent component and flow downward to children. Having state owned by a sibling is usually quite problematic as React does not guarantee a render order. That's why for example |
@devongovett Can you elaborate on which part you want me to clarify? Are you referring to the Carousel API or the menu hook problems? I suppose its mostly the menu problems you are interested in, but let me clarify the background: To implement W3C's tabbed This architecture makes it impossible for a parent component to reliably target a collection DOM element via its Node Now I have started work on getting the id changes done in a non-breaking PR, but have ran into issues with Luckily for us, the JSX structure of trigger elements and I hope this could help - again, I will elaborate more on carousel in a dedicated RFC 👍 I can commit a WIP PR of the id changes if you would like to see code next to what im saying here. |
I'm unsure how the ListBox and Tabs relate to each other within a carousel pattern. The APG Example doesn't have a listbox, just tabs. An RFC would definitely help there.
I think it generates based on the a base id (attached to the state) and the collection node's id:
So is the problem here that you're using two different collection components (ListBox and TabList) and trying to sync them somehow? Understanding how these fit together would help. |
@devongovett The problem here is completely independent of
That's exactly the point - the parent wrapper has no way to determine the internal As to the requested relation between Now After finishing up the implementation using Since our implementation pretty much let's Now we are in the middle of testing exactly how this would get announced, if |
This PR adds support for lifecycle hooks to a
useId
. This can be useful to build global state with unique ids as the key, in scenarios where a common state object isn't accessible.✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: