Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch back to a ref to track element creating, updating, and destroying #376

Merged
merged 4 commits into from
Jan 18, 2023

Conversation

awalker-stripe
Copy link
Contributor

Summary & motivation

Addresses #375: if un-mounting occurs on the same render as creating the element (ex. in strictmode), elements.create could get called multiple times without element.destroy being called. This was because setting our state with setElement doesn't apply to the next render, so the element would still be null and we wouldn't call to destroy.

This PR reverts part of #372 by switching back to a ref to track creating, updating, and destroying an element. However, it keeps the element state used to attach events in that PR.

Testing & documentation

  • Added unit test that fails in v1.16.3 for strict mode to make sure .create() and destroy() get called correctly
  • Tested against reproduction of the issue, where multiple re-renders using React 17 (not in strict mode) threw an error.
  • Storybooks for Payment and Card Element still both work

Co-authored-by: Brian Mathews <93609068+bmathews-stripe@users.noreply.github.com>
Co-authored-by: Brian Mathews <93609068+bmathews-stripe@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants