{"record":{"id":"84b8b29d40f2901e","repo":"leptos-rs/leptos","slug":"reading-from-a-localresource-outside-suspense-in","errorCode":null,"errorMessage":"Reading from a LocalResource outside Suspense in `ssr` mode will cause the response to hang, because LocalResources are always pending on the server.","messagePattern":"Reading from a LocalResource outside Suspense in `ssr` mode will cause the response to hang, because LocalResources are always pending on the server\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"leptos_server/src/local_resource.rs","lineNumber":147,"sourceCode":"    /// left to handle the `None` and `Err(_)` states.\n    #[track_caller]\n    pub fn and_then<U>(&self, f: impl FnOnce(&T) -> U) -> Option<Result<U, E>> {\n        self.map(|data| data.as_ref().map(f).map_err(|e| e.clone()))\n    }\n}\n\nimpl<T> IntoFuture for ArcLocalResource<T>\nwhere\n    T: Clone + 'static,\n{\n    type Output = T;\n    type IntoFuture = AsyncDerivedFuture<T>;\n\n    fn into_future(self) -> Self::IntoFuture {\n        if let Some(mut notifier) = use_context::<LocalResourceNotifier>() {\n            notifier.notify();\n        } else if cfg!(feature = \"ssr\") {\n            panic!(\n                \"Reading from a LocalResource outside Suspense in `ssr` mode \\\n                 will cause the response to hang, because LocalResources are \\\n                 always pending on the server.\"\n            );\n        }\n        self.data.into_future()\n    }\n}\n\nimpl<T> DefinedAt for ArcLocalResource<T> {\n    fn defined_at(&self) -> Option<&'static Location<'static>> {\n        #[cfg(any(debug_assertions, leptos_debuginfo))]\n        {\n            Some(self.defined_at)\n        }\n        #[cfg(not(any(debug_assertions, leptos_debuginfo)))]\n        {\n            None","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/leptos_server/src/local_resource.rs#L129-L165","documentation":"In ssr mode a LocalResource never resolves on the server (it is always pending, since its data is client-local). Reading it via into_future outside a Suspense context means there is no LocalResourceNotifier to defer serialization, so leptos panics instead of hanging the HTTP response forever.","triggerScenarios":"Calling `.get()`/`.await` (into_future) on a LocalResource during SSR when the read happens outside any <Suspense> component, so use_context::<LocalResourceNotifier>() returns None and the ssr feature is enabled.","commonSituations":"Awaiting a LocalResource in a component rendered on the server without wrapping it in <Suspense>; refactoring a Resource (server-friendly) into a LocalResource (client-only) and forgetting the SSR implications; reading the resource at the top level of a view during server render.","solutions":["Wrap the reading component/view in <Suspense> so the LocalResource can register its notifier.","If the data must be available during SSR, use a regular Resource (server-fn backed) instead of LocalResource.","Only read LocalResources in client/hydration-only code paths."],"exampleFix":"// before\nlet res = use_local_resource(...);\nview! { <p>{move || res.get().map(|d| d.text())}</p> } // panics on ssr\n// after\nview! {\n    <Suspense fallback=|| view! { <p>Loading...</p> }>\n        <p>{move || res.get().map(|d| d.text())}</p>\n    </Suspense>\n}","handlingStrategy":"try-catch","validationCode":"#[cfg(feature = \"ssr\")]\nfn local_resource_ssr_safe() -> bool {\n    use leptos::reactive_graph::LocalResourceNotifier;\n    // true only when rendering inside Suspense (notifier present)\n    leptos::prelude::use_context::<LocalResourceNotifier>().is_some()\n}","typeGuard":null,"tryCatchPattern":"// Panics cannot be caught idiomatically here; restructure instead.\n// catch_unwind is a last resort around the whole render:\nlet result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| render_app()));","preventionTips":["Always read LocalResources inside <Suspense>.","Use regular Resource for data needed during SSR.","Review components converted from Resource to LocalResource for SSR reads.","Run an SSR smoke test (cargo leptos serve + curl) in CI."],"tags":["rust","ssr","local-resource","suspense","panic"],"backgroundTag":"localresource-outside-suspense","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}