Skip to content

Commit

Permalink
silenced non-normalised element name warnings for SVG elements (#3769)
Browse files Browse the repository at this point in the history
  • Loading branch information
its-the-shrimp authored Dec 13, 2024
1 parent 6bec0ec commit 2362fad
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/yew-macro/src/derive_props/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub struct PropFieldCheck<'a> {
check_arg: GenericParam,
}

impl<'a> PropFieldCheck<'a> {
impl PropFieldCheck<'_> {
pub fn to_fake_prop_decl(&self) -> proc_macro2::TokenStream {
let Self { this, .. } = self;
if !this.is_required() {
Expand Down
43 changes: 41 additions & 2 deletions packages/yew-macro/src/html_tree/html_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,45 @@ use crate::props::{ElementProps, Prop, PropDirective};
use crate::stringify::{Stringify, Value};
use crate::{is_ide_completion, non_capitalized_ascii, Peek, PeekValue};

fn is_normalised_element_name(name: &str) -> bool {
match name {
"animateMotion"
| "animateTransform"
| "clipPath"
| "feBlend"
| "feColorMatrix"
| "feComponentTransfer"
| "feComposite"
| "feConvolveMatrix"
| "feDiffuseLighting"
| "feDisplacementMap"
| "feDistantLight"
| "feDropShadow"
| "feFlood"
| "feFuncA"
| "feFuncB"
| "feFuncG"
| "feFuncR"
| "feGaussianBlur"
| "feImage"
| "feMerge"
| "feMergeNode"
| "feMorphology"
| "feOffset"
| "fePointLight"
| "feSpecularLighting"
| "feSpotLight"
| "feTile"
| "feTurbulence"
| "foreignObject"
| "glyphRef"
| "linearGradient"
| "radialGradient"
| "textPath" => true,
_ => !name.chars().any(|c| c.is_ascii_uppercase()),
}
}

pub struct HtmlElement {
pub name: TagName,
pub props: ElementProps,
Expand Down Expand Up @@ -310,9 +349,9 @@ impl ToTokens for HtmlElement {
TagName::Lit(dashedname) => {
let name_span = dashedname.span();
let name = dashedname.to_ascii_lowercase_string();
if name != dashedname.to_string() {
if !is_normalised_element_name(&dashedname.to_string()) {
emit_warning!(
dashedname.span(),
name_span.clone(),
format!(
"The tag '{dashedname}' is not matching its normalized form '{name}'. If you want \
to keep this form, change this to a dynamic tag `@{{\"{dashedname}\"}}`."
Expand Down
2 changes: 1 addition & 1 deletion packages/yew-macro/tests/html_macro_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn dynamic_tags_catch_non_ascii() {
#[test]
fn html_nested_macro_on_html_element() {
let _node = html_nested! {
<div/>
<feBlend/>
};
let _node = html_nested! {
<input/>
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/dom_bundle/blist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct NodeWriter<'s> {
slot: DomSlot,
}

impl<'s> NodeWriter<'s> {
impl NodeWriter<'_> {
/// Write a new node that has no ancestor
fn add(self, node: VNode) -> (Self, BNode) {
test_log!("adding: {:?}", node);
Expand Down
1 change: 0 additions & 1 deletion packages/yew/src/dom_bundle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub(crate) struct Bundle(BNode);

impl Bundle {
/// Creates a new bundle.
pub const fn new() -> Self {
Self(BNode::List(BList::new()))
}
Expand Down

1 comment on commit 2362fad

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yew master branch benchmarks (Lower is better)

Benchmark suite Current: 2362fad Previous: 6bec0ec Ratio
yew-hooks-v0.21.0-keyed 01_run1k 191.3 201.6 0.95
yew-hooks-v0.21.0-keyed 02_replace1k 219.3 216.2 1.01
yew-hooks-v0.21.0-keyed 03_update10th1k_x16 103.6 97 1.07
yew-hooks-v0.21.0-keyed 04_select1k 48.2 44.9 1.07
yew-hooks-v0.21.0-keyed 05_swap1k 113.4 109.3 1.04
yew-hooks-v0.21.0-keyed 06_remove-one-1k 80.1 79.8 1.00
yew-hooks-v0.21.0-keyed 07_create10k 2158.1 2219.9 0.97
yew-hooks-v0.21.0-keyed 08_create1k-after1k_x2 219.5 220.4 1.00
yew-hooks-v0.21.0-keyed 09_clear1k_x8 96 99.3 0.97
yew-hooks-v0.21.0-keyed 21_ready-memory 2.1243391036987305 2.124758720397949 1.00
yew-hooks-v0.21.0-keyed 22_run-memory 6.3097944259643555 6.24371337890625 1.01
yew-hooks-v0.21.0-keyed 23_update5-memory 6.571384429931641 6.594074249267578 1.00
yew-hooks-v0.21.0-keyed 25_run-clear-memory 5.114053726196289 5.1737060546875 0.99
yew-hooks-v0.21.0-keyed 26_run-10k-memory 42.78852844238281 42.80021953582764 1.00
yew-hooks-v0.21.0-keyed 41_size-uncompressed 166.8 166.8 1
yew-hooks-v0.21.0-keyed 42_size-compressed 54.5 54.5 1
yew-hooks-v0.21.0-keyed 43_first-paint 450.5 438.6 1.03
yew-v0.21.0-keyed 01_run1k 191.6 204 0.94
yew-v0.21.0-keyed 02_replace1k 219.3 225.3 0.97
yew-v0.21.0-keyed 03_update10th1k_x16 85.2 88.7 0.96
yew-v0.21.0-keyed 04_select1k 27.8 28 0.99
yew-v0.21.0-keyed 05_swap1k 92.3 99 0.93
yew-v0.21.0-keyed 06_remove-one-1k 71.3 78.9 0.90
yew-v0.21.0-keyed 07_create10k 2164.9 2252.5 0.96
yew-v0.21.0-keyed 08_create1k-after1k_x2 216.1 228.2 0.95
yew-v0.21.0-keyed 09_clear1k_x8 94.5 94.7 1.00
yew-v0.21.0-keyed 21_ready-memory 2.1441469192504883 2.12838077545166 1.01
yew-v0.21.0-keyed 22_run-memory 6.219922065734863 6.245858192443848 1.00
yew-v0.21.0-keyed 23_update5-memory 6.323358535766602 6.322515487670898 1.00
yew-v0.21.0-keyed 25_run-clear-memory 4.889327049255371 4.963235855102539 0.99
yew-v0.21.0-keyed 26_run-10k-memory 41.570733070373535 41.536672592163086 1.00
yew-v0.21.0-keyed 41_size-uncompressed 164.4 164.4 1
yew-v0.21.0-keyed 42_size-compressed 54 54 1
yew-v0.21.0-keyed 43_first-paint 422.8 430.3 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.