Skip to content

Commit 6dd5a83

Browse files
javachefacebook-github-bot
authored andcommitted
Do not crash when event is emitted when ReactInstance is reloaded
Summary: Regression introduced in D71735505 where I tried to ensure fabricEventEmitter was always non-null. Instead log a soft error when this happens, so we don't drop the event silently. Changelog: [Android][Fixed] Fixed crash when event is emitted after instance is shutdown Reviewed By: mdvacca Differential Revision: D71967092 fbshipit-source-id: 990b6414b41a2709d70a6deae38f5aa043203a20
1 parent 6877263 commit 6dd5a83

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventEmitterImpl.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ internal class EventEmitterImpl(
8383
logSoftException(
8484
TAG,
8585
ReactNoCrashSoftException(
86-
"Cannot get RCTEventEmitter from Context, no active Catalyst instance!"))
86+
"Cannot get RCTEventEmitter without active Catalyst instance!"))
8787
}
8888
}
8989
return legacyEventEmitter
@@ -100,15 +100,15 @@ internal class EventEmitterImpl(
100100
) {
101101
@UIManagerType val uiManagerType = getUIManagerType(targetTag, surfaceId)
102102
if (uiManagerType == UIManagerType.FABRIC) {
103-
checkNotNull(fabricEventEmitter)
104-
.receiveEvent(
105-
surfaceId,
106-
targetTag,
107-
eventName,
108-
canCoalesceEvent,
109-
customCoalesceKey,
110-
params,
111-
category)
103+
val fabricEventEmitter = fabricEventEmitter
104+
if (fabricEventEmitter == null) {
105+
logSoftException(
106+
TAG,
107+
ReactNoCrashSoftException("No fabricEventEmitter registered, cannot dispatch event"))
108+
} else {
109+
fabricEventEmitter.receiveEvent(
110+
surfaceId, targetTag, eventName, canCoalesceEvent, customCoalesceKey, params, category)
111+
}
112112
} else if (uiManagerType == UIManagerType.LEGACY) {
113113
ensureLegacyEventEmitter()?.receiveEvent(targetTag, eventName, params)
114114
}

0 commit comments

Comments
 (0)