mithril.js
mithril.js copied to clipboard
Leftover DOM elements when switching between fragment and element
Mithril.js version: v2.0.4-156-gad9aa97d
Browser and OS: Firefox on Linux.
Project:
Code
var toggle = true;
m.mount(document.body, {
view: function() {
return m('div', { onclick: () => toggle = !toggle },
toggle ? 'text' : [ 'fragment', 'b' ],
m('br') // extra element is needed to trigger the issue
)
}
})
Steps to Reproduce
- Load above code
- Click a few times on the
<div>
- Observe that the
'b'
element from the fragment remains in the DOM after switching back to the non-fragment version.
hi it's because of the
.
I find the funny approach of putting a
after a simple text hahaha.
the problem in this example is that each piece of text is considered as a pseudo element node
in the first you have "text" then
in the second you have
"fragment" then "b" then
when it switches for the first time it removes the first node and displays the two nodes "fragment" then "b" then when you switch for the second time it removes the first node but it leave the second because for him we replace only by a node (the first) and therefore the "b" remains.
to avoid this problem, you must surround your text with a
tag in this case it will replace all the text inside the parent
This is indeed a bug, thanks for the report. I'll look into this.
working properl.
clicked!
Second click!