InteractionManager.runAfterInteractions not running at all! (In Production/Release builds)
See original GitHub issueDescription
I am using a lot of InteractionManager.runAfterInteractions(() => ...)
calls throughout my project.
For example, I have a feed of multiple posts in my HomeScreen (Tab Navigator) and each post has useEffect
and useFocusEffect
hooks which call InteractionManager.runAfterInteractions
inside the hook to schedule loading extra post data after some animations have completed. “Some animations” = mostly navigation transitions from react-navigation, but since the post items specifically are inside a Tab Navigator, no navigation transitions/animations are run so this should fire almost immediately.
In development/debug build everything works fine, but once I build for production/release, the extra post data never gets loaded, a test Alert.alert(...)
I’ve put in there never gets shown, and my animations will never start, causing my app to be fully stuck.
I have added a GlobalErrorHandler
callback to my entry point (App.tsx
) since I thought “hey, maybe some JS error is thrown and execution is stopped?”:
const defaultErrorHandler = ErrorUtils.getGlobalHandler();
ErrorUtils.setGlobalHandler((error, isFatal) => {
Alert.alert(`Unexpected ${isFatal ? 'fatal error' : 'error'}!`, `Unexpected error occured! ${JSON.stringify(error)}`);
Logger.logError(isFatal ? 'A fatal, unhandled error occured!' : 'An unhandled error occured!', error);
if (defaultErrorHandler) defaultErrorHandler(error, isFatal);
});
but this doesn’t get called either.
Unfortunately, since this only happens on production/release builds, I’m having a hard time debugging this. I will happily provide any extra information needed.
Extra Details
- I’m using react-navigation, so this might cause a problem I suppose. My root view is a
NavigationContainer
, and inside of it, I conditionally render theLoginStackNavigator
or theHomeStackNavigator
depending if the user is logged in or not. - I’m using react-native-screens (because of react-navigation), but I call the
enableScreens()
function at the top of my entry point (App.tsx
):import { enableScreens } from 'react-native-screens'; enableScreens();
- I’m using react-native-gesture-handler (because of react-navigation), but I import the library at the top of my entry point (
App.tsx
):import 'react-native-gesture-handler';
- I’m using react-native-vector-icons, and somehow those Icons won’t get shown either. Issue for this: https://github.com/oblador/react-native-vector-icons/issues/1208
Current Behavior
Right now, the InteractionManager does not call the callback function at all, causing my app to be “broken”. Data is never getting loaded, delayed animations are not getting started, etc.
Expected Behavior
The InteractionManager should call the callback after animations have finished. (Which, on a Tab navigator, should be instantly.)
Screenshots
Debug/Development Build | Release/Production Build |
---|---|
Everything working fine, all InteractionManager.runAfterInteraction callbacks inside my useEffect hooks are being called.
|
Everything is broken, InteractionManager.runAfterInteraction callbacks inside my useEffect hooks are not being called, the text for the post is not being loaded (which is inside an InteractionManager.runAfterInteraction callback), and weirdly the react-native-vector-icons are not being displayed. no idea why that's the case, since that has nothing to do with an InteractionManager.runAfterInteraction callback.
|
How to reproduce
- Create awesome app
- Use
react-navigation
for navigation, create NavigationContainer, in my case a Stack Navigator containing a Tab Navigator (Home) and a “Post Details Screen”. - Add
InteractionManager.runAfterInteractions(() => ...)
callbacks in your components (e.g.useEffect()
hook) - Callbacks will be called in debug, but never in release
Navigation Structure
Dumbed down, I have the following Navigation Structure:
NavigationContainer
Stack.Navigator
fromcreateNativeStackNavigator
- Some Screens like an Add Screen which are irrelevant here
- A
Stack.Navigator
fromcreateStackNavigator
(not native, because I need react-navigation-shared-element)- Bottom Tabs with 4 Screens from
createBottomTabNavigator
- Post Details Screen which is just a simple Screen.
- Bottom Tabs with 4 Screens from
My Environment
software | version |
---|---|
iOS or Android | iOS, 13.5.1 |
@react-navigation/native | 5.7.1 |
react-native-screens | ^2.9.0 |
react-native | 0.63.2 |
react-native-gesture-handler | ^1.7.0 |
@react-native-community/masked-view | ^0.1.10 |
react-native-reanimated | ^1.10.1 |
react-native-safe-area-context | ^3.0.7 |
node | v14.4.0 |
npm or yarn | npm, 6.14.6 |
Conclusion
I would really appreciate some help with this. I am having an incredibly hard time finding the cause for this and cannot release my app for production… I have already opened issues for this here:
- https://github.com/facebook/react-native/issues/29421
- https://github.com/react-navigation/react-navigation/issues/8606
I have tried rewriting my app to use wix/react-native-navigation, and noticed that all InteractionManagers work correctly there.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
incase this helps someone… requestAnimationFrame is a great alternative! Its also quicker since it waits until there are enough frames to fire the function.
Yes, I tried eliminating all other causes and finally came to the root of the problem. It’s because of the
react-navigation-shared-element
library, created an issue over there: https://github.com/IjzerenHein/react-navigation-shared-element/issues/94. Hopefully it will get resolved soon, don’t want to rewrite everything in react-native-navigation 😦Thanks for your help @WoLewicki.