react-native-reanimated: [android][release] makeShareableCloneRecursive Call Stack Size Exceeded
Description
I’ll start by saying that I’ve spent many days on this and already looked at #4140, #4177, #4367 and #4475, and this is a separate issue. I also created an issue at expo/expo#23297 but I don’t think it’s expo’s fault because I could not reproduce this on their bare template. It’s worth noting that this does not occur on react-native@0.71
or expo@48
.
The bug, for me, only occurs on the Android release
build or the debug
build with the JS Dev Mode
disabled.
This gave me the idea to search for all __DEV__
flags within the installed version in my node_modules
and flip all of them so that I can see the error in dev mode and get a nicer stacktrace. Here’s what I got:
This narrows down the problem quite well, and I found that the following patch solves my issue:
diff --git a/node_modules/react-native-reanimated/src/reanimated2/shareables.ts b/node_modules/react-native-reanimated/src/reanimated2/shareables.ts
index 4f358f4..8be3e2b 100644
--- a/node_modules/react-native-reanimated/src/reanimated2/shareables.ts
+++ b/node_modules/react-native-reanimated/src/reanimated2/shareables.ts
@@ -1,6 +1,6 @@
import NativeReanimatedModule from './NativeReanimated';
-import { ShareableRef } from './commonTypes';
import { shouldBeUseWeb } from './PlatformChecker';
+import { ShareableRef } from './commonTypes';
import { registerWorkletStackDetails } from './errors';
import { jsVersion } from './platform-specific/jsVersion';
@@ -146,8 +146,9 @@ export function makeShareableCloneRecursive<T>(
value.__workletHash,
value.__stackDetails
);
- delete value.__stackDetails;
}
+ // TODO: This is the fixes Maximum call stack size exceeded error
+ delete value.__stackDetails;
// to save on transferring static __initData field of worklet structure
// we request shareable value to persist its UI counterpart. This means
// that the __initData field that contains long strings represeting the
Obviously, this is not ideal and doesn’t seem like the official solution (why would stackDetails have anything to do with the fix?), so I’m hoping the team will have a better idea. Thanks for the great work!
Steps to reproduce
I could not reproduce this on the bare expo template, but I’m linking it anyway. I hope the patch I provided above will give some clue as to why it only happens on some projects.
- Install
react-native-reanimated@3.3.0
npx pod-install
- Importing the library using
import 'react-native-reanimated'
inApp.tsx
is enough to trigger the bug
Snack or a link to a repository
Reanimated version
3.3.0
React Native version
0.72.1
Platforms
Android
JavaScript runtime
Hermes
Workflow
Expo bare workflow
Architecture
Paper (Old Architecture)
Build type
Release mode
Device
Android emulator
Device model
Pixel 7 Pro (Android 13) and Pixel 3a (Android 10)
Acknowledgements
Yes
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 29 (18 by maintainers)
Commits related to this issue
- Detected debug version of the worklet in release bundle (#4732) ## Summary Fixes: https://github.com/software-mansion/react-native-reanimated/issues/4690 It may happen when one of the user dependen... — committed to software-mansion/react-native-reanimated by piaskowyk a year ago
- Improve detecting production bundle in Babel plugin (#4747) <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that... — committed to software-mansion/react-native-reanimated by tomekzaw a year ago
@hirbod Just tried it and the issue still occurs 🤔 @tomekzaw I patched
plugin.js
with #4747 but the issue still occurs. Even just returningtrue
doesn’t work, what gives?I’m getting a similar issue on android in release mode, in development everything works fine.
Hey @thespacemanatee, thanks for reporting this issue, investigating the root cause as well as providing the workaround.
Sure, we will investigate this issue once we finish investigating other issues that we’re looking into right now.
PS: the reason why I said your syntax looks wrong to me is because you didn’t include
--variant
.@tomekzaw this matches exactly my issue. So the uppercase R was the main problem for me. I retried couple of times and could reproduce this reliable.
@hirbod @thespacemanatee I think I found something. This is how we detect dev/release bundle in Reanimated Babel plugin:
https://github.com/software-mansion/react-native-reanimated/blob/5d4e02e0ded7e7acc2f23e277e68c592fe0e2e2b/plugin/src/utils.ts#L1-L6
If you pass
Release
asBABEL_ENV
it will probably still generate dev bundle.This issue is also blocking our release right now. The crash only occurs in release mode (–variant Release) and works fine in dev mode.
@hirbod sorry I was typing on my phone. This is very helpful, thanks. There isn’t really any documentation about configuring
NODE_ENV
so I guess we’ll have to pass that env variable with every build command?@tomekzaw @hirbod If my variant is
productionRelease
, how would I go about this? The funny thing is that I triednpx expo run:android productionrelease
and it works, and thereafternpx expo run:android productionRelease
also works as well, until it stops working randomly. I think it’s related to expo but I’m not sure how to phrase it as an issue.@tomekzaw the issue occurs again now and then and doesn’t seem to have a deterministic solution, @hirbod could you confirm if it works every time and on different machines?
I also think it’s weird that this issue only happens to Android. If it is what the team says it is, that the Android build cache needs to be cleared, then why does the solution in #4737 suggest fixes in the JS-land (solution 2)? And why does this affect Android only and not iOS as well? More investigations need to be done to find the root cause.
@tomekzaw, the only thing that might support your guess is that I can see the Expo CLI outputs
env: load .env.development
, even though I did pass the--variant Release
parameter. There are no errors in SDK 48. Maybe something happened between these versions.I need to do some quick research on how to dump the release bundle, never did that before.