yewstack/yew · error · syn::Error
byte-strings can't be converted to HTML text note: remove th
Error message
byte-strings can't be converted to HTML text note: remove the `b` prefix or convert this to a `String`
What it means
`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.
Source
Thrown at packages/yew-macro/src/html_tree/html_node.rs:23
use syn::spanned::Spanned;
use syn::{Expr, Lit};
use super::ToNodeIterator;
use crate::PeekValue;
use crate::stringify::Stringify;
pub enum HtmlNode {
Literal(Box<Lit>),
Expression(Box<Expr>),
}
impl Parse for HtmlNode {
fn parse(input: ParseStream) -> Result<Self> {
let node = if HtmlNode::peek(input.cursor()).is_some() {
let lit = input.parse()?;
match lit {
Lit::ByteStr(lit) => {
return Err(syn::Error::new(
lit.span(),
"byte-strings can't be converted to HTML text
note: remove the `b` prefix or convert this to a `String`",
));
}
Lit::Verbatim(lit) => {
return Err(syn::Error::new(lit.span(), "unsupported literal"));
}
_ => (),
}
HtmlNode::Literal(Box::new(lit))
} else {
HtmlNode::Expression(Box::new(input.parse()?))
};
Ok(node)
}
}View on GitHub (pinned to 0e4a05472f)
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
Example fix
// before
html! { <p>{ b"payload" }</p> }
// after
html! { <p>{ "payload" }</p> } Defensive patterns
Strategy: validation
Prevention
- 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
When it happens
Trigger: `html! { <p>{ b"raw bytes" }</p> }` — any byte-string literal used where an HTML child (text) is expected.
Common situations: 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.
Related errors
- unsupported literal
- string literals must not contain more than one class (hint:
- expected a valid closing tag for component note: found openi
- missing condition for `if` expression
- this `if` expression has a condition, but no block
AI-assisted analysis of yewstack/yew@0e4a05472f (2026-08-22).
Data as JSON: /api/errors/3589d161babab286.
Report an issue: GitHub.