mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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;
|
child = child.nextSibling;
|
||||||
}
|
}
|
||||||
|
global.console && console.error && console.error(
|
||||||
|
'Error while invoking `findComponentRoot` with the following ' +
|
||||||
|
'ancestor node:',
|
||||||
|
ancestorNode
|
||||||
|
);
|
||||||
invariant(
|
invariant(
|
||||||
false,
|
false,
|
||||||
'findComponentRoot: Unable to find element by React ID, `%s`. This ' +
|
'findComponentRoot(..., %s): Unable to find element. This probably ' +
|
||||||
'indicates that someone (or the browser) has mutated the DOM tree in ' +
|
'means the DOM was unexpectedly mutated (e.g. by the browser).',
|
||||||
'an unexpected way. Try inspecting the child nodes of the element with ' +
|
|
||||||
'React ID, `%s`.',
|
|
||||||
id,
|
id,
|
||||||
ReactID.getID(ancestorNode)
|
ReactID.getID(ancestorNode)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -139,10 +139,9 @@ describe('ReactInstanceHandles', function() {
|
|||||||
ReactID.getID(childNodeB)
|
ReactID.getID(childNodeB)
|
||||||
);
|
);
|
||||||
}).toThrow(
|
}).toThrow(
|
||||||
'Invariant Violation: findComponentRoot: Unable to find element by ' +
|
'Invariant Violation: findComponentRoot(..., .react[0].1:0): Unable ' +
|
||||||
'React ID, `.react[0].1:0`. This indicates that someone (or the ' +
|
'to find element. This probably means the DOM was unexpectedly ' +
|
||||||
'browser) has mutated the DOM tree in an unexpected way. Try ' +
|
'mutated (e.g. by the browser).'
|
||||||
'inspecting the child nodes of the element with React ID, `.react[0]`.'
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user