Skip to content

Commit c59446f

Browse files
committed
Handle subsecond updates asynchronously in Dioxus
Try to resolve #4902. Empty merge commit
1 parent b084432 commit c59446f

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ futures-util = { workspace = true, default-features = false, features = ["alloc"
2626
serde = { workspace = true, optional = true, features = ["derive"] }
2727
subsecond = { workspace = true }
2828
anyhow = { workspace = true }
29+
wasm-bindgen-futures = { workspace = true }
2930

3031
[dev-dependencies]
3132
dioxus = { workspace = true }

packages/core/src/virtual_dom.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,20 @@ impl VirtualDom {
770770
#[cfg(debug_assertions)]
771771
fn register_subsecond_handler(&self) {
772772
let sender = self.runtime().sender.clone();
773+
773774
subsecond::register_handler(std::sync::Arc::new(move || {
774-
_ = sender.unbounded_send(SchedulerMsg::AllDirty);
775+
#[cfg(target_arch = "wasm32")]
776+
{
777+
let sender = sender.clone();
778+
wasm_bindgen_futures::spawn_local(async move {
779+
_ = sender.unbounded_send(SchedulerMsg::AllDirty);
780+
});
781+
}
782+
783+
#[cfg(not(target_arch = "wasm32"))]
784+
{
785+
let _ = sender.unbounded_send(SchedulerMsg::AllDirty);
786+
}
775787
}));
776788
}
777789
}

0 commit comments

Comments
 (0)