Issue
In the Android Firestore native module, UniversalFirebaseFirestoreCommon.getFirestoreForApp() reads from instanceCache using firestoreKey = appName + ":" + databaseId, but writes back using only appName.
That means the cache lookup can never hit for the default database or any custom database:
String firestoreKey = createFirestoreKey(appName, databaseId);
WeakReference<FirebaseFirestore> cachedInstance = instanceCache.get(firestoreKey);
...
instanceCache.put(appName, new WeakReference<FirebaseFirestore>(instance));
The write should use firestoreKey, not appName.
Why this matters
On Android, this can cause setFirestoreSettings(...) to be called repeatedly on an already-started Firestore instance, which crashes with:
java.lang.IllegalStateException: FirebaseFirestore has already been started and its settings can no longer be changed. You can only modify settings before calling any methods on a FirebaseFirestore object.
I hit this in production via Crashlytics while using @react-native-firebase/firestore 22.4.0, but I also checked the currently published npm release 24.0.0 and the current main branch, and both still contain the same cache write bug.
Current affected code
As of npm 24.0.0 and main:
packages/firestore/android/src/main/java/io/invertase/firebase/firestore/UniversalFirebaseFirestoreCommon.java
instanceCache.put(appName, new WeakReference<FirebaseFirestore>(instance));
Expected fix
instanceCache.put(firestoreKey, new WeakReference<FirebaseFirestore>(instance));
Local confirmation
Applying the one-line change above removed the Firestore initialization crash in my app.
Environment
@react-native-firebase/firestore: observed on 22.4.0
- latest npm at time of writing:
24.0.0
- platform: Android
- app type: React Native / Expo dev client app using
firestore.settings(...) during initialization
Issue
In the Android Firestore native module,
UniversalFirebaseFirestoreCommon.getFirestoreForApp()reads frominstanceCacheusingfirestoreKey = appName + ":" + databaseId, but writes back using onlyappName.That means the cache lookup can never hit for the default database or any custom database:
The write should use
firestoreKey, notappName.Why this matters
On Android, this can cause
setFirestoreSettings(...)to be called repeatedly on an already-started Firestore instance, which crashes with:I hit this in production via Crashlytics while using
@react-native-firebase/firestore22.4.0, but I also checked the currently published npm release24.0.0and the currentmainbranch, and both still contain the same cache write bug.Current affected code
As of npm
24.0.0andmain:packages/firestore/android/src/main/java/io/invertase/firebase/firestore/UniversalFirebaseFirestoreCommon.javaExpected fix
Local confirmation
Applying the one-line change above removed the Firestore initialization crash in my app.
Environment
@react-native-firebase/firestore: observed on22.4.024.0.0firestore.settings(...)during initialization