{"record":{"id":"8e2530bb4317058d","repo":"leptos-rs/leptos","slug":"lazy-routes-should-not-be-used-with-hydrate-body","errorCode":null,"errorMessage":"lazy routes should not be used with hydrate_body(); use hydrate_lazy() instead","messagePattern":"lazy routes should not be used with hydrate_body\\(\\); use hydrate_lazy\\(\\) instead","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"router/src/flat_router.rs","lineNumber":732,"sourceCode":"                    ScopedFuture::new(async move {\n                        OwnedView::new(view.choose().await)\n                    })\n                }));\n\n                match view.as_mut().now_or_never() {\n                    Some(view) => Rc::new(RefCell::new(FlatRoutesViewState {\n                        view: view\n                            .into_any()\n                            .hydrate::<FROM_SERVER>(cursor, position),\n                        id,\n                        owner,\n                        params,\n                        path,\n                        url,\n                        matched,\n                    })),\n                    None => {\n                        panic!(\n                            \"lazy routes should not be used with \\\n                             hydrate_body(); use hydrate_lazy() instead\"\n                        );\n                    }\n                }\n            }\n        }\n    }\n\n    async fn hydrate_async(\n        self,\n        cursor: &Cursor,\n        position: &PositionState,\n    ) -> Self::State {\n        let FlatRoutesView {\n            current_url,\n            routes,\n            fallback,","sourceCodeStart":714,"sourceCodeEnd":750,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/router/src/flat_router.rs#L714-L750","documentation":"When hydrating with hydrate_body(), the flat router requires all routes to already be loaded; if the matched route is lazy (code-split via LazyRoute/lazy()), it panics because lazy route components must be fetched before body hydration. The dedicated hydrate_lazy() API first loads the lazy route, then hydrates.","triggerScenarios":"Using FlatRoutes::hydrate_body (or hydrate_body at the app root) while the matched route is defined with lazy() / Lazy::new or LazyRoute — i.e. the resolved match is a lazy (None variant) route.","commonSituations":"Code-splitting route components for smaller bundles while still calling hydrate_body in the client entry; older templates using hydrate_body updated to include lazy routes; mixing hydrate_body and lazy route definitions after a refactor.","solutions":["Replace hydrate_body() with hydrate_lazy() in the client entry when any route is lazy.","Remove lazy() wrappers from route components so all routes are statically available, keeping hydrate_body.","Check the entry point matches the route style: static routes -> hydrate_body, lazy routes -> hydrate_lazy."],"exampleFix":"// before\nleptos::mount::hydrate_body(App); // panics if a matched route is lazy()\n\n// after\nleptos::mount::hydrate_lazy(App); // loads lazy route chunks before hydrating","handlingStrategy":"validation","validationCode":"// before calling hydrate_body, ensure no matched route is lazy\nif route_tree.has_lazy_routes() { leptos::mount::hydrate_lazy(App); } else { leptos::mount::hydrate_body(App); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick the hydration API based on route style: lazy -> hydrate_lazy, static -> hydrate_body.","Keep entry-point templates in sync with route definitions when adding lazy()."],"tags":["leptos","leptos-router","hydration","lazy-routes","code-splitting"],"backgroundTag":"lazy-route-hydration-mismatch","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}