-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
A props object containing a "key" prop is being spread into JSX #11989
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
Comments
Hey @KrisLau! Thanks for opening the issue. It seems that the issue doesn't contain a link to a repro. The best way to get attention to your issue is to provide an easy way for a developer to reproduce the issue. You can provide a repro using any of the following:
A snack link is preferred since it's the easiest way to both create and share a repro. If it's not possible to create a repro using a snack, link to a GitHub repo under your username is a good alternative. Don't link to a branch or specific file etc. as it won't be detected. Try to keep the repro as small as possible by narrowing down the minimal amount of code needed to reproduce the issue. Don't link to your entire project or a project containing code unrelated to the issue. See "How to create a Minimal, Reproducible Example" for more information. You can edit your original issue to include a link to the repro, or leave it as a comment. The issue will be closed automatically after a while if you don't provide a repro. |
Couldn't find version numbers for the following packages in the issue:
Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3. |
Couldn't find version numbers for the following packages in the issue:
Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3. |
@satya164 Fixed it by moving the key out of the props. My patch file from yarn: diff --git a/src/TabBar.tsx b/src/TabBar.tsx
index e8d0b4c8dcbbe779fcd304f483d2d91c2d5e8dde..203adc927db153df3f8472d4ec67346e1cd7405b 100644
--- a/src/TabBar.tsx
+++ b/src/TabBar.tsx
@@ -364,8 +364,7 @@ export function TabBar<T extends Route>({
const renderItem = React.useCallback(
({ item: route, index }: ListRenderItemInfo<T>) => {
- const props: TabBarItemProps<T> & { key: string } = {
- key: route.key,
+ const props: TabBarItemProps<T> = {
position: position,
route: route,
navigationState: navigationState,
@@ -446,9 +445,9 @@ export function TabBar<T extends Route>({
<>
{gap > 0 && index > 0 ? <Separator width={gap} /> : null}
{renderTabBarItem ? (
- renderTabBarItem(props)
+ renderTabBarItem({key: route.key, ...props})
) : (
- <TabBarItem {...props} />
+ <TabBarItem key={route.key} {...props} />
)}
</>
); |
Hi @KrisLau, which version of react are you using? In my case for
This version should have a peerDependency |
Yes, the warning appears with React 18.3.x. There is no crash for me and the React crew is promising that there is no changes apart of new deprecation warnings |
@antoniogoulao I'm using v18.3.1. My Android builds are running fine on it but I'll make sure to keep an eye out for issues with it! My upgraded version is still sitting on a separate branch because I'm testing all the packages I upgraded haha. |
@linusrush you can use patch-package or yarn's built in patching to patch it in your project if you need it urgently |
+1 and thanks for the patch @KrisLau |
same error. will this be fixed? |
At the time of writing, no. Apply this patch. |
Hi, after upgrading to 0.75.0-rc.7 from 0.74.4, I came accross this issue.
could you help ? |
Same on react-native@0.75.1. Waiting for an official fix. :) |
i encounter the same problem with @react-navigation/material-top-tabs |
I encountered the same issue. Applying the patches did not work for me. I guess the better option is to downgrade to react |
Got the same issue when upgrading to react native 0.75.1, still crashes for android tried with patch and older version of react |
Oh! I had to downgrade from react native |
how do we name the patch file? |
@AyoCodess not sure what exactly youre asking but look up the tutorials for https://github.com/ds300/patch-package or the yarn patch package |
Whoever needs the patch file, it’s here. |
@AyoCodess You should be using yarn as your package manager for react-native projects. Follow the instructions here: https://yarnpkg.com/cli/patch to create a patch. |
Send a PR. We would be happy to review. |
Any Update??? |
i encounter the same problem with @react-navigation/material-top-tabs |
The same problem on my side :( |
getting the same error in android "dependencies": { const renderScene = ({ route }) => { <TabView const renderTabBar = (props) => ( <TabBar
/> props: { |
same error for us with react native 0.76.1 |
same error occurs when using tutorial demo of dynamic navigation from https://reactnavigation.org/docs/hello-react-navigation#creating-a-native-stack-navigator function RootStack() {
return (
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Details" component={DetailsScreen} />
</Stack.Navigator>
);
} |
Any updates? |
After downgrade react from # I'm using yarn. If you are using npm or npx, use related command
yarn remove react
yarn add react@18.2.0 🤡 I Temporary solve the problem The reason is: since Downgrade is a temp solution to run code correctly, while it's better to make the lib compatible with newest react version. Hope someone to solve the problem soon. (I'm a freshman of react so I have no idea why this happens) |
@KrisLau I solved this issue by downgrading the React version from 18.3.1 to 18.2.0 |
getting same error while I am not using any TabBarItem &platform=android&de…=hermes-stable:1086 Warning: A props object containing a "key" prop is being spread into JSX: |
The bug has been fixed since react-native-tab-view 4.0.0! |
Оф решений пока нет я так понимаю? |
This issue just reappeared for me too |
Has anyone done a fix for this issue?! |
|
I was having the same issue, it can be solved without applying a patch by extracting the key from the spread operator and passing it afterwards: const renderTabBar = (props: TabBarProps<Route>) => (
<TabBar
{...props}
renderTabBarItem={({ key, ...props }) => (
<TabBarItem {...props} key={key} />
)}
/>
); Hope it helps! |
Thanks a lot!!! it works |
Any news on this? Even with that adjustment, there are under the hood other places where we end up with this error, and IRL navigation gets confused when navigating fast between different nav items. ( Android issue, iOS doesn't have that glitch from what I've tested.) |
Merges the two tabs into a new tab "Sammlung", which has two top bar tabs for "Meine Wörter" and "Favoriten". - Add the material top tabs dependency - Create a patch for react-native-tab-view, because the 6.x.x versions are not properly supported anymore. More context: react-navigation/react-navigation#11989 (comment) - Remove the old favorites tab
Merges the two tabs into a new tab "Sammlung", which has two top bar tabs for "Meine Wörter" and "Favoriten". - Add the material top tabs dependency - Create a patch for react-native-tab-view, because the 6.x.x versions are not properly supported anymore. More context: react-navigation/react-navigation#11989 (comment) - Remove the old favorites tab
Merges the two tabs into a new tab "Sammlung", which has two top bar tabs for "Meine Wörter" and "Favoriten". - Add the material top tabs dependency - Create a patch for react-native-tab-view, because the 6.x.x versions are not properly supported anymore. More context: react-navigation/react-navigation#11989 (comment) - Remove the old favorites tab
Merges the two tabs into a new tab "Sammlung", which has two top bar tabs for "Meine Wörter" and "Favoriten". - Add the material top tabs dependency - Create a patch for react-native-tab-view, because the 6.x.x versions are not properly supported anymore. More context: react-navigation/react-navigation#11989 (comment) - Remove the old favorites tab
Merges the two tabs into a new tab "Sammlung", which has two top bar tabs for "Meine Wörter" and "Favoriten". - Add the material top tabs dependency - Create a patch for react-native-tab-view, because the 6.x.x versions are not properly supported anymore. More context: react-navigation/react-navigation#11989 (comment) - Remove the old favorites tab
Merges the two tabs into a new tab "Sammlung", which has two top bar tabs for "Meine Wörter" and "Favoriten". - Add the material top tabs dependency - Create a patch for react-native-tab-view, because the 6.x.x versions are not properly supported anymore. More context: react-navigation/react-navigation#11989 (comment) - Remove the old favorites tab
any solution? |
this started showing up again in sdk53 latest version |
Hello, I was getting this issue in another package, which took me a few hours to figure out since it wasn't my code. There is a more generic way to solve this issue whenever this warning is thrown by the react-jsx-runtime irrespective of the package that actually causes it. In my case the package was react-native-snap-carousel. Here is the offending code:
...
The issue is caused by props containing a key named 'key' being passed into react components via the spread operator ... as in the example shown above. The spread operator simply rolls out a json object into key=value syntax to be used as props by the receiving component. However, according to some research this may cause problems downstream if the component receiving the props doesn't handle it properly. Thus, when the framework detects a prop named 'key' being passed via spread syntax into a component, it throws this warning. The way to fix the issue is to send the key prop by itself and remove the entry from the rest of the props so that they don't trigger the framework to throw the same warning. As the rest of the json entries are not problematic, we may continue to send them via spread once the offending key is removed. To fix the example above, you would write:
After that you would want to patch the package to retain the changeset on future npm install. Hope it helps someone else. |
Uh oh!
There was an error while loading. Please reload this page.
Current behavior
Every time I load my app, after updating a bunch of my packages (of note: react-native, expo), I get this error:
Code:
When i add
renderTabBarItem={() => {}}
, the error disappears so I tried to change the<TabBarItem {...props} />
to<TabBarItem key={props.key} {...props} />
innode_modules/react-native-tab-view/src/TabBar.tsx
but the error did not disappear.Expected behavior
No error
Reproduction
Doesn't show up on snack but I modified this snack to match my code: https://snack.expo.dev/UtHfj87TmrjuCkct-fB9z
Platform
Packages
Environment
The text was updated successfully, but these errors were encountered: