{"record":{"id":"ec121043265ed586","repo":"leptos-rs/leptos","slug":"executor-spawn-local-called-but-no-global-spawn","errorCode":null,"errorMessage":"Executor::spawn_local called, but no global 'spawn_local' function is configured.","messagePattern":"Executor::spawn_local called, but no global 'spawn_local' function is configured\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"any_spawner/src/lib.rs","lineNumber":88,"sourceCode":"         without threading?).\"\n    );\n}\n\n// Wasm panics if you spawn without an executor\n#[cfg(feature = \"wasm-bindgen\")]\n#[cold]\n#[inline(never)]\nfn no_op_spawn(_: PinnedFuture<()>) {\n    panic!(\n        \"Executor::spawn called, but no global 'spawn' function is configured.\"\n    );\n}\n\n#[cfg(not(debug_assertions))]\n#[cold]\n#[inline(never)]\nfn no_op_spawn_local(_: PinnedLocalFuture<()>) {\n    panic!(\n        \"Executor::spawn_local called, but no global 'spawn_local' function \\\n         is configured.\"\n    );\n}\n\n/// Errors that can occur when using the executor.\n#[derive(Error, Debug)]\npub enum ExecutorError {\n    /// The executor has already been set.\n    #[error(\"Global executor has already been set.\")]\n    AlreadySet,\n}\n\n/// A global async executor that can spawn tasks.\npub struct Executor;\n\nimpl Executor {\n    /// Spawns a thread-safe [`Future`].","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/any_spawner/src/lib.rs#L70-L106","documentation":"This panic is the release-mode (or non-tracing) counterpart for spawn_local: any_spawner has no global 'spawn_local' implementation registered, so the no_op_spawn_local placeholder is invoked and panics. It means local (same-thread) task spawning was requested before an executor was configured.","triggerScenarios":"Calling Executor::spawn_local in a build without a configured global spawn_local function (no any_spawner::spawn_local::set_executor call), e.g. on native or in release builds where the debug handler is compiled out.","commonSituations":"Using spawn_local for DOM-touching tasks in wasm without executor init; native apps spawning thread-local futures without a LocalSet-based executor registered; debug vs release differences hiding the richer debug message.","solutions":["Register a global local executor via any_spawner::spawn_local::set_executor(...) (e.g. LocalSet on native, wasm-bindgen on wasm) at startup, before spawning.","In Leptos, verify the platform init ran (client hydration or server bootstrap) which wires up the executor.","Confirm you call spawn_local only from the thread that owns the registered LocalSet/executor."],"exampleFix":"// before\nlet rt = tokio::runtime::Runtime::new().unwrap();\nExecutor::spawn_local(async { do_work().await }); // panics: no local executor\n// after\nlet local = tokio::task::LocalSet::new();\nany_spawner::spawn_local::set_executor(any_spawner::LocalExecutor::TokioLocalSet(local.clone()));\nlocal.spawn_local(async { do_work().await });","handlingStrategy":"validation","validationCode":"// idempotent local-executor installation before any spawn_local\nfn ensure_local_executor() {\n    thread_local! { static INIT: std::cell::Cell<bool> = const { std::cell::Cell::new(false) }; }\n    INIT.with(|i| {\n        if !i.get() {\n            // install appropriate LocalSet/wasm executor here\n            i.set(true);\n        }\n    });\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair every Executor::spawn_local usage with a verified executor install on the same thread.","Prefer wrapping spawn_local in a helper that guarantees initialization.","Check debug and release builds both init the executor (cfg differences matter)."],"tags":["wasm","async","executor","spawn-local","panic"],"backgroundTag":"no-global-executor-configured","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}