Skip to content

Commit d248271

Browse files
author
Kent C. Dodds
committed
fix(cleanup): don't error out if the container is not in the body
1 parent 5257500 commit d248271

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: src/__tests__/bugs.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// this is where we'll put bug reproductions/regressions
2+
// to make sure we never see them again
3+
4+
import React from 'react'
5+
import {render, cleanup} from '../'
6+
7+
test('cleanup does not error when an element is not a child', () => {
8+
render(<div />, {container: document.createElement('div')})
9+
cleanup()
10+
})

Diff for: src/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ function cleanup() {
3737
// maybe one day we'll expose this (perhaps even as a utility returned by render).
3838
// but let's wait until someone asks for it.
3939
function cleanupAtContainer(container) {
40-
document.body.removeChild(container)
40+
if (container.parentNode === document.body) {
41+
document.body.removeChild(container)
42+
}
4143
ReactDOM.unmountComponentAtNode(container)
4244
mountedContainers.delete(container)
4345
}

0 commit comments

Comments
 (0)