[button][select] Add support for async react action props#5136
[button][select] Add support for async react action props#5136suneettipirneni wants to merge 8 commits into
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,098.22 ms -73.11 ms(-6.2%) | Renders: 78 (+0) No significant changes — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
| <div className={styles.Field}> | ||
| <Button | ||
| className={styles.Button} | ||
| clickAction={() => saveAction()} |
There was a problem hiding this comment.
The idea makes sense, but given the library supports React 17-19 I don't think we can have APIs that only work with React 19 though and degrades/doesn't work for other versions
(Not sure if it can be feature-detected either as startTransition exists in React 18 as well)
There was a problem hiding this comment.
We can feature-detect this without relying on startTransition, since startTransition exists in React 18 too.
If we decide these props should be React 19-only, the runtime guard can check for React 19 action primitives instead, for example React.useActionState and/or React.useOptimistic. Those APIs are the meaningful signal here because clickAction / valueChangeAction are intended to integrate with React 19 action scheduling, not merely to run an async callback.
So the compatibility behavior could be:
- if
clickAction/valueChangeActionare not used, nothing changes; - if they are used with React 19, they work as intended;
- if they are used with React 17/18, Base UI throws a clear runtime error recommending
onClick/onValueChangeinstead or to upgrade to react 19.
That avoids version parsing and avoids using startTransition as an ambiguous signal.
There was a problem hiding this comment.
if they are used with React 17/18, Base UI throws a clear runtime error recommending onClick / onValueChange instead or to upgrade to react 19
My point is I don't think we can have an API that doesn't work ("throws a runtime error" = doesn't work) for a supported React version
There was a problem hiding this comment.
Makes sense. I’d be interested in hearing what the other maintainers think as well. If everyone agrees that we shouldn’t support this API until it works across all supported React versions, I’m happy to close this PR.
Closes #5133
Implements the actions paradigm for
SelectandButton. Some more can be added in the future, these components seemed to benefit the most.The Async actions handbook page gives a good user-oriented overview as to why these props exist and what problems they aim to solve.