Improve findComponentRoot Error Message
Instead of simply logging the React ID of the `ancestorNode` when `findComponentRoot` fails, use a `try ... finally` to `console.error` the `ancestorNode`. This allows modern web inspectors to actually log a reference to the node (which may not have a React ID).
This means when people run into the problem, they will not have to execute:
require('ReactID').getNode(<copy+paste>);
NOTE: Admittedly, this will not log anything in IE8. That's fine, since IE8 has shitty console logging anyway.
This commit is contained in:
committed by
Paul O’Shannessy
parent
bd150ec658
commit
738de8cfa8
@@ -296,12 +296,15 @@ var ReactInstanceHandles = {
|
||||
}
|
||||
child = child.nextSibling;
|
||||
}
|
||||
global.console && console.error && console.error(
|
||||
'Error while invoking `findComponentRoot` with the following ' +
|
||||
'ancestor node:',
|
||||
ancestorNode
|
||||
);
|
||||
invariant(
|
||||
false,
|
||||
'findComponentRoot: Unable to find element by React ID, `%s`. This ' +
|
||||
'indicates that someone (or the browser) has mutated the DOM tree in ' +
|
||||
'an unexpected way. Try inspecting the child nodes of the element with ' +
|
||||
'React ID, `%s`.',
|
||||
'findComponentRoot(..., %s): Unable to find element. This probably ' +
|
||||
'means the DOM was unexpectedly mutated (e.g. by the browser).',
|
||||
id,
|
||||
ReactID.getID(ancestorNode)
|
||||
);
|
||||
|
||||
@@ -139,10 +139,9 @@ describe('ReactInstanceHandles', function() {
|
||||
ReactID.getID(childNodeB)
|
||||
);
|
||||
}).toThrow(
|
||||
'Invariant Violation: findComponentRoot: Unable to find element by ' +
|
||||
'React ID, `.react[0].1:0`. This indicates that someone (or the ' +
|
||||
'browser) has mutated the DOM tree in an unexpected way. Try ' +
|
||||
'inspecting the child nodes of the element with React ID, `.react[0]`.'
|
||||
'Invariant Violation: findComponentRoot(..., .react[0].1:0): Unable ' +
|
||||
'to find element. This probably means the DOM was unexpectedly ' +
|
||||
'mutated (e.g. by the browser).'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user