stripe-react-native: CardField crashes the app when it's focused and unmounted while using the new architecture (Fabric)

Using the new NEW_ARCH (Fabric), the app crashes with the error: Swift runtime failure: force unwrapped a nil value + 0 [inlined] closure #1 in CardFieldManager.blur(_:) + 484 when the component containing CardField is unmounted while the CardField is focused.

To Reproduce Steps to reproduce the behavior:

  1. Create a screen with a CardField component and compile the iOS app with RCT_NEW_ARCH_ENABLED=1.
  2. Focus on the CardField.
  3. Unmount the screen (e.g., using navigation.goBack, bottomsheet.close, etc.).
  4. See the crash.

Expected behavior The app should dismiss keyboard and unmount the screen without crashing, even when the CardField is focused.

Screenshots N/A

Desktop (please complete the following information):

  • OS: iOS
  • Browser: N/A
  • Version: N/A

Smartphone (please complete the following information):

  • Device: iPhone15
  • OS: iOS 18.5
  • Browser: N/A
  • Version: N/A

Additional context This issue occurs only when using the new Fabric architecture with RCT_NEW_ARCH_ENABLED=1. I have not tested on Android yet, the issue may also be present there.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 15
  • Comments: 39

Commits related to this issue

Most upvoted comments

Hi all, thanks for reporting. We’re working on updating to the new architecture and will post an update when completed.

Hi all, thank you for sharing all of the feedback here. I agree with you; it’s taken us way too long to support the new architecture. I’m sorry for that. Fortunately, I have good news: we have begun our work to start migrating to the new architecture over the past couple of weeks and hope to complete it over the next 4-6 weeks. If anything changes, you can expect to see an update from me here, but I’m optimistic we should be able to complete it by then.

I apologize again for the delay and look forward to getting this shipped for you all soon. Please keep the feedback coming as well; we will do a better job at communicating with you all in GitHub issues going forward.

Stripe is the only package that is keeping us from migrating to the new architecture currrently.

Hoping to land this this week or next week

For those needing a temporary work-around for now, on iOS, open Xcode and go to

Pods/DevelopmentPods/stripe-react-native/CardFieldManager.swift

~line 19 will be the blur function, replace that with this:

@objc func blur(_ reactTag: NSNumber) { self.bridge!.uiManager.addUIBlock { (_: RCTUIManager?, viewRegistry: [NSNumber: UIView]?) in guard let viewRegistry = viewRegistry, let view = viewRegistry[reactTag] as? CardFieldView else { NSLog("[StripeSdk] Invalid view or reactTag when calling blur. \(reactTag)") return } view.blur() } }

This simply adds a guard that prevents the blur function from breaking because of some wrong view id being sent to the function. This allows me to just blur the field.

Please note that this change is temporary, still throws a warning, but it stops the app from breaking at least for now.

P.S. This may be slightly related in terms of the new architecture affecting this, but I also found that on Android, while the app did not break, onFocus and onBlur events simply did not fire, and I ended up writing keyboardListener events to call those functions, which felt odd to have to do for a field that at least knew to open the keyboard

Any update on this?

After upgrading to 0.45.0 I get build errors on both iOS and Android using Expo SDK 52

Android:

Execution failed for task ':stripe_stripe-react-native:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction

iOS:

❌  Undefined symbols for architecture x86_64
┌─ Symbol: _EmbeddedPaymentElementViewCls
└─ Referenced from: _RCTThirdPartyFabricComponentsProvider in libReact-RCTFabric.a[41](RCTThirdPartyFabricComponentsProvider.o)

This solution worked for me

To fix the issue by patching the Stripe React Native package in your node_modules directory, follow these steps:

First, install the patch-package:

npm install --save-dev patch-package

Now, you need to modify the problematic file in your node_modules directory. Navigate to:

cd node_modules/@stripe/stripe-react-native/ios/CardFieldManager.swift

Open this file in a text editor and find the blur function. It should look like:

@objc func blur(_ reactTag: NSNumber) { self.bridge!.uiManager.addUIBlock { (_: RCTUIManager?, viewRegistry: [NSNumber: UIView]?) in let view: CardFieldView = (viewRegistry![reactTag] as? CardFieldView)! view.blur() } }

Replace it with the safer version:

@objc func blur(_ reactTag: NSNumber) { self.bridge!.uiManager.addUIBlock { (_: RCTUIManager?, viewRegistry: [NSNumber: UIView]?) in guard let viewRegistry = viewRegistry, let view = viewRegistry[reactTag] as? CardFieldView else { NSLog(“[StripeSdk] Invalid view or reactTag when calling blur. (reactTag)”) return } view.blur() } }

