DioxusLabs/dioxus · error
Must be called from inside a Dioxus runtime. Help: Some API
Error message
Must be called from inside a Dioxus runtime.
Help: Some APIs in dioxus require a global runtime to be present.
If you are calling one of these APIs from outside of a dioxus runtime
(typically in a web-sys closure or dynamic library), you will need to
grab the runtime from a scope that has it and then move it into your
new scope with a runtime guard.
For example, if you are trying to use dioxus apis from a web-sys
closure, you can grab the runtime from the scope it is created in:
```rust
use dioxus::prelude::*;
static COUNT: GlobalSignal<i32> = Signal::global(|| 0);
#[component]
fn MyComponent() -> Element {
use_effect(|| {
// Grab the runtime from the MyComponent scope
let runtime = Runtime::current().expect("Components run in the Dioxus runtime");
// Move the runtime into the web-sys closure scope
let web_sys_closure = Closure::new(|| {
// Then create a guard to provide the runtime to the closure
let _guard = RuntimeGuard::new(runtime);
// and run whatever code needs the runtime
tracing::info!("The count is: {COUNT}");
});
})
}
``` What it means
Error "Must be called from inside a Dioxus runtime. Help: Some APIs in dioxus require a global runtime to be present. If you are calling one of these APIs from outside of a dioxus runtime (typically in a web-sys closure or dynamic library), you will need to grab the runtime from a scope that has it and then move it into your new scope with a runtime guard. For example, if you are trying to use dioxus apis from a web-sys closure, you can grab the runtime from the scope it is created in: ```rust use dioxus::prelude::*; static COUNT: GlobalSignal<i32> = Signal::global(|| 0); #[component] fn MyComponent() -> Element { use_effect(|| { // Grab the runtime from the MyComponent scope let runtime = Runtime::current().expect("Components run in the Dioxus runtime"); // Move the runtime into the web-sys closure scope let web_sys_closure = Closure::new(|| { // Then create a guard to provide the runtime to the closure let _guard = RuntimeGuard::new(runtime); // and run whatever code needs the runtime tracing::info!("The count is: {COUNT}"); }); }) } ```" thrown in DioxusLabs/dioxus.
Source
Thrown at packages/core/src/runtime.rs:118
scope_states: Default::default(),
scope_stack: Default::default(),
suspense_stack: Default::default(),
current_task: Default::default(),
tasks: Default::default(),
suspended_tasks: Default::default(),
pending_effects: Default::default(),
dirty_tasks: Default::default(),
render_targets: RefCell::new(render_targets),
mounts: Default::default(),
})
}
/// Get the current runtime
pub fn current() -> Rc<Self> {
RUNTIMES
.with(|stack| stack.borrow().last().cloned())
.unwrap_or_else(|| {
panic!(
"Must be called from inside a Dioxus runtime.
Help: Some APIs in dioxus require a global runtime to be present.
If you are calling one of these APIs from outside of a dioxus runtime
(typically in a web-sys closure or dynamic library), you will need to
grab the runtime from a scope that has it and then move it into your
new scope with a runtime guard.
For example, if you are trying to use dioxus apis from a web-sys
closure, you can grab the runtime from the scope it is created in:
```rust
use dioxus::prelude::*;
static COUNT: GlobalSignal<i32> = Signal::global(|| 0);
#[component]
fn MyComponent() -> Element {{
use_effect(|| {{View on GitHub (pinned to 24f6a829df)
Solutions
- Call the API from inside a Dioxus runtime. From foreign scopes (web-sys closures, dynamic libraries), capture Runtime::current() where it exists and enter it with RuntimeGuard::new(runtime).
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at packages/core/src/runtime.rs:118 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23).
Data as JSON: /api/errors/90572b5edc4a915e.
Report an issue: GitHub.