Skip to content

Commit 05de372

Browse files
committed
Preserve camelCase for all elements per worldsender's suggestion
1 parent ce06bb1 commit 05de372

4 files changed

Lines changed: 33 additions & 13 deletions

File tree

packages/yew-macro/src/html_tree/html_element.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -370,24 +370,20 @@ impl ToTokens for HtmlElement {
370370
tokens.extend(match &name {
371371
TagName::Lit(dashedname) => {
372372
let name_span = dashedname.span();
373-
let original_name = dashedname.to_string();
374-
let name = if is_normalised_element_name(&original_name) {
375-
// Preserve case for known SVG/special elements
376-
original_name
377-
} else {
378-
// Convert to lowercase for regular HTML elements
379-
dashedname.to_ascii_lowercase_string()
380-
};
373+
// Always preserve casing from the user's code
374+
let name = dashedname.to_string();
375+
let lowercase_name = dashedname.to_ascii_lowercase_string();
381376
if !is_normalised_element_name(&dashedname.to_string()) {
382377
emit_warning!(
383378
name_span.clone(),
384379
format!(
385-
"The tag '{dashedname}' is not matching its normalized form '{name}'. If you want \
380+
"The tag '{dashedname}' is not matching its normalized form '{lowercase_name}'. If you want \
386381
to keep this form, change this to a dynamic tag `@{{\"{dashedname}\"}}`."
387382
)
388383
)
389384
}
390-
let node = match &*name {
385+
// Use lowercase for compile-time checks but preserve original casing in output
386+
let node = match &*lowercase_name {
391387
"input" => {
392388
let value = value();
393389
let checked = checked();

packages/yew/src/virtual_dom/vtag.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,13 @@ impl VTag {
158158
/// Creates a new [VTag] instance with `tag` name (cannot be changed later in DOM).
159159
pub fn new(tag: impl Into<AttrValue>) -> Self {
160160
let tag = tag.into();
161+
let lowercase_tag = tag.to_ascii_lowercase();
161162
Self::new_base(
162-
match &*tag.to_ascii_lowercase() {
163+
match &*lowercase_tag {
163164
"input" => VTagInner::Input(Default::default()),
164165
"textarea" => VTagInner::Textarea(Default::default()),
165166
_ => VTagInner::Other {
166-
tag,
167+
tag, // Preserve the original casing
167168
children: Default::default(),
168169
},
169170
},
@@ -537,7 +538,9 @@ mod feat_ssr {
537538
let _ = w.write_str("</textarea>");
538539
}
539540
VTagInner::Other { tag, children } => {
540-
if !VOID_ELEMENTS.contains(&tag.as_ref()) {
541+
// Check if it's a void element using case-insensitive comparison
542+
let lowercase_tag = tag.to_ascii_lowercase();
543+
if !VOID_ELEMENTS.contains(&lowercase_tag.as_ref()) {
541544
children
542545
.render_into_stream(w, parent_scope, hydratable, tag.into())
543546
.await;

test_svg_casing

4.03 MB
Binary file not shown.

test_svg_casing.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use yew::prelude::*;
2+
3+
#[function_component]
4+
fn TestComponent() -> Html {
5+
html! {
6+
<svg>
7+
<defs>
8+
<filter id="glow">
9+
<feDropShadow dx="0" dy="0" stdDeviation="10" flood-color="red"/>
10+
<feGaussianBlur stdDeviation="2.5"/>
11+
<feColorMatrix type="matrix"/>
12+
</filter>
13+
</defs>
14+
<rect width="100" height="100" filter="url(#glow)" />
15+
</svg>
16+
}
17+
}
18+
19+
fn main() {
20+
println!("Test compiled successfully!");
21+
}

0 commit comments

Comments
 (0)