Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove empty TextNode left behind by IE8 setInnerHTML workaround #1903

Merged
merged 1 commit into from
Jul 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/browser/ui/__tests__/ReactMount-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,12 @@ describe('ReactMount', function() {
expect(mockMount.mock.calls.length).toBe(2);
expect(mockUnmount.mock.calls.length).toBe(1);
});

it('should reuse markup if rendering to the same target twice', function() {
var container = document.createElement('container');
var instance1 = React.renderComponent(<div />, container);
var instance2 = React.renderComponent(<div />, container);

expect(instance1 === instance2).toBe(true);
});
});
10 changes: 9 additions & 1 deletion src/browser/ui/dom/setInnerHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ if (ExecutionEnvironment.canUseDOM) {
// Recover leading whitespace by temporarily prepending any character.
// \uFEFF has the potential advantage of being zero-width/invisible.
node.innerHTML = '\uFEFF' + html;
node.firstChild.deleteData(0, 1);

// deleteData leaves an empty `TextNode` which offsets the index of all
// children. Definitely want to avoid this.
var textNode = node.firstChild;
if (textNode.data.length === 1) {
node.removeChild(textNode);
} else {
textNode.deleteData(0, 1);
}
} else {
node.innerHTML = html;
}
Expand Down