colorfy-software / react-native-modalfy

🥞 Modal citizen of React Native.
https://colorfy-software.gitbook.io/react-native-modalfy
MIT License
1.16k stars 48 forks source link

Crash report when calling closeAllModals() and openModal(), undefined is not an object #73

Closed okcompewter closed 2 years ago

okcompewter commented 2 years ago

Thanks for your great library!

I am currently on v3.0.1, and getting a lot of crash reports dealing with "undefined is not an object".

Can this fail more gracefully (just early return) when undefined is not an object?

closeAllModals()

Fatal Exception: com.facebook.react.common.c
TypeError: undefined is not an object (evaluating '(0,v.default)(n.stack.openedItems).slice(-1)[0].hash') This error is located at: in l in p in RCTView in Unknown in R in Unknown in RCTView in Unknown in R in Unknown in p in y in P in RCTView in Unknown in l in RCTView in Unknown in R in Unknown in PanGestureHandler in S in w in RCTView in Unknown in v in l in C in x in p in RCTView in Unknown in M in b in C in l in v in Unknown in Unknown in Unknown in Unknown in B in Unknown in RCTView in Unknown in RCTView in Unknown in b, stack: <unknown>@1410:3955 o@1410:503 f@1410:3724 closeAllModals@1410:4352 <unknown>@1627:3754 Ul@63:66789 Ha@63:84456 Ea@63:78229 Ea@-1 ft@63:26099 _a@63:75396 jr@63:48144 jr@-1 <unknown>@1634:5683 _@1337:2386 <unknown>@1337:2603 value@28:1292 <unknown>@1335:1355 value@28:1292 <unknown>@530:1635 value@28:1292 value@44:3556 <unknown>@44:673 value@44:2503 value@44:645 value@-1

openModal()

Fatal Exception: com.facebook.react.common.c
TypeError: undefined is not an object (evaluating 'f.default.getState().currentModal') This error is located at: in l in p in RCTView in Unknown in R in Unknown in RCTView in Unknown in R in Unknown in p in y in P in RCTView in Unknown in l in RCTView in Unknown in R in Unknown in PanGestureHandler in S in w in RCTView in Unknown in v in l in C in x in p in RCTView in Unknown in M in b in C in l in v in Unknown in Unknown in Unknown in Unknown in B in Unknown in RCTView in Unknown in RCTView in Unknown in b, stack: openModal@1423:1013 <unknown>@1635:1086 Ul@63:66789 Ha@63:84456 <unknown>@63:82784 Y@179:2883 e@179:400 <unknown>@91:1256 k@91:499 callTimers@91:2652 value@44:3556 <unknown>@44:673 value@44:2503 value@44:645 value@-1
okcompewter commented 2 years ago

I can easily reproduce this with a simple button that calls closeAllModals(). When there are no modals open, the app crashes with the first error above.

I found a workaround so far by using currentModal && closeAllModals(), that seems to prevent this crash (it only calls closeAllModals if there is some currentModal that exists).

CharlesMangwa commented 2 years ago

Hey @okcompewter! Thanks for reporting this, will work on a patch with these fixes. Will keep you posted.

okcompewter commented 2 years ago

Thanks so much! Really appreciate your work :)

CharlesMangwa commented 2 years ago

OK turns out the fix for the crash was easier than I thought, will be in next release!

okcompewter commented 2 years ago

Woohoo! Thanks for the optional chaining fix. Give me a holler when the release is out :)

CharlesMangwa commented 2 years ago

🚀 v3.2.0 is out with the fix (and a few of other nice things 😁)!

okcompewter commented 2 years ago

I've updated to 3.2.0, and it seems to have fixed a lot of errors, but I'm still seeing this one crash log in production occasionally:

Are you sure the recent optional chaining fix doesn't need done elsewhere as well?

When looking at your fix, before the slice check: currentModalHash: [...currentState.stack.openedItems].slice(-1)[0]?.hash,

may it be possible that any of these are also undefined: currentState or currentState.stack or currentState.stack.openedItems ?

The crash:

Fatal Exception: com.facebook.react.common.c: TypeError: undefined is not an object (evaluating 'f.default.getState().currentModal')

This error is located at:
    in l
    in p
    in RCTView
    in Unknown
    in R
    in Unknown
    in RCTView
    in Unknown
    in R
    in Unknown
    in p
    in y
    in P
    in RCTView
    in Unknown
    in l
    in RCTView
    in Unknown
    in R
    in Unknown
    in PanGestureHandler
    in S
    in w
    in RCTView
    in Unknown
    in v
    in l
    in C
    in x
    in p
    in RCTView
    in Unknown
    in M
    in b
    in C
    in l
    in v
    in Unknown
    in Unknown
    in Unknown
    in Unknown
    in B
    in Unknown
    in RCTView
    in Unknown
    in RCTView
    in Unknown
    in b, stack:
C:\Users\...\node_modules\react-native-modalfy\src\lib\ModalProvider.tsx:39:openModal
C:\Users\...\app\screens\raid-screen\raid-screen.tsx:29:useEffect$argument_0
C:\Users\...\node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-prod.js:5467:commitHookEffectListMount
C:\Users\...\node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-prod.js:7003:flushPassiveEffects
C:\Users\...\node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-prod.js:6849:scheduleCallback$argument_1
C:\Users\...\node_modules\scheduler\cjs\scheduler.production.min.js:16:V
C:\Users\...\node_modules\scheduler\cjs\scheduler.production.min.js:10:w
C:\Users\...\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:214:_allocateCallback$argument_0
C:\Users\...\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:112:_callTimer
C:\Users\...\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:357:callTimers
C:\Users\...\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:419:__callFunction
C:\Users\...\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:116:__guard$argument_0
C:\Users\...\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:370:__guard
C:\Users\...\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:115:callFunctionReturnFlushedQueue
value@-1

       at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:83)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
       at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
       at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
       at java.lang.Thread.run(Thread.java:920)
okcompewter commented 2 years ago

Created new Issue 78.