Skip to content

Commit

Permalink
protect against nullish render
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Feb 14, 2024
1 parent 238d580 commit cc7f94c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hooks/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 21 additions & 0 deletions hooks/test/browser/useId.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,25 @@ describe('useId', () => {
'<div><div>My id is P0-0</div><div>My id is P0-1</div></div>'
);
});

it('should not crash for rendering null after a non-null render', () => {
const Id = () => {
const id = useId();
return <div>My id is {id}</div>;
};

const App = props => {
return (
<div>
<Id />
{props.secondId ? <Id /> : null}
</div>
);
};

render(createElement(App, { secondId: false }), scratch);
expect(scratch.innerHTML).to.equal('<div><div>My id is P0-0</div></div>');
render(null, scratch);
expect(scratch.innerHTML).to.equal('');
});
});

0 comments on commit cc7f94c

Please sign in to comment.