From cd02a99204042c2f84c3522d522383365d48cd6b Mon Sep 17 00:00:00 2001 From: Robert Williams Date: Thu, 20 Feb 2020 12:00:37 -0600 Subject: [PATCH 1/3] Fixed error where crash will happen if fired twice in a row. --- src/index.js | 4 +++- test/integration.test.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index f296855..9787f59 100644 --- a/src/index.js +++ b/src/index.js @@ -44,7 +44,9 @@ export default function withReactContent (ParentSwal) { const superOnDestroy = params.onDestroy params.onDestroy = (element) => { superOnDestroy(element) - ReactDOM.unmountComponentAtNode(domElement) + if (domElement) { + ReactDOM.unmountComponentAtNode(domElement) + } } } }) diff --git a/test/integration.test.js b/test/integration.test.js index b17ebbc..7a25aab 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -53,6 +53,25 @@ describe('integration', () => { }, }) }) + it('fire twice without crashing', async () => { + await cleanSwalState() + const MySwal = withReactContent(SwalWithoutAnimation) + MySwal.fire({ + title: React element, + footer: 'plain text' + }) + await MySwal.fire({ + title: React element, + footer: 'plain text', + onOpen: () => { + expect(MySwal.getTitle().innerHTML).toEqual( + 'React element', + ) + expect(MySwal.getFooter().innerHTML).toEqual('plain text') + MySwal.clickConfirm() + }, + }) + }) it('returns a class with the same instance & static properties as Swal', async () => { const MySwal = withReactContent(Swal) Object.keys(Swal).forEach(key => { From 745f506b0a5840cd200fd1a4517e92f97fcdb7bf Mon Sep 17 00:00:00 2001 From: Robert Williams Date: Thu, 20 Feb 2020 13:48:54 -0600 Subject: [PATCH 2/3] undid change to see if test fails in CI. --- src/index.js | 4 +--- test/integration.test.js | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 9787f59..f296855 100644 --- a/src/index.js +++ b/src/index.js @@ -44,9 +44,7 @@ export default function withReactContent (ParentSwal) { const superOnDestroy = params.onDestroy params.onDestroy = (element) => { superOnDestroy(element) - if (domElement) { - ReactDOM.unmountComponentAtNode(domElement) - } + ReactDOM.unmountComponentAtNode(domElement) } } }) diff --git a/test/integration.test.js b/test/integration.test.js index 7a25aab..2f63fc0 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -53,7 +53,7 @@ describe('integration', () => { }, }) }) - it('fire twice without crashing', async () => { + it('can fire twice without crashing', async () => { await cleanSwalState() const MySwal = withReactContent(SwalWithoutAnimation) MySwal.fire({ From 34036b4e63c1e44668a8f01fee2b25ce97a06430 Mon Sep 17 00:00:00 2001 From: Robert Williams Date: Thu, 20 Feb 2020 13:50:48 -0600 Subject: [PATCH 3/3] re-fixed error: unmountComponentAtNode(...): Target container is not a DOM element. --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index f296855..9787f59 100644 --- a/src/index.js +++ b/src/index.js @@ -44,7 +44,9 @@ export default function withReactContent (ParentSwal) { const superOnDestroy = params.onDestroy params.onDestroy = (element) => { superOnDestroy(element) - ReactDOM.unmountComponentAtNode(domElement) + if (domElement) { + ReactDOM.unmountComponentAtNode(domElement) + } } } })