Skip to content

Commit c4806fa

Browse files
JoshuaGrossfacebook-github-bot
authored andcommitted
Fail silently in AppStateModule.sendEvent if CatalystInstance is not available
Summary: According to our logs, 80% of these warnings are coming from AppStateModule. It's not particularly interesting or surprising that the CatalystInstance would be torn down when there's some app event, so let's stop taking up DB space with a useless message. Reviewed By: ejanzer, mdvacca Differential Revision: D20879426 fbshipit-source-id: b1182461aed4a66d82cb34bbd4b12782af6ed7b3
1 parent a37e45a commit c4806fa

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,18 @@ private WritableMap createAppStateEventMap() {
9292
}
9393

9494
private void sendEvent(String eventName, @Nullable Object data) {
95-
ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
95+
ReactApplicationContext reactApplicationContext = getReactApplicationContext();
9696

97-
if (reactApplicationContext != null) {
98-
reactApplicationContext.getJSModule(RCTDeviceEventEmitter.class).emit(eventName, data);
97+
if (reactApplicationContext == null) {
98+
return;
9999
}
100+
// We don't gain anything interesting from logging here, and it's an extremely common
101+
// race condition for an AppState event to be triggered as the Catalyst instance is being
102+
// set up or torn down. So, just fail silently here.
103+
if (!reactApplicationContext.hasActiveCatalystInstance()) {
104+
return;
105+
}
106+
reactApplicationContext.getJSModule(RCTDeviceEventEmitter.class).emit(eventName, data);
100107
}
101108

102109
private void sendAppStateChangeEvent() {

0 commit comments

Comments
 (0)