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(&current_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

  1. Escape the brace: replace the literal `}` with `}}` (and `{` with `{{`) inside the string
  2. 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

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


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