akveo / react-native-ui-kitten

:boom: React Native UI Library based on Eva Design System :new_moon_with_face::sparkles:Dark Mode
https://akveo.github.io/react-native-ui-kitten/
MIT License
10.19k stars 952 forks source link

fix: iOS app crash when UI manager isn't ready #1795

Open jgillick opened 7 months ago

jgillick commented 7 months ago

Please read and mark the following check list before creating a pull request:

Calling UIManager.measureInWindow can throw an exception and crash the app if the UIManager isn't defined yet (see nullthrows in the react native code). I have not been able to reproduce this directly, but have been getting a handful of app crash reports per day that point to this (see stack trace below).

My proposed solution is to catch the exception and then try again after a short delay. The delay is to prevent a possible infinite loop slowing down the app.

Stack trace

Error Got unexpected undefined 
    Users/runner/work/together/together/packages/dating-app/node_modules/nullthrows/nullthrows.js:7:23 nullthrows
    Users/runner/work/together/together/packages/dating-app/node_modules/react-native/Libraries/ReactNative/UIManager.js:88:40 measureInWindow
    Users/runner/work/together/together/packages/dating-app/node_modules/@ui-kitten/components/devsupport/components/measure/measure.component.js:60:48 measureSelf
    Users/runner/work/together/together/packages/dating-app/node_modules/@ui-kitten/components/devsupport/components/measure/measure.component.js:50:23 onUIManagerMeasure
    (native) apply
    Users/runner/work/together/together/packages/dating-app/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:474:12 __invokeCallback
    Users/runner/work/together/together/packages/dating-app/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:124:27 anonymous
    Users/runner/work/together/together/packages/dating-app/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:368:10 __guard
    Users/runner/work/together/together/packages/dating-app/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:123:16 invokeCallbackAndReturnFlushedQueue
jgillick commented 7 months ago

FYI, this PR seems to be a duplicate of https://github.com/akveo/react-native-ui-kitten/pull/1752 and https://github.com/akveo/react-native-ui-kitten/pull/1790, but resolves it differently.

Feel free to close this if you prefer the other solutions.