Fix additional attributes for js renderers (#3625)

This commit is contained in:
Evan Almloff authored and GitHub committed 2025-01-31 14:31:31 -08:00
1 parent 67515ce812
commit 2d188452ae
10 files changed
+125 -1

No files matched your search

+1
View File
@@ -28,6 +28,7 @@ impl LinkProps {
/// Get all the attributes for the link tag
pub fn attributes(&self) -> Vec<(&'static str, String)> {
let mut attributes = Vec::new();
extend_attributes(&mut attributes, &self.additional_attributes);
if let Some(rel) = &self.rel {
attributes.push(("rel", rel.clone()));
}
+1
View File
@@ -19,6 +19,7 @@ impl MetaProps {
/// Get all the attributes for the meta tag
pub fn attributes(&self) -> Vec<(&'static str, String)> {
let mut attributes = Vec::new();
extend_attributes(&mut attributes, &self.additional_attributes);
if let Some(property) = &self.property {
attributes.push(("property", property.clone()));
}
+23
View File
@@ -124,3 +124,26 @@ impl DeduplicationContext {
}
}
}
/// Extend a list of string attributes with a list of dioxus attribute
pub(crate) fn extend_attributes(
attributes: &mut Vec<(&'static str, String)>,
additional_attributes: &[Attribute],
) {
for additional_attribute in additional_attributes {
let attribute_value_as_string = match &additional_attribute.value {
dioxus_core::AttributeValue::Text(v) => v.to_string(),
dioxus_core::AttributeValue::Float(v) => v.to_string(),
dioxus_core::AttributeValue::Int(v) => v.to_string(),
dioxus_core::AttributeValue::Bool(v) => v.to_string(),
dioxus_core::AttributeValue::Listener(_) | dioxus_core::AttributeValue::Any(_) => {
tracing::error!("document::* elements do not support event listeners or any value attributes. Expected displayable attribute, found {:?}", additional_attribute.value);
continue;
}
dioxus_core::AttributeValue::None => {
continue;
}
};
attributes.push((additional_attribute.name, attribute_value_as_string));
}
}
+1
View File
@@ -25,6 +25,7 @@ impl ScriptProps {
/// Get all the attributes for the script tag
pub fn attributes(&self) -> Vec<(&'static str, String)> {
let mut attributes = Vec::new();
extend_attributes(&mut attributes, &self.additional_attributes);
if let Some(defer) = &self.defer {
attributes.push(("defer", defer.to_string()));
}
+1
View File
@@ -20,6 +20,7 @@ impl StyleProps {
/// Get all the attributes for the style tag
pub fn attributes(&self) -> Vec<(&'static str, String)> {
let mut attributes = Vec::new();
extend_attributes(&mut attributes, &self.additional_attributes);
if let Some(href) = &self.href {
attributes.push(("href", href.clone()));
}