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

onbeforeremove not being triggered when list element is removed #2881

Closed
frenautvh opened this issue Sep 4, 2023 · 2 comments
Closed

onbeforeremove not being triggered when list element is removed #2881

frenautvh opened this issue Sep 4, 2023 · 2 comments
Assignees
Labels
Type: Bug For bugs and any other unexpected breakage

Comments

@frenautvh
Copy link

Mithril 2.2.3

Firefox 117 on MacOS

Code

https://jsfiddle.net/v6qgoczx/

const items = [1, 2, 3]

const TodoItem = {
    view: (v) => m('span', v.attrs.value),
    oncreate: (v) => console.log('create', v.attrs.value),
    onupdate: (v) => console.log('update', v.attrs.value),
    onbeforeupdate: (v) => console.log('beforeupdate', v.attrs.value),
    onremove: (v) => console.log('remove', v.attrs.value),
    onbeforeremove: (v) => console.log('beforeremove', v.attrs.value),
}

const TodoList = {
    view: (v) =>
        m('ul', v.attrs.items.map(item =>
            m('li',
                m(TodoItem, {
                    value: item,
                }))
        ))
}

m.mount(document.body, {
    view: () => m(TodoList, { items })
})

setTimeout(() => {
    items.pop()
    m.redraw();
}, 1000)

Steps to Reproduce

https://jsfiddle.net/v6qgoczx/

Expected Behavior

Outputs :

create 1
create 2
create 3
beforeupdate 1
beforeupdate 2
beforeremove 3 <-- missing
remove 3
update 1
update 2

Current Behavior

Outputs :

create 1
create 2
create 3
beforeupdate 1
beforeupdate 2
remove 3
update 1
update 2

@frenautvh frenautvh added the Type: Bug For bugs and any other unexpected breakage label Sep 4, 2023
@frenautvh
Copy link
Author

This hook is only called on the DOM element that loses its parentNode, but it does not get called in its child elements.

Sorry for the noise

@dead-claudia
Copy link
Member

This hook is only called on the DOM element that loses its parentNode, but it does not get called in its child elements.

Sorry for the noise

Yeah, that's intended behavior. Anything else is a bug.

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

2 participants