{"record":{"id":"1821cb104b4175de","repo":"leptos-rs/leptos","slug":"async-routes-not-supported-in-ssr","errorCode":null,"errorMessage":"async routes not supported in SSR","messagePattern":"async routes not supported in SSR","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"router/src/nested_router.rs","lineNumber":383,"sourceCode":"            let new_match = routes.match_route(current_url.path());\n            let view = match new_match {\n                None => Either::Left(fallback()),\n                Some(route) => {\n                    let mut loaders = Vec::new();\n                    route.build_nested_route(\n                        &current_url,\n                        base,\n                        &mut loaders,\n                        &mut outlets,\n                        &outer_owner,\n                    );\n\n                    // outlets will not send their views if the loaders are never polled\n                    // the loaders are async so that they can lazy-load routes in the browser,\n                    // but they should always be synchronously available on the server\n                    join_all(mem::take(&mut loaders))\n                        .now_or_never()\n                        .expect(\"async routes not supported in SSR\");\n\n                    Either::Right(top_level_outlet(&outlets, &outer_owner))\n                }\n            };\n            view.to_html_with_buf(\n                buf,\n                position,\n                escape,\n                mark_branches,\n                extra_attrs,\n            );\n        }\n    }\n\n    fn to_html_async_with_buf<const OUT_OF_ORDER: bool>(\n        self,\n        buf: &mut StreamBuilder,\n        position: &mut Position,","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/router/src/nested_router.rs#L365-L401","documentation":"In nested_router.rs `to_html_with_buf`, route loaders are polled with `join_all(...).now_or_never()`; loaders are async only to enable lazy-loading in the browser, but on the server they must resolve synchronously. If any loader awaits (e.g. lazy/dynamic route loading), the future is Pending, `now_or_never` returns None, and this panic fires.","triggerScenarios":"Server-rendering (`to_html_with_buf`) with a route whose loader is genuinely async (lazy route module loading, async data fetch in the loader), so it doesn't complete on first poll.","commonSituations":"Using browser-side lazy route loading in an SSR app; defining async route components where blocking resources should be used; porting a client-only app to SSR without making loaders sync on the server.","solutions":["Make route loaders resolve synchronously on the server: load route definitions eagerly and fetch data via blocking `<Suspense>`/resources instead.","Gate lazy loading behind client-only checks so the server always uses the already-available route/view.","Use `to_html_async_with_buf` (the async variant) if the surrounding server stack supports async rendering, though loaders still should be sync per router contract."],"exampleFix":"// before\nlet routes = lazy_routes(); // loader awaits dynamic import -> panics in SSR\n\n// after\nlet routes = if is_server() { eager_routes() } else { lazy_routes() };","handlingStrategy":"validation","validationCode":"// SSR pre-check: loaders must be sync on the server\nif is_server() && loaders.iter().any(|l| !l.is_ready()) {\n    panic!(\"route loader is async in SSR\");\n}","typeGuard":"fn loader_ssr_safe(l: &Loader) -> bool { !l.is_async() || is_browser() }","tryCatchPattern":null,"preventionTips":["Register routes eagerly in server builds; reserve lazy loading for the client.","Use blocking resources for data fetching in SSR.","Cover SSR rendering in tests to surface async loaders early."],"tags":["ssr","async-route","router","leptos"],"backgroundTag":"async-route-in-ssr","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}