Permalink
Browse files

fix(observedom): Adjustments to mutation type detection

  • Loading branch information...
tmorehouse committed Sep 14, 2017
1 parent c1353a7 commit 75e92d3355c72ea10b7a4b6e4a1ad4a2e5a07d84
Showing with 2 additions and 11 deletions.
  1. +2 −11 lib/utils/observe-dom.js
@@ -34,19 +34,10 @@ export default function observeDOM(el, callback, opts) {
const type = mutation.type;
// DOM Node (could be any DOM Node type - HTMLElement, Text, comment, etc)
const target = mutation.target;
// Previous Value (only for characterData and attributes)
const old = mutation.oldValue;
if (type === 'characterData' && target.nodeType === Node.TEXT_NODE && old !== target.data) {
if (type === 'characterData' && target.nodeType === Node.TEXT_NODE) {
// We ignore nodes that are not TEXt (i.e. comments, etc) as they don't change layout
// Updating character data with the same value still triggers a mutation
// So we compare the old value to the new value
changed = true;
} else if (type === 'attributes' && target.getAttribute(mutation.attributeName) !== old) {
// Updating an attribute with the same value still triggers a mutation, so we compare
// the old value to the new value. For atributes like class or style, the content order
// could change (i.e. classes changed order in string), but have no affect on layout.
// We could pre-process these here but that added overhead might be more than the
// callback's overhead. So we just run callback anyways.
} else if (type === 'attributes') {
changed = true;
} else if (type === 'childList' && (mutation.addedNodes.length > 0 || mutation.removedNodes.length > 0)) {
// This includes HTMLElement and Text Nodes being added/removed/re-arranged

0 comments on commit 75e92d3

Please sign in to comment.