Skip to content
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

[Autocomplete][material-ui] Fix React key warning in Next.js #39795

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/mui-material/src/Autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,14 @@ const Autocomplete = React.forwardRef(function Autocomplete(inProps, ref) {
);

const renderGroup = renderGroupProp || defaultRenderGroup;
const defaultRenderOption = (props2, option) => <li {...props2}>{getOptionLabel(option)}</li>;
const defaultRenderOption = (props2, option) => {
const { key, ...otherProps } = props2;
return (
<li key={key} {...otherProps}>
{getOptionLabel(option)}
</li>
);
};
Comment on lines +555 to +562
Copy link
Member

@oliviertassinari oliviertassinari Nov 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spread is not a very fast operator (speaking under @romgrk control, who I think did changes like this in the MUI X codebase to improve performance)

Would this be better?

Suggested change
const defaultRenderOption = (props2, option) => {
const { key, ...otherProps } = props2;
return (
<li key={key} {...otherProps}>
{getOptionLabel(option)}
</li>
);
};
const defaultRenderOption = (props2, option) => {
// Need to clearly apply key because of https://github.com/vercel/next.js/issues/55642
return (
<li key={props2.key} {...props2}>
{getOptionLabel(option)}
</li>
);
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled in #40968

const renderOption = renderOptionProp || defaultRenderOption;

const renderListOption = (option, index) => {
Expand Down
Loading