stripe-archive / react-stripe-elements

Moved to stripe/react-stripe-js.
https://github.com/stripe/react-stripe-js
MIT License
3.03k stars 319 forks source link

register all elements #519

Closed dweedon-stripe closed 4 years ago

dweedon-stripe commented 4 years ago

Summary & motivation

Fix a bug where elements is not injected when using async Stripe and only mounting a CardCvcElement or CardExpiry Element.

I fixed this by always registering all Elements. Previously, we skipped this for Elements that are not auto-detected. This change ensures that state is always updated after Elements is instantiated which triggers a re-render on components wrapped with inject.

Registering these Elements should not have any unintended consequences. When we look up Elements for auto-detection in methods like createToken we always filter by an implied*Type. The newly registered Elements will not have any implied*Type and will always be filtered out.

This better fix would involve moving _elements to state. This is a much larger change that seemed to have some potential downstream implications that I wanted to avoid.

Testing & documentation

I updated the unit tests and tested this manually using the async demo.