Skip to content

Commit cc7f94c

Browse files
committed
protect against nullish render
1 parent 238d580 commit cc7f94c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

hooks/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ options._diff = vnode => {
3737
};
3838

3939
options._root = (vnode, parentDom) => {
40-
if (parentDom._children && parentDom._children._mask) {
40+
if (vnode && parentDom._children && parentDom._children._mask) {
4141
vnode._mask = parentDom._children._mask;
4242
}
4343

hooks/test/browser/useId.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,4 +456,25 @@ describe('useId', () => {
456456
'<div><div>My id is P0-0</div><div>My id is P0-1</div></div>'
457457
);
458458
});
459+
460+
it('should not crash for rendering null after a non-null render', () => {
461+
const Id = () => {
462+
const id = useId();
463+
return <div>My id is {id}</div>;
464+
};
465+
466+
const App = props => {
467+
return (
468+
<div>
469+
<Id />
470+
{props.secondId ? <Id /> : null}
471+
</div>
472+
);
473+
};
474+
475+
render(createElement(App, { secondId: false }), scratch);
476+
expect(scratch.innerHTML).to.equal('<div><div>My id is P0-0</div></div>');
477+
render(null, scratch);
478+
expect(scratch.innerHTML).to.equal('');
479+
});
459480
});

0 commit comments

Comments
 (0)