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

Tried to modify key current of an object which has been already passed to a worklet. See #557

Open
rohanthakran opened this issue Oct 14, 2024 · 14 comments

Comments

@rohanthakran
Copy link

"react-native-reanimated": "^3.15.5",
"react-native-gesture-handler": "^2.20.0",
"react-native-draggable-flatlist": "^4.0.1",

[Reanimated] Tried to modify key current of an object which has been already passed to a worklet. See

https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-modify-key-of-an-object-which-has-been-converted-to-a-shareable
for more details.

This is the code
<DraggableFlatList
activationDistance={5}
data={dragData}
onDragEnd={({data}) => setDragData(data)}
keyExtractor={item => item.key}
renderItem={renderItemDrag}
containerStyle={[{backgroundColor: 'pink'}]}
/>

const renderItemDrag = ({item, drag, isActive}: RenderItemParams) => {
return (

<TouchableOpacity
onLongPress={drag}
disabled={isActive}
style={[
styles.rowItem,
{
backgroundColor: isActive ? 'red' : item.backgroundColor,
},
]}>
{item.label}


);
};

const initialData = [
{
label: '🍎 Apple',
key: 'apple',
backgroundColor: 'indianred',
},
{
label: '🍊 Orange',
key: 'orange',
backgroundColor: 'orange',
},
{
label: '🍌 Banana',
key: 'banana',
backgroundColor: 'yellowgreen',
},
{
label: '🍇 Grapes',
key: 'grapes',
backgroundColor: 'purple',
},
];

@rohanthakran rohanthakran changed the title ] Tried to modify key current of an object which has been already passed to a worklet. See Tried to modify key current of an object which has been already passed to a worklet. See Oct 14, 2024
@muneebaa
Copy link

muneebaa commented Oct 18, 2024

Same issue here this happens on TouchableOpacity in renderItem

@stephentuso
Copy link

Also ran into this after updating to reanimated 3.15.5 and react native 0.75

lovegaoshi added a commit to lovegaoshi/azusa-player-mobile that referenced this issue Oct 24, 2024
@rsainiWin
Copy link

Facing the same issue here

@kaliseo
Copy link

kaliseo commented Nov 8, 2024

Same here
"react-native-reanimated": "^3.15.2",
"react-native-gesture-handler": "^2.19.0",
"react-native-draggable-flatlist": "^4.0.1",

@xaviers1998
Copy link

this is still an issue on the latest reanimated

@yestoall
Copy link

same here with expo 52

@Riyaancode
Copy link

facing same issue here too

"react-native": "0.75.4",
"react-native-reanimated": "^3.16.1",
"react-native-gesture-handler": "^2.20.0",
"react-native-draggable-flatlist": "^4.0.1",

@hengkx
Copy link

hengkx commented Nov 22, 2024

same here with expo 51

@MuellerSabrina
Copy link

I have the same problem. Is there any workaround by now?

@rybaier
Copy link

rybaier commented Dec 16, 2024

I Have the same issue and the ScaleDecorator specifically triggers a repetitive cascade of the same warning while the item is being dragged

without the ScaleDecorator the warning is triggered only upon completion and screen render


  const renderItem = ({ item, drag, isActive }: RenderItemParams<Item>) => {
    const { priorityColor } = getPriorityDetails(item.priority);

    return (
      <ScaleDecorator>
        <View key={item.id}>
         
              <TouchableOpacity 
                activeOpacity={1} 
                onPress={() => navigateTo(`/item/${item.id}`)}
                onLongPress={drag}
                disabled={isActive}
              >
                <View style={styles.card}>
                  <View style={styles.cardRow}>
                    <View
                      style={{
                        backgroundColor: priorityColor,
                        width: 7.5,
                      }}
                    />
                    <View style={styles.cardColumn}>
                      <Text style={styles.title}>{item.title}</Text>
                      <Text style={styles.location}>{item.location}</Text>
                      <Text style={styles.description}>{item.description}</Text>
                    </View>
                  </View>
                </View>
              </TouchableOpacity>
        </View>
      </ScaleDecorator> 
      ```

@rybaier
Copy link

rybaier commented Dec 16, 2024

I'm pretty sure The issue is within the KeyExtractor in the DraggableFlatList component. as it joins the index to the key provided so everytime an item is adjusted in the list the warning fires because the index is changing and changing the key.

@rybaier
Copy link

rybaier commented Dec 19, 2024

this is not best practice but
for anyone interested in shutting the warnings off temporarily until this is resolved put this in the root level of the app.

import {
  configureReanimatedLogger,
  ReanimatedLogLevel,
} from "react-native-reanimated";

// This is the default configuration
configureReanimatedLogger({
  level: ReanimatedLogLevel.warn, // 2 levels warn or error 
  strict: false, // Reanimated runs in strict mode by default-  change this to false
});

Reanimated Logger Config

@MuellerSabrina
Copy link

I still get the warning with your solution.

I also have this weird behavior in my list, where the dragged item jumps back for a short moment to the original place.

flatlist_problem

@rybaier
Copy link

rybaier commented Dec 21, 2024

@MuellerSabrina

Try this

import {
configureReanimatedLogger,
ReanimatedLogLevel,
} from "react-native-reanimated";

configureReanimatedLogger({
level: ReanimatedLogLevel.error,
strict: true
});

This sets it so only errors will be rendered. Though it's not an ideal work around

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests