diff --git a/src/portal-popper.spec.jsx b/src/portal-popper.spec.jsx index 6b700b1..592f8e8 100644 --- a/src/portal-popper.spec.jsx +++ b/src/portal-popper.spec.jsx @@ -84,6 +84,7 @@ describe('', () => { expect(Popper.firstCall.args[2].modifiers.preventOverflow).to.eql({ boundariesElement: 'boundary', }) + expect(Popper.firstCall.args[2].onCreate).to.be.a('function') expect(Popper.firstCall.args[2].onUpdate).to.be.a('function') }) diff --git a/src/portal.jsx b/src/portal.jsx index 3931494..e3b2d7e 100644 --- a/src/portal.jsx +++ b/src/portal.jsx @@ -25,7 +25,11 @@ class Portal extends Component { componentWillUnmount () { const appendTo = this.props.appendTo - appendTo.removeChild(this._element) + // it's possible the element was removed from the dom or the dom has been + // blown away, which will cause `removeChild` to throw an exception + try { + appendTo.removeChild(this._element) + } catch (err) {} // eslint-disable-line no-empty } render () { diff --git a/src/portal.spec.jsx b/src/portal.spec.jsx index 542e54c..fa935ae 100644 --- a/src/portal.spec.jsx +++ b/src/portal.spec.jsx @@ -28,4 +28,14 @@ describe('', () => { component.unmount() expect(document.getElementById('portal-0')).not.to.exist }) + + it('gracefully handles the portal div no longer existing on unmount', () => { + Portal.idNum = 0 + const component = mount() + + document.getElementById('portal-0').remove() + + component.unmount() // should not error + expect(document.getElementById('portal-0')).not.to.exist + }) })