Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/portal-popper.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ describe('<PortalPopper />', () => {
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')
})
Expand Down
6 changes: 5 additions & 1 deletion src/portal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
10 changes: 10 additions & 0 deletions src/portal.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,14 @@ describe('<Portal />', () => {
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(<Portal />)

document.getElementById('portal-0').remove()

component.unmount() // should not error
expect(document.getElementById('portal-0')).not.to.exist
})
})