Repository navigation
fix(crashlytics): pass setCrashlyticsCollectionEnabled to the native SDK immediately - #9529
harpreetkbadhan wants to merge 3 commits into
Conversation
Mastersam07
left a comment
There was a problem hiding this comment.
Thanks for picking this up so quickly. The native change is what we were after: passing the init provider's computed value keeps the debug-build rule on both platforms. A few changes before this can go in:
1. Don't promise current-run behaviour. The Firebase iOS SDK documents that setCrashlyticsCollectionEnabled: does not apply until the next run of the app (FIRCrashlytics.h), and the Android SDK says the same for false (FirebaseCrashlytics javadoc). The current SDKs may act on it sooner, but we can't promise that on Firebase's behalf. Please reword:
- The new docs bullet, for example:
The value is also passed to the native Crashlytics SDK straight away. Firebase guarantees the change from the next app launch, so don't rely on it for crashes later in the same run.
- The PR title, which becomes the changelog entry, for example:
fix(crashlytics): pass setCrashlyticsCollectionEnabled to the native SDK immediately - The Release Summary, to match.
2. JSDoc. Please add the same note to setCrashlyticsCollectionEnabled in packages/crashlytics/lib/types/crashlytics.ts. It currently says nothing about when the change takes effect.
3. A unit test is possible on Android. The JVM tests in packages/crashlytics/android/src/test/java/io/invertase/firebase/crashlytics/ already stub the SDK with mockStatic(FirebaseCrashlytics.class); see ReactNativeFirebaseCrashlyticsNativeHelperTest.java for the pattern. Please add a test that the SDK receives the value from ReactNativeFirebaseCrashlyticsInitProvider.isCrashlyticsCollectionEnabled() rather than the raw enabled argument. If the TurboModule is awkward to construct in a test, a small package-private static helper for the new call is fine. Please don't add it to ReactNativeFirebaseCrashlyticsNativeHelper, which is public API for app native code.
|
Thanks @Mastersam07. Done in the latest commit:
|
Description
setCrashlyticsCollectionEnabledonly wrote the module's preference. The SDK reads that preference once, when the init provider starts, so on iOS a consent withdrawal reached report handling only at the second launch after it.The method now also calls the SDK's own switch at once,
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(...)on Android and[[FIRCrashlytics crashlytics] setCrashlyticsCollectionEnabled:]on iOS, which both SDKs persist themselves. The SDK's saved value is then already correct at the next start, so the extra launch on iOS goes away.Firebase guarantees this switch from the next app launch (
FIRCrashlytics.h, and theFirebaseCrashlyticsjavadoc forfalse), so the docs and the JSDoc say that, and do not promise anything for crashes later in the same run.On Android the two steps live in a package-private static helper,
NativeRNFBTurboCrashlytics.saveAndApplyCollectionEnabled, so a JVM test can call it. It passes the module's computed value (isCrashlyticsCollectionEnabled()), not the rawenabledargument, after writing the preference. That keeps the existing rule that a debug build stays off unlesscrashlytics_debug_enabledis set infirebase.json, which the docs already state.On iOS the call goes through a new
RNFBCrashlyticsHelpermethod, sinceRNFBCrashlyticsModule.mmroutes every Crashlytics SDK call through that ObjC helper. The usage docs get one bullet under Opt-out, and thesetCrashlyticsCollectionEnabledJSDoc says when the value applies.Related issues
Fixes #9528
Release Summary
setCrashlyticsCollectionEnablednow also passes the value to the native Crashlytics SDK immediately. Firebase guarantees the change from the next app launch, so on iOS a withdrawal no longer waits for the launch after that.Checklist
AndroidiOSOther(macOS, web)e2etests added or updated inpackages/\*\*/e2ejesttests added or updated inpackages/\*\*/__tests__packages/crashlytics/android/src/testTest Plan
./gradlew :react-native-firebase_crashlytics:compileDebugJavaWithJavacintests/androidbuilds.pod installandxcodebuild -workspace testing.xcworkspace -scheme testing -configuration Debugfor a simulator build, withRNFBCrashlyticsHelper.oexporting the newsetCrashlyticsCollectionEnabled:method.yarn lint:ios:checkandgoogle-java-formatpass on the changed files;prettier --checkpasses on the docs page and the types file.jest packages/crashlytics: 28 passed.NativeRNFBTurboCrashlyticsCollectionEnabledTest(Robolectric,mockStaticlikeReactNativeFirebaseCrashlyticsNativeHelperTest): the SDK gets the init provider's value, not the raw argument, sotruein a debug build withoutcrashlytics_debug_enabledpassesfalse; plus the enabled and withdrawal cases. With the raw argument passed instead, the debug-build case fails../gradlew :react-native-firebase_crashlytics:testDebugUnitTest: 28 passed across the 6 crashlytics JVM test classes.Nothing changes on the JS side, so there is no new Jest case; the existing e2e tests for
setCrashlyticsCollectionEnabledandisCrashlyticsCollectionEnabledstill cover the JS flag. The SDK's own collection state is not readable from JS, so e2e cannot observe the native call. The issue reporter verified the same SDK call by hand on both platforms (a crash after withdrawal stays on the device and is deleted).I used Claude Code to read the code and write the change. I reviewed the diff and ran the builds above myself.