{"record":{"id":"35b30e1975657ef6","repo":"yewstack/yew","slug":"failed-to-deserialize-state","errorCode":null,"errorMessage":"failed to deserialize state","messagePattern":"failed to deserialize state","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/yew/src/functional/hooks/use_prepared_state/feat_hydration.rs","lineNumber":91,"sourceCode":"            let data = use_state(|| {\n                let (s, handle) = Suspension::new();\n                (\n                    SuspensionResult::<(Option<Rc<T>>, Option<Rc<D>>)>::Err(s),\n                    Some(handle),\n                )\n            })\n            .run(ctx);\n\n            let state = {\n                let data = data.clone();\n                ctx.next_prepared_state(move |_re_render, buf| -> PreparedStateBase<T, D> {\n                    if let Some(buf) = buf {\n                        let buf = format!(\"data:application/octet-binary;base64,{buf}\");\n\n                        spawn_local(async move {\n                            let buf = decode_base64(&buf)\n                                .await\n                                .expect(\"failed to deserialize state\");\n\n                            let ((state, deps), _) =\n                                bincode::serde::decode_from_slice::<(Option<T>, Option<D>), _>(\n                                    &buf,\n                                    bincode::config::standard(),\n                                )\n                                .map(|((state, deps), consumed)| {\n                                    ((state.map(Rc::new), deps.map(Rc::new)), consumed)\n                                })\n                                .expect(\"failed to deserialize state\");\n\n                            data.set((Ok((state, deps)), None));\n                        });\n                    }\n\n                    PreparedStateBase {\n                        #[cfg(feature = \"ssr\")]\n                        state: None,","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/yewstack/yew/blob/0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3/packages/yew/src/functional/hooks/use_prepared_state/feat_hydration.rs#L73-L109","documentation":"With use_prepared_state, the server serializes state and embeds it base64-encoded in the HTML; during hydration the client rebuilds a data:application/octet-binary;base64,... URL, fetch()es it, and decodes the bytes (decode_base64 in feat_hydration.rs). This expect fires at that first step - the fetch/decode of the data URL fails. Since Yew itself generated the payload, a failure means the HTML was altered between SSR and hydration (attributes stripped, re-escaped, or truncated) or the environment blocks data: fetches.","triggerScenarios":"Hydrating HTML whose embedded base64 state attribute was mangled by a minifier or template engine that re-escapes attributes; a Content-Security-Policy that does not allow data: URLs for fetch; proxies or CDNs truncating very long attributes; cached SSR HTML that no longer matches the deployed client bundle.","commonSituations":"Post-processing SSR output (minify/sanitize steps) between server and client; strict CSP rollouts; edge caches serving stale pages across deploys; intermediaries rewriting data: URLs.","solutions":["View the served page source and confirm the attribute containing application/octet-binary;base64 is present and intact","Allow data: in the CSP directives governing fetch (e.g. connect-src data:) or restructure how state is transferred","Disable attribute minification/re-escaping in the HTML pipeline between SSR and hydration","Purge cached SSR HTML after each deploy so server output and client bundle always come from the same build"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before hydrate(), confirm the serialized state survived your HTML pipeline:\nlet html = gloo::utils::document()\n    .document_element()\n    .expect(\"no document element\")\n    .outer_html();\nassert!(\n    html.contains(\"application/octet-binary;base64\"),\n    \"prepared-state marker was stripped by HTML post-processing\"\n);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Allow data: URLs in the CSP fetch directives when using use_prepared_state","Do not minify or re-escape attributes of SSR output between server and client","Deploy SSR server and client bundle together and purge HTML caches on deploy"],"tags":["hydration","ssr","csp","base64","use-prepared-state"],"backgroundTag":"ssr-state-transfer-corrupted","analyzedSha":"0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3","analyzedAt":"2026-08-22T21:16:31.212Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}