Hey,
I've been testing out some diffing algos, curious to see which DOM operations they actually perform.
One of the libraries I tested was this one, and I've come across a case where it seems to do an unnecessary DOM operation.
Here's my test bench:
https://jsfiddle.net/mindplay/o4gbaqw0/
I've added console.log
statements for every DOM operation - you can press the buttons to perform various array operations to change the sorting of the elements, and then watch the console output for the exact DOM operations resulting from the diff operation from one state to the next.
It looks good for all operations except "Rotate Up" - which basically means, "take the first item on the list and move it to the bottom", which should be doable with a single insertBefore
.
Instead, the result is two operations - a seemingly unnecessary replaceChild
operation, followed by the expected insertBefore
operation. (The resulting DOM state is correct though.)
With devtools open, you can see two nodes are being affected:
It isn't explicitly stated in the README of either this project or the original domdiff
, but presumably the point of diffing is to perform as few DOM operations as possible? Just figured I'd report my findings, in case you do consider this a subtle "bug". 🙂