Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leftover DOM elements when switching between fragment and element #2842

Open
17dec opened this issue May 16, 2023 · 3 comments
Open

Leftover DOM elements when switching between fragment and element #2842

17dec opened this issue May 16, 2023 · 3 comments
Assignees
Labels
Type: Bug For bugs and any other unexpected breakage

Comments

@17dec
Copy link

17dec commented May 16, 2023

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
         )
    }
})

Flems

Steps to Reproduce

  1. Load above code
  2. Click a few times on the <div>
  3. Observe that the 'b' element from the fragment remains in the DOM after switching back to the non-fragment version.
@17dec 17dec added the Type: Bug For bugs and any other unexpected breakage label May 16, 2023
@j314h
Copy link

j314h commented May 16, 2023

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

or other tag or you can also delete the
tag in this case it will replace all the text inside the parent

@pygy
Copy link
Member

pygy commented Jun 15, 2023

This is indeed a bug, thanks for the report. I'll look into this.

@pygy pygy self-assigned this Jun 15, 2023
@sonkwl

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug For bugs and any other unexpected breakage
Projects
None yet
Development

No branches or pull requests

5 participants