Skip to content

Commit

Permalink
Split into multiple invariants
Browse files Browse the repository at this point in the history
That way the messages are extracted by the error code transform.
  • Loading branch information
acdlite committed Feb 7, 2017
1 parent 9fcf761 commit 0564b08
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 32 deletions.
45 changes: 29 additions & 16 deletions src/renderers/dom/fiber/ReactDOMFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,23 +378,36 @@ var ReactDOM = {
// Top-level check occurs here instead of inside child reconciler because
// because requirements vary between renderers. E.g. React Art
// allows arrays.
invariant(
isValidElement(element),
'ReactDOM.render(): Invalid component element.%s',
(
typeof element === 'string' ?
' Instead of passing a string like \'div\', pass ' +
'React.createElement(\'div\') or <div />.' :
typeof element === 'function' ?
' Instead of passing a class like Foo, pass ' +
'React.createElement(Foo) or <Foo />.' :
if (!isValidElement(element)) {
if (typeof element === 'string') {
invariant(
false,
'ReactDOM.render(): Invalid component element. Instead of ' +
'passing a string like \'div\', pass ' +
'React.createElement(\'div\') or <div />.'
);
} else if (typeof element === 'function') {
invariant(
false,
'ReactDOM.render(): Invalid component element. Instead of ' +
'passing a class like Foo, pass React.createElement(Foo) ' +
'or <Foo />.'
);
} else if (element != null && typeof element.props !== 'undefined') {
// Check if it quacks like an element
element != null && element.props !== undefined ?
' This may be caused by unintentionally loading two independent ' +
'copies of React.' :
''
)
);
invariant(
false,
'ReactDOM.render(): Invalid component element. This may be ' +
'caused by unintentionally loading two independent copies ' +
'of React.'
);
} else {
invariant(
false,
'ReactDOM.render(): Invalid component element.'
);
}
}
}

if (__DEV__) {
Expand Down
45 changes: 29 additions & 16 deletions src/renderers/dom/stack/client/ReactMount.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,23 +434,36 @@ var ReactMount = {

_renderSubtreeIntoContainer: function(parentComponent, nextElement, container, callback) {
validateCallback(callback, 'ReactDOM.render');
invariant(
React.isValidElement(nextElement),
'ReactDOM.render(): Invalid component element.%s',
(
typeof nextElement === 'string' ?
' Instead of passing a string like \'div\', pass ' +
'React.createElement(\'div\') or <div />.' :
typeof nextElement === 'function' ?
' Instead of passing a class like Foo, pass ' +
'React.createElement(Foo) or <Foo />.' :
if (!React.isValidElement(nextElement)) {
if (typeof nextElement === 'string') {
invariant(
false,
'ReactDOM.render(): Invalid component element. Instead of ' +
'passing a string like \'div\', pass ' +
'React.createElement(\'div\') or <div />.'
);
} else if (typeof nextElement === 'function') {
invariant(
false,
'ReactDOM.render(): Invalid component element. Instead of ' +
'passing a class like Foo, pass React.createElement(Foo) ' +
'or <Foo />.'
);
} else if (nextElement != null && typeof nextElement.props !== 'undefined') {
// Check if it quacks like an element
nextElement != null && nextElement.props !== undefined ?
' This may be caused by unintentionally loading two independent ' +
'copies of React.' :
''
)
);
invariant(
false,
'ReactDOM.render(): Invalid component element. This may be ' +
'caused by unintentionally loading two independent copies ' +
'of React.'
);
} else {
invariant(
false,
'ReactDOM.render(): Invalid component element.'
);
}
}

warning(
!container || !container.tagName ||
Expand Down

0 comments on commit 0564b08

Please sign in to comment.