Teamwork/visual-dom-diff

validatetable function works incorrectly

Closed this issue · 1 comments

When a table includes text nodes between tr's or td's validatetable function works incorrently. Look at following sample:

First html includes space between tags:
<table> <tr> <td>test</td></tr></table>

Second html includes no space between tags:
<table><tr><td>test</td></tr></table>

validate table function validates second html but returns false for first html because of space chars between tags.

When i examined validate table function I realized that validatetable function works with childNodes of node element. I think it must work with children element which includes the same data with childNodes element except text nodes.

It works like that by design - visual-dom-diff expects normalized DOM trees as inputs. Assuming normalized inputs leads to better performance and simpler implementation, as the library does not need special code paths for edge cases like text nodes appearing in unexpected places (for example see Permitted Content of Table Element - text nodes are not there).

In other words, you'll need to normalize the DOM trees before passing them to visual-dom-diff. This may include removing text nodes directly under TABLE, TR, UL, OL, etc and possibly other actions specific to your content.