patrick-steele-idem / morphdom

Fast and lightweight DOM diffing/patching (no virtual DOM needed)
MIT License
3.21k stars 129 forks source link

DOM is altered unnecessarily in the presence of comments #66

Closed cfinucane closed 8 years ago

cfinucane commented 8 years ago

I noticed that morphdom was updating my DOM way more than I expected, and narrowed it down to the presence of comments. Here's a simple test I added that fails (pull request with naive fix to follow).

 it('should not alter the DOM unnecessarily in the presence of comments', function() {
     var el1 = document.createElement('div');
     el1.innerHTML = '<!-- comment --><div class="div1">a</div>';

     var el2 = el1.cloneNode(true);

     var addedNodes = [];
     var discardedNodes = [];
     morphdom(el1, el2, {
         onNodeAdded: function(el) { addedNodes.push(el) },
         onNodeDiscarded: function(el) { discardedNodes.push(el) }
     });

     // This was a no-op update, and should have made no changes
     expect(addedNodes).to.be.empty;
     expect(discardedNodes).to.be.empty;
 });
patrick-steele-idem commented 8 years ago

New version published with fix: morphdom@1.4.3

Thanks!