DioxusLabs/dioxus · error · syn::Error

Only string, int, float, and bool literals are supported

Error message

Only string, int, float, and bool literals are supported

What it means

HotLiteral is the literal type dioxus serializes for hot-reload template diffing (packages/rsx literal.rs). Only integer, float, string, and bool literals are supported; other syn literal kinds such as char ('a') or byte-string (b"...") literals are rejected by this parser.

Source

Thrown at packages/rsx/src/literal.rs:70

                quote! { dioxus_core::internal::HotReloadLiteral::Float(#f as _) }
            }
            HotLiteral::Int(f) => quote! { dioxus_core::internal::HotReloadLiteral::Int(#f as _) },
            HotLiteral::Bool(f) => quote! { dioxus_core::internal::HotReloadLiteral::Bool(#f) },
        }
    }
}

impl Parse for HotLiteral {
    fn parse(input: ParseStream) -> syn::Result<Self> {
        let raw = input.parse::<Lit>()?;

        let value = match raw.clone() {
            Lit::Int(a) => HotLiteral::Int(a),
            Lit::Bool(a) => HotLiteral::Bool(a),
            Lit::Float(a) => HotLiteral::Float(a),
            Lit::Str(a) => HotLiteral::Fmted(IfmtInput::new_litstr(a)?.into()),
            _ => {
                return Err(syn::Error::new(
                    raw.span(),
                    "Only string, int, float, and bool literals are supported",
                ));
            }
        };

        Ok(value)
    }
}

impl ToTokens for HotLiteral {
    fn to_tokens(&self, out: &mut proc_macro2::TokenStream) {
        match &self {
            HotLiteral::Fmted(f) => {
                f.formatted_input.to_tokens(out);
            }
            HotLiteral::Float(f) => f.to_tokens(out),
            HotLiteral::Int(f) => f.to_tokens(out),

View on GitHub (pinned to 393d190a80)

Solutions

  1. Replace the char/byte-string literal with a String, e.g. bind `let ch = String::from('x');` and use the variable
  2. Compute the value outside rsx and pass the variable as the attribute value
  3. If the literal must stay, do a full rebuild instead of relying on hot-reload for that template

Example fix

// before
rsx! { button { onclick: move |_| {}, '{x}' } }

// after
let label = String::from(x);
rsx! { button { onclick: move |_| {}, "{label}" } }
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Using a char literal like `label: 'x'` or a byte-string literal as an RSX attribute value or text child on a path where the HotLiteral parser must round-trip the value for hot-reload serialization.

Common situations: Typing 'x' instead of "x" for single-character text; porting keyboard/char values into templates; versions of dioxus tightening which literals hot-reload supports.

Related errors


AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16). Data as JSON: /api/errors/32bcfaa7afead28c. Report an issue: GitHub.