[Autocomplete][material-ui] Fix React key warning in Next.js#39795
Merged
mnajdova merged 1 commit intomui:masterfrom Nov 8, 2023
Merged
[Autocomplete][material-ui] Fix React key warning in Next.js#39795mnajdova merged 1 commit intomui:masterfrom
mnajdova merged 1 commit intomui:masterfrom
Conversation
Netlify deploy previewhttps://deploy-preview-39795--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
michaldudak
approved these changes
Nov 8, 2023
mnajdova
approved these changes
Nov 8, 2023
Comment on lines
+555
to
+562
| const defaultRenderOption = (props2, option) => { | ||
| const { key, ...otherProps } = props2; | ||
| return ( | ||
| <li key={key} {...otherProps}> | ||
| {getOptionLabel(option)} | ||
| </li> | ||
| ); | ||
| }; |
Member
There was a problem hiding this comment.
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> | |
| ); | |
| }; |
This was referenced Feb 3, 2024
This was referenced Jun 13, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #39474
Also see #39833 as related (for our demos in the docs that have a
renderOption)Demo: https://codesandbox.io/p/sandbox/https-gitlite.zycloud.tk-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
keyprop 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