Skip to content

Commit

Permalink
fix(android, app): fix hot-reload on react-native <= 0.73
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mikehardy committed Nov 25, 2024
1 parent 0103e12 commit 81e5fc2
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();
}

Expand Down

0 comments on commit 81e5fc2

Please sign in to comment.