Skip to content

Commit

Permalink
Fail silently in AppStateModule.sendEvent if CatalystInstance is not …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Apr 7, 2020
1 parent a37e45a commit c4806fa
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,18 @@ private WritableMap createAppStateEventMap() {
}

private void sendEvent(String eventName, @Nullable Object data) {
ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
ReactApplicationContext reactApplicationContext = getReactApplicationContext();

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

private void sendAppStateChangeEvent() {
Expand Down

0 comments on commit c4806fa

Please sign in to comment.