Properly handle rendering into document when comparing markup
Eric O'Connell committed
Jul 9, 2015 at 11:48 UTC
1316160b866f7e34506910313338fabafb9defc3
1 file changed
+14
-3
src/renderers/dom/client/ReactMount.js
+14
-3
@@ -880,9 +880,20 @@ var ReactMount = {
880
checksum
881
);
882
883
- var normalizer = document.createElement('div');
884
- normalizer.innerHTML = markup;
885
- var normalizedMarkup = normalizer.innerHTML;
883
+ // because rootMarkup is retrieved from the DOM, various normalizations
884
+ // will have occurred which will not be present in `markup`. Here,
885
+ // insert markup into a <div> or <iframe> depending on the container
886
+ // type to perform the same normalizations before comparing.
887
+ if (container.nodeType === ELEMENT_NODE_TYPE) {
888
+ var normalizer = document.createElement('div');
889
+ normalizer.innerHTML = markup;
890
+ var normalizedMarkup = normalizer.innerHTML;
891
+ } else {
892
+ var normalizer = document.createElement('iframe');
893
+ document.body.appendChild(normalizer);
894
+ normalizer.contentDocument.write(markup);
895
+ var normalizedMarkup = normalizer.contentDocument.documentElement.outerHTML;
896
+ }
897
898
var diffIndex = firstDifferenceIndex(normalizedMarkup, rootMarkup);
899
var difference = ' (client) ' +