-
-
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
react 18.3.0 "A props object containing a "key" prop is being spread into JSX" #39833
Comments
If it's a Next.js regression, maybe it's for them to fix it, but maybe not depending on what they say about it. If they say they will fix it in 4 weeks, I don't think it's worth it for us, if it's "normal", 👍 to handle. At least it's a tradeoff, we are adding complexity to the codebase that is a good benefit to 1/4 of the users (Next.js userbase?) and harms a little bit 3/4. |
multipule
option has console errors in Next.jsmultiple
option has console errors in Next.js
Thank you for your quick reply! And, thank you for commenting on the Next.js issue. |
This is not only in Next.js. It also happens with React starting from version |
multiple
option has console errors in Next.js
I had a closer look at this. The behavior of the JSX transform is interesting: const profile1 = (
<div key="baarr" {...foo} />
);
const profile2 = (
<div {...foo} key="baarr" />
); outputs: import { jsx as _jsx } from "react/jsx-runtime";
import { createElement as _createElement } from "react";
const profile1 = /*#__PURE__*/_jsx("div", {
...foo
}, "baarr");
const profile2 = /*#__PURE__*/_createElement("div", {
...foo,
key: "baarr"
}); Now, when you check the sources, I'm super confused: https://github.com/facebook/react/blob/04b058868c9fc61c78124b12efb168734d79d09e/packages/react/src/jsx/ReactJSXElement.js#L557-L562. But it gets a lot clearer from: https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md
So what React wants is a clear I have created #42168 to illustrate it. |
Thanks for taking a deeper look @oliviertassinari! Summarizing, if I understand correctly 1.
|
@DiegoAndai This matches what I understand of the situation 👍 |
Hi, I've been having this issue using Next.js 14 + React 18 + MUI 5.15 This error comes up when you select an item and the Chip appears within the input, not sure if you already solve it but I was able to solve it overriding the Chip with the renderTags:
Basically you cannot pass the {...props} containing a For example:
Hope it works to other folks! |
I raised an issue #42161 which got closed as a duplicate of this one. However, the fixes that went in to v5.15.19 don't seem to address it so i'm hoping it will still be tracked and resolved. Whilst as @amd2107 points out, there is a @DiegoAndai are there plans to address this still? |
I have the same issue - React + mui, mostly with the Autocomplete
|
Yes, I'll take a look as soon as possible, sorry for the delay. I'll keep you posted. |
@mbiggs-gresham @a-tonchev you should upgrade to the following version: npm i @mui/[email protected] --save or npm i @mui/material@next --save I spent several hours exploring how MUI works behind the scenes. While testing in the integrated playground, I upgraded to Next.js 14, and the error was resolved. I believe the issue has been fixed in this latest version. Hope it works! This topic can be closed as the error has been resolved in the mentioned version. Edit: I removed the part where I mentioned compatibility with version 7 and other MUI plugins. Initially, it seemed to work, but after rebuilding the project and fixing the component styles, it resulted in a failure. Note that there are no compatible grid or time picker libraries yet for this next version. |
I was also seeing this issue in react and I am not using Nextjs.. I was also able to resolve the issue by de-structing the object that is being passed into the renderOption with muiv5. Basically, the key prop must be removed before passing into the
The answer above from @amd2107 and @a-tonchev helped me. Hope it helps others as well. |
An update. This issue covers two related bugs: The first bug; key spreading inside the Autocomplete component codebase, was fixed in #42099 and is available from versions To close this issue, we need to fix the second one: Other components might have similar issues to the one I mentioned above. We should look for and fix those in the same PR. This is included in the support React 19 work, so it should be picked up in the coming weeks. Thank for your patience. |
Thanks for the update |
Hi, I'm encountering a similar issue on Joy Autocomplete (v5.0.0-beta.36). I'm willing to make a pull request, if you can point me to the right direction. I am on react 18 btw.
<FormControl>
<FormLabel>...</FormLabel>
<Autocomplete
multiple
freeSolo
placeholder="..."
options={data ?? []}
getOptionLabel={(option) => option}
/>
</FormControl> |
Hey @keyvanm, have you tried with the latest Joy version: |
Just upgraded. Same issue. |
We have a change that might fix this in this week's release: |
Steps to reproduce 🕹
Link to live example: https://mui.com/material-ui/react-autocomplete/#multiple-values
using Next.js
It works, but I get warnings on the console.
Current behavior 😯
Some of the issues have been identified and addressed at #39474, and they have already been resolved. However, a similar problem occurs with renderTags when using multiple.
Expected behavior 🤔
It appears that the following code also needs to be modified:
https://github.com/mui/material-ui/blob/v5.14.17/packages/mui-material/src/Autocomplete/Autocomplete.js#L506-L525
Also, the type of the props for renderOption is currently defined as React.HTMLAttributes, but in reality, it includes the key property. This might cause some confusion in TypeScript.
Context 🔦
No response
Your environment 🌎
npx @mui/envinfo
The text was updated successfully, but these errors were encountered: