DioxusLabs / DioxusLabs/dioxus

Eval unexpected finish

Open
#4,590 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

**Problem**

Eval unexpectedly finishes after a while

**Steps To Reproduce**

Sample code
```rust
use dioxus::{logger::tracing, prelude::*};
use futures_util::StreamExt;

fn main() {
dioxus::launch(App);
}

#[component]
fn App() -> Element {
let js_cr = use_coroutine(|mut channel: UnboundedReceiver| {
let js = document::eval(
r"
while (true) {
const msg = await dioxus.recv()

console.log(`Received message ${msg}`)
}
",
);

async move {
loop {
match channel.next().await {
Some(msg) => {
let r = js.send(msg);
tracing::info!("{:?}", r);
}
None => unreachable!("shouldnt be here"),
};
}
}
});

rsx! {
button {
onclick: move |_| {
js_cr.send("Testing".to_string());
},
"Click to send"
}
}
}
```

**Expected behavior**

Clicking the button should always be able to send to js, but after a while the eval is finished.

**Screenshots**

**Environment:**

- Dioxus version: 0.6.3
- DX Cli version: 0.6.3
- Rust version: 1.88.0
- OS info: macOS
- App platform: web
- Browser: both Chrome and Firefox

**Temporary Solution**

adding this line before the loop makes it not drop (js)
```js
setInterval(() => {}, 2000)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.