-
-
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
[Autocomplete][material-ui] Fix React key warning in Next.js #39795
Conversation
Netlify deploy previewhttps://deploy-preview-39795--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
const defaultRenderOption = (props2, option) => { | ||
const { key, ...otherProps } = props2; | ||
return ( | ||
<li key={key} {...otherProps}> | ||
{getOptionLabel(option)} | ||
</li> | ||
); | ||
}; |
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.
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?
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> | |
); | |
}; |
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.
Handled in #40968
Closes #39474
Also see #39833 as related (for our demos in the docs that have a
renderOption
)Demo: https://codesandbox.io/p/sandbox/https-github-com-mui-material-ui-pull-39795-fwdm7f?file=%2Fsrc%2Fapp%2Fpage.tsx%3A1%2C1
There should no console errors when opening the listbox with grouped options
Next.js doesn't like it when a
key
prop is part of an object being spread, here's the related issue in their repo: vercel/next.js#55642BTW I'm not sure why this doesn't repro when the options are ungrouped, as in both cases they both use
defaultRenderOption