Skip to content

Commit 5c4c13f

Browse files
syranidezpao
authored andcommitted
Remove empty TextNode left behind by IE8 setInnerHTML workaround
(cherry picked from commit 8a135c0)
1 parent eb6d101 commit 5c4c13f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/browser/ui/__tests__/ReactMount-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,12 @@ describe('ReactMount', function() {
106106
expect(mockMount.mock.calls.length).toBe(2);
107107
expect(mockUnmount.mock.calls.length).toBe(1);
108108
});
109+
110+
it('should reuse markup if rendering to the same target twice', function() {
111+
var container = document.createElement('container');
112+
var instance1 = React.renderComponent(<div />, container);
113+
var instance2 = React.renderComponent(<div />, container);
114+
115+
expect(instance1 === instance2).toBe(true);
116+
});
109117
});

src/browser/ui/dom/setInnerHTML.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ if (ExecutionEnvironment.canUseDOM) {
6666
// Recover leading whitespace by temporarily prepending any character.
6767
// \uFEFF has the potential advantage of being zero-width/invisible.
6868
node.innerHTML = '\uFEFF' + html;
69-
node.firstChild.deleteData(0, 1);
69+
70+
// deleteData leaves an empty `TextNode` which offsets the index of all
71+
// children. Definitely want to avoid this.
72+
var textNode = node.firstChild;
73+
if (textNode.data.length === 1) {
74+
node.removeChild(textNode);
75+
} else {
76+
textNode.deleteData(0, 1);
77+
}
7078
} else {
7179
node.innerHTML = html;
7280
}

0 commit comments

Comments
 (0)