Skip to content

Commit 6a30d4b

Browse files
committed
fix(messaging, android): repair crash handling remote notifications
WritableNativeMap has a check to see if it is consumed or not when it is used, to prevent resolving a Promise in native code then attempting to modify it. We may use the same WritableNativeMap object twice though when handling deferred initial notifications. Crash repair is to store a copy so the Maps are distinct
1 parent b972cb6 commit 6a30d4b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/messaging/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingModule.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void getInitialNotification(Promise promise) {
8383
} else {
8484
remoteMessageMap = ReactNativeFirebaseMessagingSerializer.remoteMessageToWritableMap(remoteMessage);
8585
}
86-
if (remoteMessageMap != null){
86+
if (remoteMessageMap != null) {
8787
promise.resolve(remoteMessageMap);
8888
initialNotificationMap.put(messageId, true);
8989
return;
@@ -228,9 +228,10 @@ public void onNewIntent(Intent intent) {
228228
} else {
229229
remoteMessageMap = ReactNativeFirebaseMessagingSerializer.remoteMessageToWritableMap(remoteMessage);
230230
}
231-
232-
if (remoteMessageMap != null){
233-
initialNotification = remoteMessageMap;
231+
232+
if (remoteMessageMap != null) {
233+
// WritableNativeMap not be consumed twice. But it is resolved in future and in event below. Make a copy - issue #5231
234+
initialNotification = remoteMessageMap.copy();
234235
ReactNativeFirebaseMessagingReceiver.notifications.remove(messageId);
235236

236237
ReactNativeFirebaseEventEmitter emitter = ReactNativeFirebaseEventEmitter.getSharedInstance();

0 commit comments

Comments
 (0)