Open d4vidi opened 1 year ago
:warning: | Newer Version of React Native is Available! |
---|---|
:information_source: | You are on a supported minor version, but it looks like there's a newer patch available - 0.70.9. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases. |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Still requires attention. Please help out 🙏🏻
Ping
It's also valid for 2024.
Ping. we'd love to see this fixed for Maestro use
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
ping
Ping. we'd love to see this fixed for Maestro use
Is this still an issue on 0.76? Can we get a small repro for us to look into?
[!WARNING] Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:
- If your bug is UI related: a Snack
- If your bug is build/upgrade related: a project using our Reproducer Template
- Otherwise send us a Pull Request with the RNTesterPlayground.js edited to reproduce your bug.
Description
ReactContextBaseJavaModule
has a method calledgetCurrentActivity()
. When used insideReactContextBaseJavaModule.getConstants()
(actually,BaseJavaModule.getConstants()
) - namely, during app launch (Javascript init), it sometimes returns the current activity, and sometimesnull
in what seems to be a random behavior.React Native Version
0.70.7
Output of
npx react-native info
Steps to reproduce
react-native init
Create a fresh stub
NativeModule
that looks roughly like so:ReactNativeHost.getPackages()
method.index.js
(orapp.js
), add the following import at the top:react-native run-android
), and follow the logs usinglogcat
. You will end up seeing something like this, in consequent runs:(and so on and so forth)
Snack, code example, screenshot, or link to a repository
For starters, this report is in fact the reason behind this bug, which has been reported by me to the
react-native-launch-arguments
repo.As for the problem itself - it is rooted in the handling of
mCurrentActivity
, here:While
mCurrentActivity
is set inonHostResume()
, which is a bit late compared to when the activity gets initially created,getConstants()
can be called by RN's initialization sequence in very early stages. Add to that the fact the two occur in an asynchronous way (i.e. in different, async threads) - you get that the call togetCurrentActivity()
is very likely to miss the completion of the initialization ofReactContext.mCurrentActivity
. These circumstances induce the mentioned behavior, which is highly nondeterministic and "feels random".Solutions
There are quite a few nonoverlapping alternatives to how this can be resolved: