Skip to content

Mixed literal and dynamic classes emit duplicate class attributes #496

@eboody

Description

@eboody

Summary

When Maud renders markup that mixes a literal class shorthand with a dynamic class=(...) attribute on the same element, it accepts the syntax but emits duplicate class attributes instead of merging them.

Reproduction

use maud::html;

fn main() {
    let my_variable = "warning";

    let markup = html! {
        div.alert class=(my_variable) {}
    }
    .into_string();

    assert_eq!(markup, r#"<div class=\"alert warning\"></div>"#);
}

Actual output

<div class="alert" class="warning"></div>

Expected output

<div class="alert warning"></div>

Why this matters

Duplicate attributes are not a stable contract. In local verification, HTML5-style parsers kept the first class attribute and ignored the later one, so browser-effective behavior was usually equivalent to:

<div class="alert"></div>

That means the dynamic class can be silently lost even though the Maud syntax is accepted.

Notes

I verified two things locally:

  1. div.alert class=(my_variable) compiles successfully.
  2. Its rendered output is <div class="alert" class="warning"></div>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions