useId behavior in asynchronous environments #11817
Unanswered
tuskermanshu
asked this question in
Help/Questions
Replies: 1 comment
-
I'm not sure, but aren't we supposed to only call use...() functions at the top-level of the setup function? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'd like to start a discussion about the useId composable in Vue 3, specifically its behavior in asynchronous environments. As many of us have experienced, useId doesn't work as expected when called within asynchronous contexts such as setTimeout, setInterval, or Promise callbacks. This is due to its reliance on getCurrentInstance(), which returns null in these scenarios.
Current Behavior
Currently, when useId is called in an async context:
Questions for Discussion
Was the current behavior a deliberate design decision? If so, what were the key considerations?
How are others in the community handling ID generation in async contexts while maintaining the benefits of useId (like SSR compatibility and component scope)?
Would it be beneficial to extend useId to work in async environments? What would be the pros and cons?
If extending useId isn't feasible, what alternatives could we consider? Perhaps a new composable like useAsyncId?
Code Example
Here's a simple example to illustrate the issue:
Beta Was this translation helpful? Give feedback.
All reactions