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

Using multiple recv in js inside an eval on web ignores all promises but the last #2295

Closed
3 tasks
elias098 opened this issue Apr 11, 2024 · 1 comment · Fixed by #2302
Closed
3 tasks

Using multiple recv in js inside an eval on web ignores all promises but the last #2295

elias098 opened this issue Apr 11, 2024 · 1 comment · Fixed by #2302
Assignees
Labels
bug Something isn't working

Comments

@elias098
Copy link

Problem

not completely sure if its intended or not something to care about.

Currently when you do

dioxus.recv()
  .then((a) => {
    console.log("fulfilled");
  })
  .catch((a) => {
    console.error("rejected");
  }); 
dioxus.recv()
  .then((a) => {
    console.log("fulfilled");
  })
  .catch((a) => {
    console.error("rejected");
  }); 

in the js inside an eval in web while theres no messages in the queue it ignores all promises except for the last one

Steps To Reproduce

Here is the code i used to test it

fn main() {
    // Init debug
    dioxus_logger::init(LevelFilter::Info).expect("failed to init logger");
    console_error_panic_hook::set_once();

    launch(App);
}

fn App() -> Element {
    let mut signal = use_signal(|| 0);
    let mut eval2 = use_signal(|| None);
    use_effect(move || {
        if signal() == 1 {
            *eval2.write() = Some(eval(
                r#"
                    dioxus.recv()
                        .then((a) => {
                            console.log("fulfilled");
                        })
                        .catch((a) => {
                            console.error("rejected");
                        }); 
                    dioxus.recv()
                        .then((a) => {
                            console.log("fulfilled");
                        })
                        .catch((a) => {
                            console.error("rejected");
                        }); 
                "#,
            ));
        } else if signal() > 1 {
            let eval2 = eval2().unwrap();
            eval2.send("data".into()).unwrap();
        }
    });

    let onclick = move |_| signal.with_mut(|v| *v += 1);

    rsx! {
        button {
            onclick,
            "locks js"
        }
        {format!("{}", signal())}
    }
}

Expected behavior

i would expect the promises to be fulfilled in the order they were created in

Environment:

  • Dioxus version: 0.5.1
  • Rust version: 1.76.0
  • OS info: MacOS
  • App platform: web

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
  • I don't have time to fix this right now, but maybe later
@elias098
Copy link
Author

the code causing this should be that this.promiseResolve = resolve; overwrites the promise in eval.js

  recv() {
    return new Promise((resolve, _reject) => {
      // If data already exists, resolve immediately
      let data = this.received.shift();
      if (data) {
        resolve(data);
        return;
      }

      // Otherwise set a resolve callback
      this.promiseResolve = resolve;
    });
  }

@ealmloff ealmloff added the bug Something isn't working label Apr 12, 2024
@ealmloff ealmloff self-assigned this Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants