From 7e1c351d5805ba9bffb31aab8d051a2b6833b78d Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Sun, 24 Nov 2024 21:30:50 -0500 Subject: [PATCH] fix(android, app): fix hot-reload on react-native <= 0.73 super.invalidate() is an empty function in rn >= 0.74, so no need to call it going forward But on rn <= 0.73 it may not exist, and if it does it calls onCatalystInstanceDestroy which makes for a StackOverFlowException as we go recursive --- .../common/ReactNativeFirebaseModule.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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 57850abd23..cbb7539f14 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,12 +92,13 @@ public final ExecutorService getTransactionalExecutor(String identifier) { return executorService.getTransactionalExecutor(identifier); } - - // 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` + // On react-native 0.73 this is called, but simply calls `invalidate()` + // https://github.com/facebook/react-native/blob/0.73-stable/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/BaseJavaModule.java#L65-L72 + // This is no longer called ever for react-native >= 0.74 and is only here for + // compatibility with older versions. We delegate to the new `invalidate` // method, which all modules should implement now // Remove this method when minimum supported react-native is 0.74 - /** @noinspection removal*/ + // @noinspection removal @SuppressWarnings({"deprecation", "removal"}) @Deprecated public void onCatalystInstanceDestroy() { @@ -107,11 +108,14 @@ public void onCatalystInstanceDestroy() { } // 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 + // that until our minimum supported react-native version is 0.74 + // + // No need to call super.invalidate and in fact it is dangerous to do so: + // - did not exist before react-native 0.73 + // - on 0.74 it calls onCatalystInstanceDestroy which would infinite loop here + // - on 0.75+ it is empty - meant as sub-class hook only @CallSuper public void invalidate() { - super.invalidate(); executorService.shutdown(); }