Open neurodynamic opened 4 years ago
@neurodynamic I linked a PR that adds a test for us to review. You are right. It doesn't remove another element with the same id. I'm dig into the traversal mechanisms and see if it is possible to get this test passing.
In this PR, I added a few tests to show various behaviours with duplicate ids. There is one test that shows the duplicate id
is kept. I know the reason why. In order to allow duplicate ids, we would need to reverse the way we store ids ({ 'id': element }
) and take advantage of a WeakMap data structure. I'll have to test out some of these ideas because likely this would result in a major version bump.
The library seems to get confused by elements with the same id attribute. I realize having more than one element with the same id is bad practice, but it can easily happen temporarily in the process of editing HTML, and very strange behavior results.
Example: if I create several
p
elements with an id ofhi
, runningmorphdom
after each is created, and then I delete some of those samep
elements from the HTML that is being passed tomorphdom
, the corresponding elements are not removed, even if all of thep
tags are removed.This same example behaves exactly as would normally be expected if the
p
tags do not have id attributes.Example gif: