diff --git a/src/Frame.jsx b/src/Frame.jsx index 8470f30..c936411 100644 --- a/src/Frame.jsx +++ b/src/Frame.jsx @@ -128,6 +128,10 @@ export class Frame extends Component { const mountTarget = this.getMountTarget(); + if (!mountTarget) { + return null; + } + return [ ReactDOM.createPortal(this.props.head, this.getDoc().head), ReactDOM.createPortal(contents, mountTarget) diff --git a/test/Frame.spec.jsx b/test/Frame.spec.jsx index c90242b..63db5ed 100644 --- a/test/Frame.spec.jsx +++ b/test/Frame.spec.jsx @@ -341,6 +341,23 @@ describe('The Frame Component', () => { ); }); + it("should render null when `this.getMountTarget()` can't resolve", done => { + const didMount = sinon.spy(); + const getMountTarget = sinon + .stub(Frame.prototype, 'getMountTarget') + .returns(null); + + div = document.body.appendChild(document.createElement('div')); + + ReactDOM.render(, div); + + setTimeout(() => { + expect(didMount.callCount).to.equal(0); + done(); + getMountTarget.restore(); + }, 100); + }); + it('should not error when parent components are reused', done => { div = document.body.appendChild(document.createElement('div'));