I have found a bug in RCTRootView initialization logic, which we hit in a use case for wix/react-native-navigation.
When a root view is initialized, it checks if the bridge is still loading; if not, it calls bundleFinishedLoading: directly. However, it also always adds itself as an observer for RCTJavaScriptDidLoadNotification, in whose handler method it also calls bundleFinishedLoading:.
However it seems that the loading property of the bridge and RCTJavaScriptDidLoadNotification are not synchronized, and there is a gap between loading being set to NO and RCTJavaScriptDidLoadNotification firing. Whether this is a bug or not, I leave to you to decide. However, RCTRootView behaves incorrectly in the current condition; there exists a code path that can cause a nasty crash with the following error:
Expect all root views to have unique tag. Added 1 twice
From here.
If a new RCTRootView is created between some time after the bridge has starting loading and RCTJavaScriptDidLoadNotification has been dispatched for that bridge, the logic bug in RCTRootView causes -[RCTUIManager registerRootView:withSizeFlexibility:] to be called twice with the same root view, cause the aforementioned crash.
A simple fix is to remove the root view as observer to RCTJavaScriptDidLoadNotification in case _bridge.loading returns NO. However, it might be worth investigating whether loading and RCTJavaScriptDidLoadNotification should not be properly synchronized.
CC @javache @nicklockwood
same issue, maybe related with this commit
from v0.31.0-rc.0
same issue with v0.42.3
CC @majak
@javache Do you have any idea?
I believe I've done some investigation into this before. Since the bridge actually allows you to queue messages as soon as RCTBridge exists, we can probably enqueue the render call immediately instead of waiting for the bridge to load.
Just for reference: D4849610.
Please checkout https://github.com/facebook/react-native/commit/59378f71dbc059bb6d8eb75cf86148012a20ba09 and see if that resolves the issue for you. Thanks!
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.
Most helpful comment
same issue with v0.42.3