mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Continue over ID-less children in ReactMount.findComponentRoot.
This fixes our perf test by coping with edge cases like the injection of `<tbody>` between `<table>` and `<tr>` nodes, which occurs automatically in some browsers when we set `.innerHTML`. Introducing more search branches would be risky if not for my previous commit that made `findComponentRoot` breadth-first instead of depth-first.
This commit is contained in:
committed by
Paul O’Shannessy
parent
a5ddb07cb3
commit
a4123a069e
@@ -303,6 +303,13 @@ var ReactInstanceHandles = {
|
||||
firstChildren.push(child.firstChild);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// If this child had no ID, then there's a chance that it was
|
||||
// injected automatically by the browser, as when a `<table>`
|
||||
// element sprouts an extra `<tbody>` child as a side effect of
|
||||
// `.innerHTML` parsing. Optimistically continue down this
|
||||
// branch, but not before examining the other siblings.
|
||||
firstChildren.push(child.firstChild);
|
||||
}
|
||||
child = child.nextSibling;
|
||||
}
|
||||
|
||||
@@ -133,15 +133,20 @@ describe('ReactInstanceHandles', function() {
|
||||
// No ID on `childNodeA`, it was "rendered by the browser".
|
||||
ReactID.setID(childNodeB, '.react[0].1:0');
|
||||
|
||||
expect(ReactInstanceHandles.findComponentRoot(
|
||||
parentNode,
|
||||
ReactID.getID(childNodeB)
|
||||
)).toBe(childNodeB);
|
||||
|
||||
expect(function() {
|
||||
ReactInstanceHandles.findComponentRoot(
|
||||
parentNode,
|
||||
ReactID.getID(childNodeB)
|
||||
ReactID.getID(childNodeB) + ":junk"
|
||||
);
|
||||
}).toThrow(
|
||||
'Invariant Violation: findComponentRoot(..., .react[0].1:0): Unable ' +
|
||||
'to find element. This probably means the DOM was unexpectedly ' +
|
||||
'mutated (e.g. by the browser).'
|
||||
'Invariant Violation: findComponentRoot(..., .react[0].1:0:junk): ' +
|
||||
'Unable to find element. This probably means the DOM was ' +
|
||||
'unexpectedly mutated (e.g. by the browser).'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user