diff --git a/Cargo.lock b/Cargo.lock index 2dcebf972e..2edc5e7744 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5679,6 +5679,7 @@ dependencies = [ "tracing-fluent-assertions", "tracing-subscriber", "warnings", + "wasm-bindgen-futures", "web-sys", ] diff --git a/packages/core/Cargo.toml b/packages/core/Cargo.toml index 368ea60489..30ce176934 100644 --- a/packages/core/Cargo.toml +++ b/packages/core/Cargo.toml @@ -26,6 +26,7 @@ futures-util = { workspace = true, default-features = false, features = ["alloc" serde = { workspace = true, optional = true, features = ["derive"] } subsecond = { workspace = true } anyhow = { workspace = true } +wasm-bindgen-futures = { workspace = true } [dev-dependencies] dioxus = { workspace = true } diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index bc1fced02f..940aaa451c 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -770,8 +770,20 @@ impl VirtualDom { #[cfg(debug_assertions)] fn register_subsecond_handler(&self) { let sender = self.runtime().sender.clone(); + subsecond::register_handler(std::sync::Arc::new(move || { - _ = sender.unbounded_send(SchedulerMsg::AllDirty); + #[cfg(target_arch = "wasm32")] + { + let sender = sender.clone(); + wasm_bindgen_futures::spawn_local(async move { + _ = sender.unbounded_send(SchedulerMsg::AllDirty); + }); + } + + #[cfg(not(target_arch = "wasm32"))] + { + let _ = sender.unbounded_send(SchedulerMsg::AllDirty); + } })); } }