-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[core] Fix React 18.3 warnings about spreading keys in the Material UI Autocomplete
component
#42099
[core] Fix React 18.3 warnings about spreading keys in the Material UI Autocomplete
component
#42099
Conversation
Netlify deploy previewhttps://deploy-preview-42099--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
AutoComplete
componentAutoComplete
component
Hey @heath-freenome, thanks for working on this! We need this for #42047, but it's missing some fixes. I've updated the PR with the missing cases. Adding @ZeeshanTamboli as a reviewer. |
@michaldudak This requires an update on |
@DiegoAndai Thanks for fixing that!! |
Signed-off-by: Heath C <[email protected]>
No problem at all! I'll port this update to the Base UI repo as well. |
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.
@heath-freenome Thank you for the PR. Would you like this PR to also address the issue for @mui/joy
Autocomplete and thereby close #40905? Given the error in #40905 (comment), I believe it relates to the Autocomplete option. Handling the separate passing of the key
for selected Chip
is already taken care of in Joy UI.
const { key, ...customTagProps } = getCustomizedTagProps({ index }); | ||
return ( | ||
<Chip | ||
key={key} |
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.
Should we consider #39795 (comment) here?
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.
We could do
startAdornment = value.map((option, index) => {
const customTagProps = getCustomizedTagProps({ index });
const key = customTagProps.key;
delete customTagProps.key;
return (
<Chip
key={key}
label={getOptionLabel(option)}
size={size}
{...customTagProps}
{...ChipProps}
/>
);
});
or
startAdornment = value.map((option, index) => {
const customTagProps = getCustomizedTagProps({ index });
return (
<Chip
label={getOptionLabel(option)}
size={size}
{...customTagProps}
key={customTagProps.key} // specifying it after stops the warning
{...ChipProps}
/>
);
});
Are there other options? I'm not sure which one I like the least 😅
Also, I'm not sure if we will get the benefits with option 2: facebook/react#25697
I couldn't find much info about this warning 😓
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.
Option 2 is similar to what was done in #40968 (See #39795 (comment)). However, I also believe it won't make much difference, as you mentioned in facebook/react#25697 (comment). So, the current solution seems fine.
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 think #39795 (comment) is wrong in retrospect considering how the Babel plugin is implemented: #39833 (comment). It could have worked, but it doesn't. React is relying on TypeScript to help detect key duplicates.
AutoComplete
componentAutocomplete
component
Autocomplete
componentAutocomplete
component
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.
Looks good. If we prefer not to address Joy UI Autocomplete in this PR (#42099 (review)), it can be handled separately. I've updated the title and label accordingly to focus on Material UI.
…ead-warning Signed-off-by: Diego Andai <[email protected]>
This is related to #40905 only it fixes
@mui/material
Iterate toward the resolution of #39833.