plaid / react-native-plaid-link-sdk

Plaid Link for React Native
MIT License
170 stars 120 forks source link

OpenLink onSuccess or onFailure callbacks never fire #575

Closed henrygrant closed 9 months ago

henrygrant commented 10 months ago

The problem

Neither the onSuccess nor the onFailure callback is ever firing from openLink(). I traced this back to PlaidModule.onActivityResult() never firing at all, meaning this is likely an issue with the implementation of ActivityEventListener in that file (PlaidModule.kt).

It doesn't seem like PlaidModule's onActivityResult() is hooking into LinkActivity properly.

Environment

Plaid Link React Native 10.6.2
ReactNative Version 0.71.12
Occurs on Android yes
Android OS Version 31
Android Devices/Emulators Pixel 7 Physical
Occurs on iOS unknown
iOS Version unknown
iOS Devices/Emulators unknown
Link Session ID link-sandbox-d81d7feb-115b-4a29-a7f0-629697f30533

Steps to Reproduce

One of my teams is using openLink as so, and have asked me why their callback functions never fire when the Plaid experience is exited/completed.

openLink({
      onSuccess: async ({ publicToken }: LinkSuccess) => {
        //do something
      },
      onExit: async ({ error, ...linkExit }: LinkExit) => {
        // do something
      },
      tokenConfig: {
        // config
      },
    })

I spun this up locally saw the same thing. After running the android debugger for a bit, I'm seeing that PlaidModule.kt onActivityResult() is never getting called.

Expected Result

I'd expect onActivityResult to fire when the Plaid experience is closed.

Logs

Not getting anything relevant in the logs

I did run the flow with the profiler to see what was going on. Our RN application runs in a Fragment inside an Activity.

  1. MyReactNativeActivity with MyReactNativeFragment are created
  2. Tap plaid, plaid's LinkActivity starts
  3. Tap "x", plaid's LinkActivity gets destroyed and MyReactNativeActivity resumes.

Code To Reproduce Issue

It's really just what you see above, but it may be worth noting that I am working in a brownfielded React Native app, and Plaid is also used on the native side. When I first got this bug I assumed the version of Plaid the native app was using was mismatched with the version of react-native-plaid-link-sdk we're using, and that was true. I went ahead and made sure they were synced, but to no avail.

My Android project: image

It may also be worth noting that the android project is the parent project in this implementation, and the react native app is a package. The dir structure looks like this:

myandroidapp/
  node_modules/
     myreactnativeapp/
     react-native-plaid-link-sdk

myreactnativeapp specifies react-native-plaid-link-sdk as a peerDependency.

Other notes

dtroupe-plaid commented 10 months ago

@henrygrant thanks for the detailed report. I just tested our example application and both the success and the exit callback are called as expected on Android. Given the unique nature of your application I think the problem is rather specific. I am happy to help where I can, but I am currently not sure what could be causing this 🤔

henrygrant commented 10 months ago

Update to this for anyone who may have the same issue in the future:

The root of it is that the activity that our React Native fragment is running in, i.e. the activity that PlaidLink is being launched from, doesn't subclass ReactActivity. Looking at RN's "Integration with an Android Fragment" doc, it shouldn't have to. We have our MainApplication.kt configured for ReactNative, and can use a React Native fragment in any of our native activities without issue. This is the first I've seen an issue with this setup.

Their ReactFragment overrides onActivityResult, but it doesn't seem like react-native-plaid-link-sdk plays well with this. I'm going to investigate a bit further, as I can't tell if this is an issue on the RN side or the react-native-plaid-link-sdk side.

For the time being, I've changed the activity that loads our ReactNative fragment to subclass ReactActivity, but I don't really want to use this as a long term solution.

dtroupe-plaid commented 10 months ago

@henrygrant any update on this issue? I'd like to close this if possible 🙏

henrygrant commented 9 months ago

I haven't had the chance to dig into this as the workaround is working for now. You can close this, but you may want to update the documentation with something that says Plaid Link needs to be run in an activity that subclasses ReactActivity, else your callbacks won't fire. RN doesn't require you to sub ReactActivity if you're using a ReactFragment, so this is a fairly easy trap to fall into if you're working in a brownfield/hybrid project, but as this is pretty nonconventional I'll leave it up to you to determine if it's important enough to mention 😆

Thanks!