-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Fix crash animated #51442
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
base: main
Are you sure you want to change the base?
Fix crash animated #51442
Conversation
When an array of styles are passed its get flattened here react-native/packages/react-native/Libraries/Animated/nodes/AnimatedStyle.js Lines 95 to 97 in f169754
Now if array with animated object keys is passed to flattened style
The result is below
It can be seen that react-native/packages/react-native/Libraries/Animated/nodes/AnimatedStyle.js Lines 100 to 106 in f169754
We don't recieve any animated nodes cause it doesn't exist in flattened array causing it to return null. These tricks it into passing an style array(before flattening) with animated values to View component which causes this crash. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
7c24e77
to
66338d7
Compare
@rshest has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this. Please add a unit test that shows how this behaviour previously broke.
Please also revert the changes to LogBoxInspectorSourceMapStatus
Thanks so much for the review, @javache! 🙏 .
However, it seems to pass even in scenarios where the component crashes on device. Also we need to update the snapshot for as the current fix involves flattening style arrays passed to Animated. The snapshot for LogBoxInspectorSourceMapStatus still expects a nested style array, which no longer reflects the updated structure. |
Instead of flattening, let's make sure all props passed through have values applied. You won't see this in jest, since processTransform is only called at the mounting layer. You'd need to validate there's no more Animated.Value in the final props. |
Thanks so much for the response, @javache! 🙏 You're absolutely right — though from what I understand, validating all the props might not be very helpful in this case, since they’ll likely be overwritten anyway during the later stages when styles are further flattened (especially in the cases that are currently crashing). Also, to properly apply all the style values when props are passed, it seems we would need to modify createAnimatedStyle itself to support working with style arrays directly, rather than flattened style object. react-native/packages/react-native/Libraries/Animated/nodes/AnimatedStyle.js Lines 96 to 104 in f169754
Please do correct me if I’ve misunderstood anything — happy to adjust the approach accordingly! |
Hey @javache , I was thinking about this yesterday night and now I think we can do this too .
Should we do something like this ? Whats your opinion? |
I think the fix you're looking for needs to be in
|
It's not super clear why we are flattening props there when we can see that in the end a series of unflattened props are passed through to the host component - that's incorrect. |
Hey @javache , |
Good catch. Perhaps that's a bug that should be fixed here first? If there's an animated value in the unflattened style we should still allocate the Animated.Style. cc @yungsters |
Summary:
Fixes #51395 .
Changelog:
[GENERAL][FIXED]Crash when Animated value & primitive value used together
Test Plan:
Can be tested on RNTester with