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
[Rating] Make input ids less predictable #26493
Conversation
Details of bundle changes (experimental) @material-ui/core: parsed: +0.08% , gzip: +0.09% |
3121a73
to
8d562e4
Compare
Something I have noticed that changed: a double focus ring instead of a single one: https://deploy-preview-26493--material-ui.netlify.app/components/rating/#rating-precision |
8d562e4
to
478e696
Compare
478e696
to
bc77276
Compare
bc77276
to
6dd6488
Compare
Greatch catch 👍 Reproduced it in a visual regression test (https://www.argos-ci.com/mui-org/material-ui/builds/4211) and fixed it in The implementation is still a bit hard to follow but it's now clearer where the odd part happens (active state is located in different components between precise (precision % 1 > 0) and non-precise (precision % 1 === 0) ratings. |
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.
I can't notice anything else. Looks good
reactjs/rfcs#32 (comment) doesn't seem to happen (it would allow the usage of a single opaque identifier).
For context, in the initial implementation of the rating, I didn't use a component for the rating items to avoid the overhead of React components, in the order of +10% CPU per extra component (but I don't have a benchmark to prove it). With precision={0.5}
we render a lot of DOM, the rating doesn't seem fast to render. But I understand that without a component, we can't use useId
.
If reactjs/rfcs#32 (comment) ever happen in the future 👍 for: 1. adding a perf benchmark, 2. calling RatingItem
as a function, instead of a React component and measure if it makes a difference or not.
This does not match the latest information I was given:
-- reactwg/react-18#9 (reply in thread)
I don't find it helpful that we constantly have to get back to this discussion. If you want to start a discussion whether Reacts lazy evaluation model vis components is useful then go for it. But starting it whenever it suits to make an argument against a change that wasn't explicitly sanctioned by you is just not helpful. So either start an RFC on the appropriate channels to get a good understanding when we should use function calls and when compoent or stop constantly opening this unconfirmed issue. |
I don't think that it goes against the changes done here. I was interested in the opportunity it could yield later on, once these changes are on HEAD.
AFAIK, the overhead was confirmed at the root. Here are two examples where we measured it:
My question was: Will we need to care in this specific context of the Rating? Will it ever be significant? Anyway, it's not for us to consider today, but in the future :). #17001 might be one where we can have a larger impact first. |
Found this when working on mui#26493 (comment)
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.
To unlock the PR, as it doesn't seem to get interest from other maintainers :)
Incomplete. Please review by commit.
Previous usage of
useId
was incompatible with the upcomingReact.useOpaqueIdentifier
. We can refactor theitem()
factory to a<Item />
component which allows us to to useReact.useOpaqueIdentifier
for each item.This may break tests if you relied on stable ids for the individual radio inputs. However, you can use
[value]
attribute selectors instead which also means you no longer have to provide an explicitname
in your tests:(This example queries for the input for the rating value "2")
Given that your container only has a single
input
of course. Otherwise you probably should provide an explicit name.Preview: https://deploy-preview-26493--material-ui.netlify.app/components/rating/