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
This commit is contained in:
Pieter De Baets
2025-03-28 04:17:20 -07:00
committed by Facebook GitHub Bot
parent 6877263003
commit 6dd5a838c3
@@ -83,7 +83,7 @@ internal class EventEmitterImpl(
logSoftException(
TAG,
ReactNoCrashSoftException(
"Cannot get RCTEventEmitter from Context, no active Catalyst instance!"))
"Cannot get RCTEventEmitter without active Catalyst instance!"))
}
}
return legacyEventEmitter
@@ -100,15 +100,15 @@ internal class EventEmitterImpl(
) {
@UIManagerType val uiManagerType = getUIManagerType(targetTag, surfaceId)
if (uiManagerType == UIManagerType.FABRIC) {
checkNotNull(fabricEventEmitter)
.receiveEvent(
surfaceId,
targetTag,
eventName,
canCoalesceEvent,
customCoalesceKey,
params,
category)
val fabricEventEmitter = fabricEventEmitter
if (fabricEventEmitter == null) {
logSoftException(
TAG,
ReactNoCrashSoftException("No fabricEventEmitter registered, cannot dispatch event"))
} else {
fabricEventEmitter.receiveEvent(
surfaceId, targetTag, eventName, canCoalesceEvent, customCoalesceKey, params, category)
}
} else if (uiManagerType == UIManagerType.LEGACY) {
ensureLegacyEventEmitter()?.receiveEvent(targetTag, eventName, params)
}