Skip to content

Conversation

@rapporian
Copy link

@rapporian rapporian commented Dec 19, 2025

Hi @ealmloff, This PR implements the closure strategy discussed. It adds an optional cleanup closure to onmounted handlers. When an element is removed from the DOM, any cleanup closure returned by its onmounted handler is automatically invoked.

Here is how it would be used:

div {
    onmounted: move |e| {
        let el = e.data();
        start_animation(el.clone());
        move || stop_animation(el)
    },
}

Changes

  • onmounted handlers can now return a FnOnce() cleanup closure
  • Cleanup runs before element removal (removereplace_with)
  • Existing handlers returning () or async {} continue to work
  • Web renderer only (desktop/mobile not yet implemented)

Testing

  • Added Playwright test that toggles an element and verifies cleanup is called

Documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant