verygoodsecurity / collect-js-react

MIT License
1 stars 15 forks source link

Field delete on unmount #38

Closed KyloJorgensen closed 1 year ago

KyloJorgensen commented 1 year ago

Description

In React, there is a possibility of calling useEffect twice in the browser or experiencing unmounting and remounting. Due to this behavior, the VGS collect-js-react package does not handle unmounting properly, and neither the form nor the field values are exposed in contexts or callbacks for proper cleanup.

Motivation and Context

I am attempting to integrate VGS into a Next.js app. During this process, two iframes are rendered for each secure field. The first iframe is not being unmounted correctly, which results in it not being part of the form object but still present in the DOM.

Testing

I have tested this code in a local development runtime with Next.js.

Screenshots (if appropriate):

image

Types of Changes

Checklist:

flor-master commented 1 year ago

@KyloJorgensen, thanks for a good job :)