Skip to content

Add JSX/XML-like tag syntax to the rsx! macro - #5730

Open
nicoburns wants to merge 2 commits into
mainfrom
devin/1785758131-jsx-syntax
Open

Add JSX/XML-like tag syntax to the rsx! macro#5730
nicoburns wants to merge 2 commits into
mainfrom
devin/1785758131-jsx-syntax

Conversation

@nicoburns

Copy link
Copy Markdown
Member

Summary

Adds a JSX/XML-like tag syntax to rsx!, freely mixable with the existing block syntax (similar to dioxus-html-macro, but integrated into the one macro). A < token switches BodyNode::parse into tag mode:

rsx! {
    <div class="container" onclick={move |_| info!("clicked")}>
        <h1>"Hello, {name}!"</h1>
        <img src="image.png" />
        <MyComponent prop="value" {..props}>"children"</MyComponent>

        // both syntaxes mix freely in either direction
        p { class: "regular", "regular child" }
        for item in items {
            <span>"{item}"</span>
        }
    </div>
}

The new parser (packages/rsx/src/jsx.rs) produces the exact same Element/Component AST as the block syntax, so templates, hot-reloading, attribute merging, and diagnostics all behave identically. Element-vs-component tag names, string-literal text nodes, key, shorthand attributes (<div class>), custom/dashed attributes (data-foo="1", "custom-attr"="x"), web components (<my-widget />), component paths/generics (<some::Outlet<R>>), and {..spread} all follow the existing rsx rules. Attribute values must be literals or braced expressions (attr={expr}); closing tags must match the opening tag or a spanned error is emitted.

Supporting changes:

  • Element::from_parts / Component::from_parts extracted from the existing Parse impls so the tag parser can construct nodes with the same merge/validation logic (pure refactor).
  • PartialExpr::parse now also treats {expr} followed by < as a braced expression, so {children} directly before a closing tag parses correctly.
  • Tag bodies synthesize a Brace spanned to the open tag's > so brace-dependent consumers (completion hints, autofmt) treat the node as complete.

Notes/limitations:

  • Fragments (<>...</>) are rejected with a dedicated error (children can just be listed directly in rsx).
  • dx fmt (autofmt) will currently rewrite tag syntax into the canonical block syntax, since it prints from the shared AST. If tag syntax should instead be preserved by the formatter, that would be a follow-up in dioxus-autofmt.

Tests: parser unit tests in jsx.rs (elements, components, generics, web components, spreads, shorthand, mixing, error cases, codegen) plus end-to-end SSR rendering tests in packages/ssr/tests/jsx_syntax.rs.

Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/418cbef546c844b6b40c575b1ae28376
Requested by: @nicoburns

@nicoburns nicoburns self-assigned this Aug 3, 2026
@staging-devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant