{"record":{"id":"3589d161babab286","repo":"yewstack/yew","slug":"byte-strings-can-t-be-converted-to-html-text-note","errorCode":null,"errorMessage":"byte-strings can't be converted to HTML text\nnote: remove the `b` prefix or convert this to a `String`","messagePattern":"byte-strings can't be converted to HTML text\nnote: remove the `b` prefix or convert this to a `String`","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"packages/yew-macro/src/html_tree/html_node.rs","lineNumber":23,"sourceCode":"use syn::spanned::Spanned;\nuse syn::{Expr, Lit};\n\nuse super::ToNodeIterator;\nuse crate::PeekValue;\nuse crate::stringify::Stringify;\n\npub enum HtmlNode {\n    Literal(Box<Lit>),\n    Expression(Box<Expr>),\n}\n\nimpl Parse for HtmlNode {\n    fn parse(input: ParseStream) -> Result<Self> {\n        let node = if HtmlNode::peek(input.cursor()).is_some() {\n            let lit = input.parse()?;\n            match lit {\n                Lit::ByteStr(lit) => {\n                    return Err(syn::Error::new(\n                        lit.span(),\n                        \"byte-strings can't be converted to HTML text\n                         note: remove the `b` prefix or convert this to a `String`\",\n                    ));\n                }\n                Lit::Verbatim(lit) => {\n                    return Err(syn::Error::new(lit.span(), \"unsupported literal\"));\n                }\n                _ => (),\n            }\n            HtmlNode::Literal(Box::new(lit))\n        } else {\n            HtmlNode::Expression(Box::new(input.parse()?))\n        };\n\n        Ok(node)\n    }\n}","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/yewstack/yew/blob/0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3/packages/yew-macro/src/html_tree/html_node.rs#L5-L41","documentation":"`HtmlNode::parse` accepts literals as HTML text children, but a byte-string literal (`b\"…\"`, of type `&[u8; N]`) has no text representation in the virtual DOM, so it is rejected at its span with instructions to drop the `b` prefix or convert to a `String` (html_node.rs:20-27). The check runs before any code generation.","triggerScenarios":"`html! { <p>{ b\"raw bytes\" }</p> }` — any byte-string literal used where an HTML child (text) is expected.","commonSituations":"Interfacing with binary protocols or embedded assets and pasting a `b\"…\"` sample into markup, or code near `include_bytes!` where a byte literal is mistaken for ordinary text.","solutions":["Remove the `b` prefix if the content is text: `{ \"payload\" }`","If it is truly binary, decode first: `String::from_utf8_lossy(&BYTES)` and interpolate the result","For non-UTF-8 data, render a placeholder (hex dump, byte count) computed in plain Rust"],"exampleFix":"// before\nhtml! { <p>{ b\"payload\" }</p> }\n\n// after\nhtml! { <p>{ \"payload\" }</p> }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["HTML children must be text-like: use ordinary `\"…\"` literals, numbers, or bools","Decode binary data with `String::from_utf8_lossy` before putting it in markup","Search templates for `b\"` before compiling when porting binary-adjacent code"],"tags":["rust","yew","html-macro","byte-string","literal","text-child"],"backgroundTag":"unsupported-literal-type","analyzedSha":"0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3","analyzedAt":"2026-08-22T21:16:31.212Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}