{"record":{"id":"82cb2b71850a69de","repo":"yewstack/yew","slug":"failed-to-find-worker-context","errorCode":null,"errorMessage":"failed to find worker context","messagePattern":"failed to find worker context","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/yew-agent/src/oneshot/hooks.rs","lineNumber":51,"sourceCode":"    }\n}\n\nimpl<T> PartialEq for UseOneshotRunnerHandle<T>\nwhere\n    T: Oneshot,\n{\n    fn eq(&self, rhs: &Self) -> bool {\n        self.state == rhs.state\n    }\n}\n\n/// A hook to create a runner to an oneshot agent.\n#[hook]\npub fn use_oneshot_runner<T>() -> UseOneshotRunnerHandle<T>\nwhere\n    T: Oneshot + 'static,\n{\n    let state = use_context::<OneshotProviderState<T>>().expect(\"failed to find worker context\");\n\n    UseOneshotRunnerHandle { state }\n}\n","sourceCodeStart":33,"sourceCodeEnd":55,"githubUrl":"https://github.com/yewstack/yew/blob/0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3/packages/yew-agent/src/oneshot/hooks.rs#L33-L55","documentation":"use_oneshot_runner<T> (packages/yew-agent/src/oneshot/hooks.rs:51) fetches an OneshotProviderState<T> from Yew's context system and panics with .expect when it is absent. The context only exists if an ancestor component rendered <OneshotProvider<T>> (packages/yew-agent/src/oneshot/provider.rs:90), so the panic means the hook ran in a subtree with no matching provider for that agent type T.","triggerScenarios":"Calling use_oneshot_runner::<MyAgent>() inside a component whose ancestors never rendered <OneshotProvider<MyAgent>>; placing the provider as a sibling instead of an ancestor; registering the provider for a different agent type T than the one requested by the hook.","commonSituations":"Adding an oneshot agent hook to a deep page component while the provider was only added on another branch of the tree; forgetting to re-add the provider after refactoring the root layout; generic parameter mismatch so the context type does not line up.","solutions":["Wrap the consuming component's subtree in <OneshotProvider<MyAgent>> so the provider is an ancestor: html! { <OneshotProvider<MyAgent, Bincode> path={AttrValue::from(\"/agent.js\")}> <Page /> </OneshotProvider<MyAgent, Bincode>> }","Verify the generic agent type passed to use_oneshot_runner is exactly the type given to OneshotProvider","If the provider is conditionally rendered, ensure it mounts before any child calls the hook (render the provider unconditionally at the app root)"],"exampleFix":"// before\nhtml! { <Page /> }  // Page calls use_oneshot_runner::<MyAgent>()\n\n// after\nhtml! {\n    <OneshotProvider<MyAgent, Bincode> path={AttrValue::from(\"/agent.js\")}>\n        <Page />\n    </OneshotProvider<MyAgent, Bincode>>\n}","handlingStrategy":"validation","validationCode":"// ensure the provider is an ancestor of every use_oneshot_runner call site\n// html! { <OneshotProvider<MyAgent, Bincode> path={AttrValue::from(\"/agent.js\")}>\n//     <ConsumingComponent />\n// </OneshotProvider<MyAgent, Bincode>> }","typeGuard":"// debug-only guard: place at the top of the consuming component\n// #[cfg(debug_assertions)]\n// fn assert_provider<T: 'static>() { yew::functional::use_context::<yew_agent::oneshot::OneshotProviderState<T>>().expect(\"missing OneshotProvider<T> ancestor\"); }","tryCatchPattern":null,"preventionTips":["Mount OneshotProvider at the app root so no route can bypass it","Keep the agent type parameter identical between provider and hook","Wrap components in the provider in tests too — the hook panics outside the provider subtree"],"tags":["rust","wasm","yew-agent","context-provider","runtime-panic"],"backgroundTag":"missing-context-provider","analyzedSha":"0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3","analyzedAt":"2026-08-22T21:16:31.212Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}