plaid / react-plaid-link

React bindings for Plaid Link
https://plaid.github.io/react-plaid-link
MIT License
267 stars 149 forks source link

Plaid link iframe is not removed #325

Open lorentzimys opened 10 months ago

lorentzimys commented 10 months ago

Hi there! I've noticed that iframe that is created by usePlaidLink hook is not removed on successful scenario, so when I start plaid linking process multiple times - a new iframe is created each time. The only case when iframe is not recreated is when I close plaid link window and onError callback is triggered.

I've noticed that this behaviour happens because usePlaidLink effect fires an exit method on unmout, but destroy callback is not triggered: image

React component to reproduce:


import React, { useEffect } from 'react';
import { PlaidLinkOptions, usePlaidLink } from 'react-plaid-link';

interface PlaidLinkProps {
  options: PlaidLinkOptions;
}

export const PlaidLink: React.FC<PlaidLinkProps> = ({ options }) => {
  const { open, ready } = usePlaidLink(options);

  useEffect(() => {
    if (ready) {
      open();
    }
  }, [ready]);

  useEffect(() => {
    return () => {
      console.log('unmount');
    };
  }, []);

  return (<></>);
};
lorentzimys commented 10 months ago

I think this issue is related to opened PR https://github.com/plaid/react-plaid-link/pull/226