Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: stripe/react-stripe-js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.3.0
Choose a base ref
...
head repository: stripe/react-stripe-js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.3.1
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Sep 12, 2023

  1. v2.3.0

    pololi-stripe committed Sep 12, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    nielsbauman Niels Bauman
    Copy the full SHA
    1441b7a View commit details

Commits on Sep 26, 2023

  1. Copy the full SHA
    f44a072 View commit details
Showing with 37 additions and 3 deletions.
  1. +1 −1 package.json
  2. +25 −0 src/components/EmbeddedCheckout.client.test.tsx
  3. +11 −2 src/components/EmbeddedCheckout.tsx
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stripe/react-stripe-js",
"version": "2.2.0",
"version": "2.3.0",
"description": "React components for Stripe.js and Stripe Elements",
"main": "dist/react-stripe.js",
"module": "dist/react-stripe.esm.js",
25 changes: 25 additions & 0 deletions src/components/EmbeddedCheckout.client.test.tsx
Original file line number Diff line number Diff line change
@@ -129,4 +129,29 @@ describe('EmbeddedCheckout on the client', () => {
);
expect(mockEmbeddedCheckout.unmount).toBeCalled();
});

it('does not throw when the Embedded Checkout instance is already destroyed when unmounting', async () => {
const {container, rerender} = render(
<EmbeddedCheckoutProvider stripe={mockStripe} options={fakeOptions}>
<EmbeddedCheckout />
</EmbeddedCheckoutProvider>
);

await act(() => mockEmbeddedCheckoutPromise);

expect(mockEmbeddedCheckout.mount).toBeCalledWith(container.firstChild);

mockEmbeddedCheckout.unmount.mockImplementation(() => {
throw new Error('instance has been destroyed');
});

expect(() => {
rerender(
<EmbeddedCheckoutProvider
stripe={mockStripe}
options={fakeOptions}
></EmbeddedCheckoutProvider>
);
}).not.toThrow();
});
});
13 changes: 11 additions & 2 deletions src/components/EmbeddedCheckout.tsx
Original file line number Diff line number Diff line change
@@ -32,8 +32,17 @@ const EmbeddedCheckoutClientElement = ({
// Clean up on unmount
return () => {
if (isMounted.current && embeddedCheckout) {
embeddedCheckout.unmount();
isMounted.current = false;
try {
embeddedCheckout.unmount();
isMounted.current = false;
} catch (e) {
// Do nothing.
// Parent effects are destroyed before child effects, so
// in cases where both the EmbeddedCheckoutProvider and
// the EmbeddedCheckout component are removed at the same
// time, the embeddedCheckout instance will be destroyed,
// which causes an error when calling unmount.
}
}
};
}, [embeddedCheckout]);