paypalpaypal-sandboxpaypal-rest-sdk

paypal_js_sdk_v5_unhandled_exception, Uncaught Error: Component closed


I've set up PayPal subscriptions on a React app I started working on 2 years ago. I started working on it again recently.

I'm getting 2 console errors: paypal_js_sdk_v5_unhandled_exception, and Uncaught Error: Component closed. I'm using @paypal/react-paypal-js and updated to the newest version.

Everything seems to be working fine with one exception: my app doesn't detect when the payment has been made. I have to send a request to my server again to check if the subscription has been registered. However, there's no direct callback that indicates that the subscription has been completed.

I also get warnings about third-party cookies


Solution

  • After some investigation, there are no code changes required to keep functionality after changing versions.

    The console errors are caused by the component being unloaded forcefully but do not affect functionality.

    These can be turned into console warns:

    window.addEventListener('unload', () => {
     try { // Your PayPal button teardown code here } 
     catch (err) { console.warn('PayPal button unload error:', err); } 
    });
    

    Alternatively, to ensure the buttons are unloaded properly and there are no residual event listeners causing errors:

    if (window.paypal && window.paypal.Buttons) { window.paypal.Buttons().close(); }