react-native: com.facebook.react.uimanager.IllegalViewOperationException
Is this a bug report?
Yeah.
Have you read the Contributing Guidelines?
Yeah.
Environment
Environment: OS: macOS High Sierra 10.13.1 Node: 8.9.2 Yarn: 1.3.2 npm: 5.5.1 Watchman: 4.7.0 Xcode: Xcode 9.2 Build version 9C40b Android Studio: 2.3 AI-162.4069837
Packages: (wanted => installed) react: 16.0.0 => 16.0.0 react-native: 0.50.3 => 0.50.3
Steps to Reproduce
- Have Android phone
- Add
LayoutAnimation
to some of your components - App crashes randomly
Expected Behavior
The UIImplementation
is trying to add some View
which is not there yet.
Actual Behavior
- Happening only on Android
- OS versions having this crash so far:
Logs:
com.facebook.react.uimanager.IllegalViewOperationException Trying to add unknown view tag: 430
UIImplementation.java:396 com.facebook.react.uimanager.UIImplementation.setChildren
UIManagerModule.java:310 com.facebook.react.uimanager.UIManagerModule.setChildren
Method.java:-2 java.lang.reflect.Method.invoke
JavaMethodWrapper.java:363 com.facebook.react.bridge.JavaMethodWrapper.invoke
JavaModuleWrapper.java:162 com.facebook.react.bridge.JavaModuleWrapper.invoke
NativeRunnable.java:-2 com.facebook.react.bridge.queue.NativeRunnable.run
Handler.java:789 android.os.Handler.handleCallback
Handler.java:98 android.os.Handler.dispatchMessage
MessageQueueThreadHandler.java:31 com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage
Looper.java:164 android.os.Looper.loop
MessageQueueThreadImpl.java:194 com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run
Thread.java:764 java.lang.Thread.run
Backstory
I have developed with RN for over a year now. And this crash has been there always. Some people say it is related to LayoutAnimation but I have gotten it already before that. Recently there were fix commits to similar issue https://github.com/facebook/react-native/commit/f2c6877b91963878f36ec42f5f865427bc69488c But I think they don’t fix this because looks like the lines that can have this crash are here: https://github.com/facebook/react-native/search?utf8=✓&q=“Trying+to+add”&type=
This crash has been so long in RN so maybe it would be time to fix it? Tell me if there is anything I could do for help 😃
Reproducible Demo
Unfortenately I can’t reproduce this on my Android 😦
Similar issues: https://github.com/facebook/react-native/issues/13984 https://github.com/facebook/react-native/issues/17092 https://github.com/facebook/react-native/issues/16412 https://github.com/facebook/react-native/issues/14944 https://github.com/facebook/react-native/issues/14768 https://github.com/facebook/react-native/issues/10745
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 14
- Comments: 29 (6 by maintainers)
Commits related to this issue
- Now using a thread lock on UIImplementation methods that mutate the node children sparse array - Fixes: https://github.com/facebook/react-native/issues/17178#issuecomment-395858863 — committed to SudoPlz/react-native by SudoPlz 6 years ago
- Fix React Native 0.57 compatibility (https://github.com/wix/react-native-navigation/issues/3831) — committed to LordParsley/react-native-navigation by LordParsley 6 years ago
- Remove UIImplementationProvider class and refactor UIManagerModule Summary: @public This diff deprecates and deletes the UIImplementationProvider class. It is not required to create an UIImplementat... — committed to facebook/react-native by mdvacca 6 years ago
- Now using a thread lock on UIImplementation methods that mutate the node children sparse array - Fixes: https://github.com/facebook/react-native/issues/17178#issuecomment-395858863 — committed to SudoPlz/react-native by SudoPlz 6 years ago
- Now using a thread lock on UIImplementation methods that mutate the node children sparse array - Fixes: https://github.com/facebook/react-native/issues/17178#issuecomment-395858863 — committed to SudoPlz/react-native by SudoPlz 6 years ago
- Now using a thread lock on UIImplementation methods that mutate the node children sparse array - Fixes: https://github.com/facebook/react-native/issues/17178#issuecomment-395858863 — committed to SudoPlz/react-native by SudoPlz 6 years ago
- Enforced thread safety on UIImplementation methods that mutate the shadowNodeRegistry (#20025) Summary: Fixes: #17178 [ANDROID] [Fixes] - UIImplementation: Now enforcing atomic mutation of the shado... — committed to facebook/react-native by SudoPlz 5 years ago
I managed to spot exactly what’s causing that problem in
react-native
.So what happens behind the scenes is,
react-native
is trying to manipulate the shadowNode list at the same time some other thread is manipulating it.Specifically UIImplementation manipulates that list with the following methods
so if any of those get invoked at the same time, there’s a really high chance that the app will crash.
In our app we fixed that issue by providing a custom
UIImplementation
that looks like this:https://gist.github.com/SudoPlz/23ea2dee9772cb39e1e742034cdf8b98
as you can see we don’t allow those UIImplementation methods to run unsynchronised anymore.
We could constantly reproduce the issue on our end, but now that’s totally fixed. We pass the new UIImplementation provided through this method here.
I hope this post helps others, because it really took me A CRAZY amount of time to figure this out.
I really wonder though, is there a reason the facebook team kept that code unsynchronized?
If you don’t know how to pass a new
UIImplementationProvider
you have to go to yourMainApplication.java
file, find the creation ofReactNativeHost
:and add the following function:
so that it now looks like this:
Having same issue, some times random crash on navigation reset
EDIT: I think it was because I’m using wix navigation (react-native-navigation) My fork of it has it fixed, check the commit were I did it and patch your repo if you are using it
+1
Same:
+1
+1
Yeah, I think this should be default behaviour… I’ll open a PR later on.
Its not a react native issue, check your code
@wesleymooiman ^
@SudoPlz Thank you very much and great work! I hope that your PR will be accepted asap!
And if you are going to update react, go to 0.53 instead of 0.54 (less problems)
May also be because you have a modal or lightbox that needs to be dismissed first
Any solution to this problem? It causes random crash on the app.