DioxusLabs/dioxus · error · syn::Error
unmatched closing '}' in format string
Error message
unmatched closing '}' in format string
What it means
Error from dioxus's inline format string parser (ifmt) used for formatted text like `div { "Hello {name}" }`. Inside RSX string literals `{` starts and `}` ends an interpolation; a lone `}` in the literal portion is invalid and must be doubled (`}}`), exactly like Rust std format strings.
Source
Thrown at packages/rsx/src/ifmt.rs:197
}
break;
}
if c == '}' {
segments.push(Segment::Formatted(FormattedSegment {
format_args: String::new(),
segment: FormattedSegmentType::parse(¤t_captured)?,
}));
break;
}
current_captured.push(c);
}
} else {
if '}' == c {
if let Some(c) = chars.next_if(|c| *c == '}') {
current_literal.push(c);
continue;
} else {
return Err(Error::new(
Span::call_site(),
"unmatched closing '}' in format string",
));
}
}
current_literal.push(c);
}
}
if !current_literal.is_empty() {
segments.push(Segment::Literal(current_literal));
}
Ok(segments)
}
}
impl ToTokens for IfmtInput {View on GitHub (pinned to 393d190a80)
Solutions
- Escape the brace: replace the literal `}` with `}}` (and `{` with `{{`) inside the string
- Move brace-heavy text into a variable outside rsx and interpolate it: `"{css_text}"`
Example fix
// before
rsx! { p { "json { value: 1 }" } }
// after
rsx! { p { "json {{ value: 1 }}" } } Defensive patterns
Strategy: validation
Prevention
- Treat RSX string literals like format! strings: always write literal braces as {{ and }}
- Run cargo check after editing templates with braces (CSS, JSON) to catch escaping early
- Keep brace-heavy static text in constants outside rsx and interpolate them
When it happens
Trigger: A single `}` appearing in the literal part of an RSX formatted string, e.g. `div { "list: {items}" }` mis-typed as `div { "} items" }`, or CSS/JSON snippets like `"body { color: red }"` where the closing brace is not escaped as `}}`.
Common situations: Rendering CSS fragments, JSON, or code samples containing braces; un-escaping a format! string when moving it into rsx; hand-editing templates after hot-reload iterations.
Related errors
- Failed to parse formatted segment: Expected Ident or Express
- Only string, int, float, and bool literals are supported
- Catch all segments are not allowed in nests
- 1 issue found.
- Use `api_route` instead of `route` to use OpenAPI options
AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16).
Data as JSON: /api/errors/25c4cc2834123f18.
Report an issue: GitHub.