From 83696ea4c944b2be0b8fd9f2fc1db212800cbcf8 Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Fri, 15 Nov 2024 14:06:47 -0500 Subject: [PATCH] fix(android): rn74 forward-port onCatalystInstanceDestroy -> invalidate onCatalystInstanceDestroy is no longer calld as of rn74, so our teardown methods were not being called so we were orphaning listeners on rn 74+ this forward ports to the new invalidate API for rn74+ but leaves in place the old hook as an override for people on rn73- and just delegates to the new implementation --- .../ReactNativeFirebaseAppCheckModule.java | 4 ++-- .../common/ReactNativeFirebaseModule.java | 21 +++++++++++++++++-- .../auth/ReactNativeFirebaseAuthModule.java | 4 ++-- ...eactNativeFirebaseDatabaseQueryModule.java | 4 ++-- ...ReactNativeFirebaseDynamicLinksModule.java | 4 ++-- ...tiveFirebaseFirestoreCollectionModule.java | 4 ++-- ...NativeFirebaseFirestoreDocumentModule.java | 4 ++-- ...iveFirebaseFirestoreTransactionModule.java | 4 ++-- .../perf/ReactNativeFirebasePerfModule.java | 4 ++-- .../ReactNativeFirebaseConfigModule.java | 4 ++-- .../ReactNativeFirebaseStorageModule.java | 4 ++-- 11 files changed, 39 insertions(+), 22 deletions(-) diff --git a/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java b/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java index 9789917cf6..3c9b61dff4 100644 --- a/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java +++ b/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java @@ -100,8 +100,8 @@ private boolean isAppDebuggable() throws Exception { } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); Log.d(TAG, "instance-destroyed"); Iterator appCheckListenerIterator = mAppCheckListeners.entrySet().iterator(); diff --git a/packages/app/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java b/packages/app/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java index 353a4bf4ad..57850abd23 100644 --- a/packages/app/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java +++ b/packages/app/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java @@ -92,9 +92,26 @@ public final ExecutorService getTransactionalExecutor(String identifier) { return executorService.getTransactionalExecutor(identifier); } - @Override - @CallSuper + + // This is no longer called as of react-native 0.74 and is only here for + // compatibility with older versions. It delegates to thew new `invalidate` + // method, which all modules should implement now + // Remove this method when minimum supported react-native is 0.74 + /** @noinspection removal*/ + @SuppressWarnings({"deprecation", "removal"}) + @Deprecated public void onCatalystInstanceDestroy() { + // This should call the child class invalidate, which will then call super.invalidate, + // and everything will work correctly up and down the inheritance hierarchy to shut down + invalidate(); + } + + // This should have an @Override annotation but we cannot do + // that until our minimum supported react-native version is 0.74, since the + // method did not exist before then + @CallSuper + public void invalidate() { + super.invalidate(); executorService.shutdown(); } diff --git a/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java b/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java index c92ffd6412..06c73c7698 100644 --- a/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java +++ b/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java @@ -123,8 +123,8 @@ public void initialize() { } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); Log.d(TAG, "instance-destroyed"); Iterator authListenerIterator = mAuthListeners.entrySet().iterator(); diff --git a/packages/database/android/src/reactnative/java/io/invertase/firebase/database/ReactNativeFirebaseDatabaseQueryModule.java b/packages/database/android/src/reactnative/java/io/invertase/firebase/database/ReactNativeFirebaseDatabaseQueryModule.java index e8a397c2ac..6a016b128c 100644 --- a/packages/database/android/src/reactnative/java/io/invertase/firebase/database/ReactNativeFirebaseDatabaseQueryModule.java +++ b/packages/database/android/src/reactnative/java/io/invertase/firebase/database/ReactNativeFirebaseDatabaseQueryModule.java @@ -42,8 +42,8 @@ public class ReactNativeFirebaseDatabaseQueryModule extends ReactNativeFirebaseM } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); Iterator refIterator = queryMap.entrySet().iterator(); while (refIterator.hasNext()) { diff --git a/packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java b/packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java index 4dc402cec7..9e9e63caef 100644 --- a/packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java +++ b/packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java @@ -71,10 +71,10 @@ public class ReactNativeFirebaseDynamicLinksModule extends ReactNativeFirebaseMo } @Override - public void onCatalystInstanceDestroy() { + public void invalidate() { getReactApplicationContext().removeActivityEventListener(this); getReactApplicationContext().addLifecycleEventListener(this); - super.onCatalystInstanceDestroy(); + super.invalidate(); } @ReactMethod diff --git a/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreCollectionModule.java b/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreCollectionModule.java index b44b87170f..ecf8e21e42 100644 --- a/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreCollectionModule.java +++ b/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreCollectionModule.java @@ -42,8 +42,8 @@ public class ReactNativeFirebaseFirestoreCollectionModule extends ReactNativeFir } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); for (int i = 0, size = collectionSnapshotListeners.size(); i < size; i++) { int key = collectionSnapshotListeners.keyAt(i); diff --git a/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreDocumentModule.java b/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreDocumentModule.java index e99531b3f9..43c956cd9a 100644 --- a/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreDocumentModule.java +++ b/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreDocumentModule.java @@ -43,8 +43,8 @@ public class ReactNativeFirebaseFirestoreDocumentModule extends ReactNativeFireb } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); for (int i = 0, size = documentSnapshotListeners.size(); i < size; i++) { int key = documentSnapshotListeners.keyAt(i); diff --git a/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreTransactionModule.java b/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreTransactionModule.java index fd92061a09..e22c0b4950 100644 --- a/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreTransactionModule.java +++ b/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreTransactionModule.java @@ -45,7 +45,7 @@ public class ReactNativeFirebaseFirestoreTransactionModule extends ReactNativeFi } @Override - public void onCatalystInstanceDestroy() { + public void invalidate() { for (int i = 0, size = transactionHandlers.size(); i < size; i++) { int key = transactionHandlers.keyAt(i); ReactNativeFirebaseFirestoreTransactionHandler transactionHandler = @@ -57,7 +57,7 @@ public void onCatalystInstanceDestroy() { } transactionHandlers.clear(); - super.onCatalystInstanceDestroy(); + super.invalidate(); } @ReactMethod diff --git a/packages/perf/android/src/reactnative/java/io/invertase/firebase/perf/ReactNativeFirebasePerfModule.java b/packages/perf/android/src/reactnative/java/io/invertase/firebase/perf/ReactNativeFirebasePerfModule.java index b6468d7838..7deef885f6 100644 --- a/packages/perf/android/src/reactnative/java/io/invertase/firebase/perf/ReactNativeFirebasePerfModule.java +++ b/packages/perf/android/src/reactnative/java/io/invertase/firebase/perf/ReactNativeFirebasePerfModule.java @@ -36,8 +36,8 @@ public class ReactNativeFirebasePerfModule extends ReactNativeFirebaseModule { } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); module.onTearDown(); } diff --git a/packages/remote-config/android/src/reactnative/java/io/invertase/firebase/config/ReactNativeFirebaseConfigModule.java b/packages/remote-config/android/src/reactnative/java/io/invertase/firebase/config/ReactNativeFirebaseConfigModule.java index 9a439dd7af..530ae5b6b1 100644 --- a/packages/remote-config/android/src/reactnative/java/io/invertase/firebase/config/ReactNativeFirebaseConfigModule.java +++ b/packages/remote-config/android/src/reactnative/java/io/invertase/firebase/config/ReactNativeFirebaseConfigModule.java @@ -45,8 +45,8 @@ public class ReactNativeFirebaseConfigModule extends ReactNativeFirebaseModule { } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); Iterator> configRegistrationsIterator = mConfigUpdateRegistrations.entrySet().iterator(); diff --git a/packages/storage/android/src/main/java/io/invertase/firebase/storage/ReactNativeFirebaseStorageModule.java b/packages/storage/android/src/main/java/io/invertase/firebase/storage/ReactNativeFirebaseStorageModule.java index 27f4cddaec..7bd81c2152 100644 --- a/packages/storage/android/src/main/java/io/invertase/firebase/storage/ReactNativeFirebaseStorageModule.java +++ b/packages/storage/android/src/main/java/io/invertase/firebase/storage/ReactNativeFirebaseStorageModule.java @@ -51,9 +51,9 @@ public class ReactNativeFirebaseStorageModule extends ReactNativeFirebaseModule } @Override - public void onCatalystInstanceDestroy() { + public void invalidate() { ReactNativeFirebaseStorageTask.destroyAllTasks(); - super.onCatalystInstanceDestroy(); + super.invalidate(); } /**