Open Quelklef opened 2 years ago
Workaround: put the conditional addClass
after the unconditional one
I think I have spotted the cause, and it's with the diffing algorithm. This is what I think is happening.
old | new |
---------------+---------------|
addClass "two" | addClass "one"| compare: remove class "two", add class "one"
addClass "one" | | compare: remove class "one"
Oh, that's subtle. This seems to suggest that the issue could affect other kinds of attributes, as well, such as conditionally attaching an event listener.
Unclear to me the proper solution. What jumps to mind is to reify attribute collections as Set
s instead of List
s; set subtraction will then give you which attributes need to be added/removed.
But attributes don't commute, so jumping to a set is not correct.
Perhaps just do the same but with list differences? I don't know if there's an algorithm for that which is better than 2nm
steps, but maybe that's acceptable since usually there aren't that many attributes on a node.
Our model has two states (≅ bool). In the initial state, we give a
<p>
element a class to make the text underlined. When we switch to the second state, we additionally give it a class to make the text bold. When we switch back to the initial state, we remove the class to make the text bold. The class to make the text underlined wrongly also disappears.https://user-images.githubusercontent.com/14851215/150645856-bffe5704-dd62-4645-a4f6-dbf08f308211.mp4
MWE:
Note that if the order of the two
addClass
es are reversed, the bug ceases to manifest.