-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
makeShareableCloneRecursive Call Stack Size Exceeded #4177
Comments
Hey! 👋 The issue doesn't seem to contain a minimal reproduction. Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem? |
Hey! 👋 It looks like you've omitted a few important sections from the issue template. Please complete Snack or a link to a repository section. |
We hit this as well when attempting to upgrade from v3 RC1. Haven't had a chance to dig in yet, but we will add more details if we can figure out a minimum repro. |
Hi, It occurs on Android too in debug mode. When you have this error, all animation on screen do not work. I will try to reproduce this except if you know where it can come from. |
Added a log to the shareable clone and seeing this:
was accessing a redux prop moving it value into a useSharedValue solved the problem for me. was fine in the rc of version3 |
Commenting to follow. Also getting this error on Expo development client |
+1 |
It might be related to PanGestureHandler. When I remove PanGestureHandler from the screen where this error is happening, the error doesn't occur any more |
Interesting @andrewlo, I'm using react-native-pager-view on the screen where this message appears. |
In our case, I was able to narrow down to two different places where this error occurs. One was a Gesture.Pan.onEnd(), and the other was a useDerivedValue(). I narrowed down in both to a single line of code - and in both cases that line of code was referencing a prop from the containing component. Could be coincidence, but @andrewlo @TomCorvus it might be worth checking if you can narrow down to the line of code inside the PanGestureHandler that's causing the failure. I've still had no luck with a min repro. We had to stay on our previous build for now. |
Same here, happens with the lib "react-native-graph" when trying to migrate to reanimated v3. |
got the same issue, any hero can fix it? |
The cause of the issue is a recursive object that is being used in a worklet function ( function Test(props) {
const obj = {
opacity: 1,
}
obj.test = obj; // make the object recursive
const style = useAnimatedStyle(() => ({
opacity: obj.opacity,
}));
return <Animated.View style={style} />
} To workaround this issue you have to convert the variable to serializable value, e.g. with object destructuring: function Test(props) {
const obj = {
opacity: 1,
}
obj.test = obj; // make the object recursive
const { opacity } = obj
const style = useAnimatedStyle(() => ({
opacity: opacity,
}));
return <Animated.View style={style} />
} Reanimated V2 seems to automatically detect recursive objects and handle this edge case, but V3 does not. |
In my case the following code (inside
I'm also new to Reanimated so I don't know how to solve it. First I though it was a recursive state update at my side, then I've seen this: Any help to get rid of this would be appreciated. |
I think the way to reproduce it is the following: Example:
then in componentB you do:
As soon as doSomethingCool is called we'll get the above error. In my example |
For me it was popping when trying to install reanimated v3 with react-native < 0.71 Now that I've successfully migrated to 0.71.4 I don't have this error anymore -- no code changed |
Definitely not our case. That's happening on our end and we're on 0.71.4 and reanimated v3. |
Also, I noticed that sometimes, even converting a method from a const arrow function to an old school function like so: from:
to:
makes the error go away. (but not always) |
It happens with react-native-draggable-flatlist for me and this PR fixes the problem (computerjazz/react-native-draggable-flatlist#462) |
so it looks like the main takeaway here is to avoid passing props from outside of the context of the We can only pass params through the function parameters, and not from the outer scope. |
Just chiming in here in case this helps somebody - when we upgraded to V3 we had these issues alongside the app just freezing. The issue in our case is that we were incorrectly modifying a shared value within
|
In my case I'm not using worklets at all (honestly I don't even know how they exactly work) but still get this. |
@LeviWilliams The issue with updates in useDerivedValue is resolved here #4358 and should be included in next 3. release |
## Summary This PR addresses a number of issues reported related to exceeding stack when converting objects to shareables (e.g. in #4177). This issue got introduced in Reanimated 3 after #4060 where we got rid of filtering only attributes accessed in worklets to be captured by worklets. This PR implements a solution that filters only plain objects before converting things to shareables. In all of the instances of this issue we encountered, the crash was due to the fact we were leaking some react internals (fiber nodes) into the captured variables (e.g. via React's refs or otherwise). These objects are not of a plain object type and hence we wouldn't be able to support transferring these on the UI runtime anyways. With this change we are skipping these type of objects and replace them with a "inaccessible object" which is implemented as a proxy that throws on any attempt of accessing its attributes – this way users will get an error if they do use or access such objects. In addition we add a cyclic object detection mechanism. Currently cyclic objects cannot be converted to sharables – they weren't supported in Reanimated 2 either. We add it as a part of this change in case the object prototype check wouldn't be sufficient in some cases. In a scenario when cyclic object is captured by a worklet we will detect that and throw a more descriptive error. ## Test plan The below code illustrates a scenario when we are capturing react internals via ref: ```js function Mleko({ props }: any) { const style = useAnimatedStyle(() => { console.log(props) return {} }) return ( <View ref={props.ref} /> ); } const ref = useRef(); <Mleko props={{ ref }} /> ``` Before this change the above coud would throw stack exceeded error. Now this works ok. In addition we tested cyclic detection by capturing the following object: ```js const one = {}; const two = {one}; one.two = two; ``` The above object would throw stack exceeded error. now it throws an error that says that user is capturing cyclic object. Lastly, we tested accessing non plain objects: ```js class Something() { constructor() { this.ggg = 7 } } const something = new Something(); useAnimatedStyle(() => { console.log(something.ggg); return {}; }); ``` --------- Co-authored-by: Tomek Zawadzki <tomasz.zawadzki@swmansion.com>
This appears to be fixed in 3.1 - I can no longer repro. Thank you! |
## Summary This PR addresses a number of issues reported related to exceeding stack when converting objects to shareables (e.g. in software-mansion#4177). This issue got introduced in Reanimated 3 after software-mansion#4060 where we got rid of filtering only attributes accessed in worklets to be captured by worklets. This PR implements a solution that filters only plain objects before converting things to shareables. In all of the instances of this issue we encountered, the crash was due to the fact we were leaking some react internals (fiber nodes) into the captured variables (e.g. via React's refs or otherwise). These objects are not of a plain object type and hence we wouldn't be able to support transferring these on the UI runtime anyways. With this change we are skipping these type of objects and replace them with a "inaccessible object" which is implemented as a proxy that throws on any attempt of accessing its attributes – this way users will get an error if they do use or access such objects. In addition we add a cyclic object detection mechanism. Currently cyclic objects cannot be converted to sharables – they weren't supported in Reanimated 2 either. We add it as a part of this change in case the object prototype check wouldn't be sufficient in some cases. In a scenario when cyclic object is captured by a worklet we will detect that and throw a more descriptive error. ## Test plan The below code illustrates a scenario when we are capturing react internals via ref: ```js function Mleko({ props }: any) { const style = useAnimatedStyle(() => { console.log(props) return {} }) return ( <View ref={props.ref} /> ); } const ref = useRef(); <Mleko props={{ ref }} /> ``` Before this change the above coud would throw stack exceeded error. Now this works ok. In addition we tested cyclic detection by capturing the following object: ```js const one = {}; const two = {one}; one.two = two; ``` The above object would throw stack exceeded error. now it throws an error that says that user is capturing cyclic object. Lastly, we tested accessing non plain objects: ```js class Something() { constructor() { this.ggg = 7 } } const something = new Something(); useAnimatedStyle(() => { console.log(something.ggg); return {}; }); ``` --------- Co-authored-by: Tomek Zawadzki <tomasz.zawadzki@swmansion.com>
Is anyone getting this issue again? It's happening only on Android Release builds. |
@thespacemanatee me too, im getting this issue again |
getting a similar issue as well. |
I get this error when I'm running in debug mode, then using developer settings to change to release mode. I find rebuilding and using |
Description
I've switched from version 2.14.4 to the latest version 3.0.1 and get the error
Maximum call stack size exceeded
in the functionmakeShareableCloneRecursive
from reanimated.Steps to reproduce
I can't seem to isolate the issue, but it happened after upgrading to the latest version.
I've updated the Pods and reinstalled the App.
What could cause this kind of issue?
Snack or a link to a repository
Reanimated version
3.0.1
React Native version
0.71.0
Platforms
iOS
JavaScript runtime
Hermes
Workflow
React Native (without Expo)
Architecture
Paper (Old Architecture)
Build type
Debug mode
Device
Real device
Device model
iPhone 12 mini
Acknowledgements
Yes
The text was updated successfully, but these errors were encountered: