Properly handle rendering into document when comparing markup

This commit is contained in:
Eric O'Connell 2015-07-09 11:48:42 -07:00
parent 0249adf3db
commit 1316160b86
1 changed files with 14 additions and 3 deletions

View File

@ -880,9 +880,20 @@ var ReactMount = {
checksum
);
var normalizer = document.createElement('div');
normalizer.innerHTML = markup;
var normalizedMarkup = normalizer.innerHTML;
// because rootMarkup is retrieved from the DOM, various normalizations
// will have occurred which will not be present in `markup`. Here,
// insert markup into a <div> or <iframe> depending on the container
// type to perform the same normalizations before comparing.
if (container.nodeType === ELEMENT_NODE_TYPE) {
var normalizer = document.createElement('div');
normalizer.innerHTML = markup;
var normalizedMarkup = normalizer.innerHTML;
} else {
var normalizer = document.createElement('iframe');
document.body.appendChild(normalizer);
normalizer.contentDocument.write(markup);
var normalizedMarkup = normalizer.contentDocument.documentElement.outerHTML;
}
var diffIndex = firstDifferenceIndex(normalizedMarkup, rootMarkup);
var difference = ' (client) ' +