From cc7f94c43c63dc0cc8daabc62035daa95afd4e60 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Wed, 14 Feb 2024 12:33:54 +0100 Subject: [PATCH] protect against nullish render --- hooks/src/index.js | 2 +- hooks/test/browser/useId.test.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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(''); + }); });