Skip to content

Commit

Permalink
Fix bug where backdrop calls method on null if it is already removed …
Browse files Browse the repository at this point in the history
…from the body (#34014)

Co-authored-by: Rohit Sharma <rohit2sharma95@gmail.com>
  • Loading branch information
weaverryan and rohit2sharma95 authored May 21, 2021
1 parent d64466a commit a2b5901
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion js/src/util/backdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ class Backdrop {

EventHandler.off(this._element, EVENT_MOUSEDOWN)

this._getElement().parentNode.removeChild(this._element)
const { parentNode } = this._getElement()
if (parentNode) {
parentNode.removeChild(this._element)
}

this._isAppended = false
}

Expand Down
19 changes: 19 additions & 0 deletions js/tests/unit/util/backdrop.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ describe('Backdrop', () => {
})
})

it('should not error if the backdrop no longer has a parent', done => {
const instance = new Backdrop({
isVisible: true,
isAnimated: true
})
const getElements = () => document.querySelectorAll(CLASS_BACKDROP)

instance.show(() => {
instance.hide(() => {
expect(getElements().length).toEqual(0)

// replace the fixture, which was just wiped out
fixtureEl = getFixture()
done()
})
document.body.innerHTML = 'changed'
})
})

describe('click callback', () => {
it('it should execute callback on click', done => {
const spy = jasmine.createSpy('spy')
Expand Down

0 comments on commit a2b5901

Please sign in to comment.