blitz icon indicating copy to clipboard operation
blitz copied to clipboard

Event recursion on input in tui

Open gh22749268 opened this issue 2 years ago • 0 comments

Problem

The oninput event fall into recursion when the listener changes its own property. Additionally, before emitting the event, it should be checked if the value is not equal to the previous one. This prevents recursion on slower input, but the issue still appears with faster inputs.

Steps To Reproduce

Steps to reproduce the behavior:

[dependencies]
dioxus = "0.4.3"
dioxus-tui = "0.4.3"
#![allow(non_snake_case)]
// import the prelude to get access to the `rsx!` macro and the `Scope` and `Element` types
use dioxus::prelude::*;

fn main() {
    // launch the app in the terminal
    dioxus_tui::launch(App);
}

// create a component that renders a div with the text "Hello, world!"
pub fn App(cx: Scope) -> Element {
    let name = use_state(cx, || "bob".to_string());

    cx.render(rsx! {
        input {
            // we tell the component what to render
            value: "{name}",
            // and what to do when the value changes
            oninput: move |evt| name.set(evt.value.clone()),
        }
    })
}

Expected behavior

Should not

Screenshots

If applicable, add screenshots to help explain your problem.

Environment:

  • Dioxus version: 0.4.3
  • Rust version: 1.70.0
  • OS info: any
  • App platform: tui

Questionnaire

  • [ ] I'm interested in fixing this myself but don't know where to start
  • [ ] I would like to fix and I have a solution
  • [x] I don't have time to fix this right now, but maybe later

gh22749268 avatar Jan 06 '24 19:01 gh22749268