Save the file. Now create the patch:

npx patch-package @stripe/stripe-react-native

This will create a patch file in the patches directory of your project. The file will be named something like @stripe+stripe-react-native+0.x.x.patch. Add a postinstall script to your package.json to apply the patch automatically when dependencies are installed:

“scripts”: { “postinstall”: “patch-package” }

Rebuild your iOS app:

cd ios pod install cd … npx react-native run-ios This approach has several advantages:

Your changes won’t be lost when you reinstall dependencies The patch can be shared with your team It’s a cleaner approach than modifying files directly in the Pods directory

The patch-package tool will create a diff of your changes and apply them whenever the dependencies are installed, ensuring the fix is consistently applied.

Hi all, we’re excited to share that support for the new architecture was released yesterday as v0.45.0 (fixed in https://github.com/stripe/stripe-react-native/pull/1893)! 🎉 Thank you again for your patience.

We believe this is now fixed. If anyone is still experiencing this after upgrading to v0.45.0, could you please let us know? Otherwise we will close this issue as resolved

Any update on this?

Try to create hidden input and focus on it before hide keyboard or close page.

any update on this react native 0.76.0 was just released today with the New Arch turned on by default and this library does not work with it are you guys going to update it?

Android does not even show the CardField with Fabric enabled. This is a huge issue since react native 76 which is coming out next month will have the new Architecture enabled by default which will make this library unusable at that point. @charliecruzan-stripe any update on supporting Fabric? Screenshot 2024-09-24 at 12 23 37 PM

After upgrading to 0.45.0 I get build errors on both iOS and Android using Expo SDK 52

Android:

Execution failed for task ':stripe_stripe-react-native:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction

iOS:

❌  Undefined symbols for architecture x86_64
┌─ Symbol: _EmbeddedPaymentElementViewCls
└─ Referenced from: _RCTThirdPartyFabricComponentsProvider in libReact-RCTFabric.a[41](RCTThirdPartyFabricComponentsProvider.o)

I get this error as well

After upgrading to 0.45.0 I get build errors on both iOS and Android using Expo SDK 52

Android:

Execution failed for task ':stripe_stripe-react-native:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction

iOS:

❌  Undefined symbols for architecture x86_64
┌─ Symbol: _EmbeddedPaymentElementViewCls
└─ Referenced from: _RCTThirdPartyFabricComponentsProvider in libReact-RCTFabric.a[41](RCTThirdPartyFabricComponentsProvider.o)

I get the same, but for arm64

I got these build errors in iOS, after upgrading to version 0.45.0. I’m using Expo sdk 52:

/Users/expo/workingdir/build/ios/Pods/StripePayments/StripePayments/Source/Helpers/BundleLocator.swift:10:41: error: cannot find ‘BundleLocatorProtocol’ in scope open class StripePaymentsBundleLocator: BundleLocatorProtocol

/Users/expo/workingdir/build/ios/Pods/StripePayments/StripePayments/Source/Helpers/BundleLocator.swift:10:8: error: cannot find ‘StripePaymentsBundleLocator’ in scope open class StripePaymentsBundleLocator: BundleLocatorProtocol

@gleung93 @sabuhiteymurov @ivan-moego

Expo sets built in config plugins with its sdk versions and this library. expo SDK 52 is tied to 0.38.6 with it’s config plugins. The newly released expo SDK 53 is tied to 0.45.0 of this library. see https://docs.expo.dev/versions/latest/sdk/stripe/

I upgraded to v0.45.0. No issues were found on iOS, but the Android compilation failed with an error like this: “node_modules/@stripe/stripe-react-native/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt:1043:29 Class ‘kotlin.Unit’ was compiled with an incompatible version of Kotlin. The actual metadata version is 2.1.0, but the compiler version 1.9.0 can read versions up to 2.0.0.” Currently, I’m using Expo 52, and it seems that it doesn’t support upgrading to Kotlin 2.0.0 yet. What other solutions are there?

hi trying to implement add card functionality to react native app, the thing here its that only with navigation going back or closing the component where the CardField its inside whether is focused or has been focused once it crashes in auto the app. Tried using inside react navigation lib the method navigate.popToTop it still not working.

Is there a patch we can apply temporarily until this issue is resolved? @tjclawson-stripe @ianjabour-stripe @charliecruzan-stripe