diff --git a/src/core/ReactInstanceHandles.js b/src/core/ReactInstanceHandles.js index df3d2e8f5b..a4ddec7592 100644 --- a/src/core/ReactInstanceHandles.js +++ b/src/core/ReactInstanceHandles.js @@ -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 `` + // element sprouts an extra `` 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; } diff --git a/src/core/__tests__/ReactInstanceHandles-test.js b/src/core/__tests__/ReactInstanceHandles-test.js index 110612c1c8..b5161547c7 100644 --- a/src/core/__tests__/ReactInstanceHandles-test.js +++ b/src/core/__tests__/ReactInstanceHandles-test.js @@ -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).' ); }); });