Skip to content

Commit

Permalink
Validate portal container early
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Sep 11, 2017
1 parent f74981b commit f265e63
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/renderers/dom/fiber/ReactDOMFiberEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@ var ReactDOMFiber = {
container: DOMContainer,
key: ?string = null,
) {
invariant(
isValidContainer(container),
'Target container is not a DOM element.',
);
// TODO: pass ReactDOM portal implementation as third argument
return ReactPortal.createPortal(children, container, null, key);
},
Expand Down
12 changes: 12 additions & 0 deletions src/renderers/dom/fiber/__tests__/ReactDOMFiber-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,18 @@ describe('ReactDOMFiber', () => {
]);
});

fit('should throw on bad createPortal argument', () => {
expect(() => {
ReactDOM.unstable_createPortal(<div>portal</div>, null);
}).toThrow('Target container is not a DOM element.');
expect(() => {
ReactDOM.unstable_createPortal(
<div>portal</div>,
document.createTextNode('hi'),
);
}).toThrow('Target container is not a DOM element.');
});

it('should warn for non-functional event listeners', () => {
spyOn(console, 'error');
class Example extends React.Component {
Expand Down

0 comments on commit f265e63

Please sign in to comment.