DioxusLabs/dioxus · error

Callback was called after the runtime was dropped

Error message

Callback was called after the runtime was dropped

What it means

Runtime panic raised when an external-listener Callback is invoked after the Dioxus runtime it belongs to has been dropped. The weak runtime reference captured at creation could not be upgraded, so the event has no scheduler to spawn onto.

Solutions

  1. Do not invoke callbacks (event handlers, spawned tasks) after the VirtualDOM/runtime has been dropped; cancel or check the runtime is alive before calling, e.g. by keeping the app running or dropping handles on shutdown.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at packages/core/src/events.rs:528 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/6b1848d0838f8a78. Report an issue: GitHub.

Appendix: source

Thrown at packages/core/src/events.rs:528

            Some(ExternalListenerCallback {
                callback: Box::new(move |event: Args| f(event).spawn()),
                runtime: Rc::downgrade(&runtime),
            }),
            Location::caller(),
        );
        Self { callback, origin }
    }

    /// Call this callback with the appropriate argument type
    ///
    /// This borrows the callback using a RefCell. Recursively calling a callback will cause a panic.
    #[track_caller]
    pub fn call(&self, arguments: Args) -> Ret {
        if let Some(callback) = self.callback.write().as_mut() {
            let runtime = callback
                .runtime
                .upgrade()
                .expect("Callback was called after the runtime was dropped");
            let _guard = RuntimeGuard::new(runtime.clone());
            runtime.with_scope_on_stack(self.origin, || (callback.callback)(arguments))
        } else {
            panic!("Callback was manually dropped")
        }
    }

    /// Create a `impl FnMut + Copy` closure from the Closure type
    pub fn into_closure(self) -> impl FnMut(Args) -> Ret + Copy + 'static {
        move |args| self.call(args)
    }

    /// Forcibly drop the internal handler callback, releasing memory
    ///
    /// This will force any future calls to "call" to not doing anything
    pub fn release(&self) {
        self.callback.set(None);
    }

View on GitHub (pinned to 24f6a829df)