diff --git a/hooks/src/index.js b/hooks/src/index.js index 92eb1e113b..f2a0c12922 100644 --- a/hooks/src/index.js +++ b/hooks/src/index.js @@ -37,7 +37,7 @@ options._diff = vnode => { }; options._root = (vnode, parentDom) => { - if (parentDom._children && parentDom._children._mask) { + if (vnode && parentDom._children && parentDom._children._mask) { vnode._mask = parentDom._children._mask; } diff --git a/hooks/test/browser/useId.test.js b/hooks/test/browser/useId.test.js index fe2546fd1a..390f955df7 100644 --- a/hooks/test/browser/useId.test.js +++ b/hooks/test/browser/useId.test.js @@ -456,4 +456,25 @@ describe('useId', () => { '
My id is P0-0
My id is P0-1
' ); }); + + it('should not crash for rendering null after a non-null render', () => { + const Id = () => { + const id = useId(); + return
My id is {id}
; + }; + + const App = props => { + return ( +
+ + {props.secondId ? : null} +
+ ); + }; + + render(createElement(App, { secondId: false }), scratch); + expect(scratch.innerHTML).to.equal('
My id is P0-0
'); + render(null, scratch); + expect(scratch.innerHTML).to.equal(''); + }); });