{"record":{"id":"6a793f721ecd959a","repo":"leptos-rs/leptos","slug":"executor-spawn-called-but-no-global-spawn-func","errorCode":null,"errorMessage":"Executor::spawn called, but no global 'spawn' function is configured.","messagePattern":"Executor::spawn called, but no global 'spawn' function is configured\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"any_spawner/src/lib.rs","lineNumber":79,"sourceCode":"\n#[cfg(all(not(feature = \"wasm-bindgen\"), not(debug_assertions)))]\n#[cold]\n#[inline(never)]\nfn no_op_spawn(_: PinnedFuture<()>) {\n    #[cfg(debug_assertions)]\n    eprintln!(\n        \"Warning: Executor::spawn called, but no global 'spawn' function is \\\n         configured (perhaps only spawn_local is supported, e.g., on wasm \\\n         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.","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/any_spawner/src/lib.rs#L61-L97","documentation":"This panic comes from any_spawner's no-op spawn placeholder, compiled under the wasm-bindgen target. In a WASM/browser environment there is no default global async executor, so any call to Executor::spawn before one is configured hits this cold function and panics. It is the library's way of saying 'you tried to spawn a task but nobody is driving futures'.","triggerScenarios":"Calling Executor::spawn (directly or via leptos task spawning) in a wasm-bindgen build before assigning a global executor with any_spawner::spawn::set_executor (e.g. executor::spawnLocal / wasm-bindgen-futures based implementation).","commonSituations":"Rendering a Leptos app in the browser without calling mount + executor setup in wasm-bindgen mode; tests running in wasm without initializing an executor; forgetting the cfg-gated executor init in aCSR/hydrate entrypoint.","solutions":["Call any_spawner::spawn::set_executor(Executor::WasmBindgen) (or the equivalent wrapper) early in your wasm entrypoint before any spawn.","If using Leptos, ensure the framework's client-side init (which configures the executor) actually runs on the WASM target.","If you did not intend to run in WASM, check your target/feature flags so the native executor implementation is compiled instead.","Wrap spawn calls behind a guard that no-ops or logs when no executor is configured during tests."],"exampleFix":"// before\nfn main() {\n    // spawns a resource/effect immediately -> panics in wasm\n    leptos::mount::mount_to_body(App);\n}\n// after\nfn main() {\n    any_spawner::spawn::set_executor(any_spawner::Executor::WasmBindgen);\n    leptos::mount::mount_to_body(App);\n}","handlingStrategy":"validation","validationCode":"// ensure an executor is installed before spawning (debug guard)\nfn assert_executor_ready() {\n    // any_spawner exposes no query API; guard by installing it idempotently at startup\n    std::sync::Once::new().call_once(|| {\n        #[cfg(target_arch = \"wasm32\")]\n        any_spawner::spawn::set_executor(any_spawner::Executor::WasmBindgen);\n    });\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call set_executor as the first statement of your wasm entrypoint.","Use a Once/Lazy initializer so executor setup is centralized.","In tests, provide a shared test fixture that installs an executor.","Never assume an implicit default executor exists in wasm-bindgen builds."],"tags":["wasm","async","executor","spawner","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"}