Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.facebook.react.uimanager.IllegalViewOperationException #17178

Closed
henrikra opened this issue Dec 13, 2017 · 29 comments
Closed

com.facebook.react.uimanager.IllegalViewOperationException #17178

henrikra opened this issue Dec 13, 2017 · 29 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@henrikra
Copy link

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

  1. Have Android phone
  2. Add LayoutAnimation to some of your components
  3. App crashes randomly

Expected Behavior

The UIImplementation is trying to add some View which is not there yet.

Actual Behavior

  1. Happening only on Android
  2. OS versions having this crash so far:
    image

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 f2c6877 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=%E2%9C%93&q=%22Trying+to+add%22&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:
#13984
#17092
#16412
#14944
#14768
#10745

@a6051529

This comment has been minimized.

@mauscoelho

This comment has been minimized.

2 similar comments
@linxiaoru

This comment has been minimized.

@hpyfei

This comment has been minimized.

@filipef101
Copy link

filipef101 commented Feb 5, 2018

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

@DanGDroid
Copy link

same here
#15698

@iinsta
Copy link

iinsta commented Feb 19, 2018

Same:

com.facebook.react.uimanager.IllegalViewOperationException: Trying to add unknown view tag: 170
	at com.facebook.react.uimanager.UIImplementation.setChildren(UIImplementation.java:396)
	at com.facebook.react.uimanager.UIManagerModule.setChildren(UIManagerModule.java:310)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:363)
	at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162)
	at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
	at android.os.Handler.handleCallback(Handler.java:754)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
	at android.os.Looper.loop(Looper.java:163)
	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
	at java.lang.Thread.run(Thread.java:760)

@filipef101

This comment has been minimized.

@filipef101
Copy link

May also be because you have a modal or lightbox that needs to be dismissed first

@iinsta

This comment has been minimized.

@react-native-bot
Copy link
Collaborator

Thanks for posting this! It looks like you may not be using the latest version of React Native, v0.53.0, released on January 2018. Can you make sure this issue can still be reproduced in the latest version?

I am going to close this, but please feel free to open a new issue if you are able to confirm that this is still a problem in v0.53.0 or newer.

How to ContributeWhat to Expect from Maintainers

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon. labels Feb 24, 2018
@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Feb 24, 2018
@ssuchanowski
Copy link

Can anyone confirm that it has been fixed in most recent RN version?

@filipef101

This comment has been minimized.

@ssuchanowski
Copy link

Any hint on where to look? I have a hybrid Java + RN app and so far I cannot reproduce it on my devices (different ones are shipping now) but we get a lot of those exceptions on production.

@filipef101

This comment has been minimized.

@ssuchanowski

This comment has been minimized.

@filipef101

This comment has been minimized.

@filipef101
Copy link

I was doing a navigation reset with a modal or lightbox open, after dismissing it before reseting nav it was fixed, but Im not sure if thats the cause

@filipef101

This comment has been minimized.

@ssuchanowski

This comment has been minimized.

@Frank1234
Copy link

Frank1234 commented May 13, 2018

Here is a very simple demo project that reproduces this bug: #19233 . Sadly, it reproduces not only this bug, but many other bugs as well, in a random manner. But clicking the button in the app a few times will definitely cause this exact exception.

@SudoPlz
Copy link
Contributor

SudoPlz commented Jun 5, 2018

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

  1. createView
  2. setChildren
  3. manageChildren
  4. removeRootShadowNode

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?

@SudoPlz
Copy link
Contributor

SudoPlz commented Jun 6, 2018

If you don't know how to pass a new UIImplementationProvider you have to go to your MainApplication.java file, find the creation of ReactNativeHost:

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }
...bla bla blah

and add the following function:

protected UIImplementationProvider getUIImplementationProvider() {
    return new YourCustomUIImplementationProvider();
}

so that it now looks like this:

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    protected UIImplementationProvider getUIImplementationProvider() {
        return new YourCustomUIImplementationProvider();
    }
...bla bla blah

@brunolemos
Copy link
Contributor

brunolemos commented Jun 7, 2018

@SudoPlz if you want the core team to do something you will probably need to create a new issue or PR; they may not look at closed issues.

This code should be the default, right? I don't think users should have to do anything on their end to prevent this crash.

@SudoPlz
Copy link
Contributor

SudoPlz commented Jun 7, 2018

Yeah, I think this should be default behaviour.. I'll open a PR later on.

@Dantalion
Copy link

@SudoPlz Thank you very much and great work! I hope that your PR will be accepted asap!

@wesleymooiman
Copy link

@SudoPlz did you create a pr to fix this problem?

@SudoPlz
Copy link
Contributor

SudoPlz commented Jul 4, 2018

@wesleymooiman ^

@beausmith
Copy link
Contributor

It seems Android doesn't like converting non-Boolean values into booleans. So I'm now ensuring that all values which I'm using as booleans are in fact, booleans.

I have changed all occurrences similar to this where foo may not be true or false:

{foo && <MyComponent />}

…into one of these which converts foo into a boolean if it is not:

{!!foo && <MyComponent />}
{Boolean(foo) && <MyComponent />}

dev6james referenced this issue in LordParsley/react-native-navigation Sep 27, 2018
SudoPlz referenced this issue Sep 27, 2018
Summary:
@public
This diff deprecates and deletes the UIImplementationProvider class.

It is not required to create an UIImplementation provider anymore, from now on the UIImplementation is created inside the UIManagerModule.

If you are using the UIImplementationProvider to create a ReactInstanceManager
e.g.:

```
    ReactInstanceManager =
        getReactInstanceManagerBuilder()
            ...
            .setUIImplementationProvider(...)
            ...
            .build();
```

Then you should just remove that line:
```
    ReactInstanceManager =
        getReactInstanceManagerBuilder()
            .set.....
            .build();
```

Reviewed By: achen1

Differential Revision: D8650376

fbshipit-source-id: 8d883295d8bf6578a99685edf6a2a84c6d0df0cf
SudoPlz added a commit to SudoPlz/react-native that referenced this issue Nov 29, 2018
SudoPlz added a commit to SudoPlz/react-native that referenced this issue Feb 21, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Feb 24, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Feb 24, 2019
SudoPlz added a commit to SudoPlz/react-native that referenced this issue Mar 27, 2019
facebook-github-bot pushed a commit that referenced this issue Mar 27, 2019
…adowNodeRegistry (#20025)

Summary:
Fixes: #17178

[ANDROID] [Fixes] - UIImplementation: Now enforcing atomic mutation of the shadowNodeRegistry
Pull Request resolved: #20025

Differential Revision: D14652876

Pulled By: shergin

fbshipit-source-id: 7b20bad4cb43d3e6f09e2037e3c60a217a91d273
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet