Skip to content

Commit 8b3b25e

Browse files
committed
refactor!: remove AttributeOrProperty::Static workaround for Rust <1.72
BREAKING CHANGE: removed the `Static` variant from the public `AttributeOrProperty` enum.
1 parent 04fbf56 commit 8b3b25e

3 files changed

Lines changed: 7 additions & 15 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ impl ToTokens for HtmlElement {
302302
::std::convert::Into::into(#v)
303303
))
304304
}
305-
None => quote!(::yew::virtual_dom::AttributeOrProperty::Static(
306-
#v
305+
None => quote!(::yew::virtual_dom::AttributeOrProperty::Attribute(
306+
::yew::virtual_dom::AttrValue::Static(#v)
307307
)),
308308
};
309309
kv.push(quote! { ( #k, #v) });

packages/yew/src/dom_bundle/btag/attributes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ impl Attributes {
173173
AttributeOrProperty::Attribute(value) => el
174174
.set_attribute(intern(key), value)
175175
.expect("invalid attribute key"),
176-
AttributeOrProperty::Static(value) => el
177-
.set_attribute(intern(key), value)
178-
.expect("invalid attribute key"),
179176
AttributeOrProperty::Property(value) => {
180177
let key = JsValue::from_str(key);
181178
js_sys::Reflect::set(el.as_ref(), &key, value).expect("could not set property");
@@ -185,7 +182,7 @@ impl Attributes {
185182

186183
fn remove(el: &Element, key: &str, old_value: &AttributeOrProperty) {
187184
match old_value {
188-
AttributeOrProperty::Attribute(_) | AttributeOrProperty::Static(_) => el
185+
AttributeOrProperty::Attribute(_) => el
189186
.remove_attribute(intern(key))
190187
.expect("could not remove attribute"),
191188
AttributeOrProperty::Property(_) => {
@@ -364,7 +361,10 @@ mod tests {
364361

365362
#[test]
366363
fn class_is_always_attrs() {
367-
let attrs = Attributes::Static(&[("class", AttributeOrProperty::Static("thing"))]);
364+
let attrs = Attributes::Static(&[(
365+
"class",
366+
AttributeOrProperty::Attribute(AttrValue::Static("thing")),
367+
)]);
368368

369369
let (element, btree) = create_element();
370370
attrs.apply(&btree, &element);

packages/yew/src/virtual_dom/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,6 @@ mod feat_ssr {
179179
#[expect(missing_docs)]
180180
#[derive(PartialEq, Clone, Debug)]
181181
pub enum AttributeOrProperty {
182-
// This exists as a workaround to support Rust <1.72
183-
// Previous versions of Rust did not See
184-
// `AttributeOrProperty::Attribute(AttrValue::Static(_))` as `'static` that html! macro
185-
// used, and thus failed with "temporary value dropped while borrowed"
186-
//
187-
// See: https://github.com/yewstack/yew/pull/3458#discussion_r1350362215
188-
Static(&'static str),
189182
Attribute(AttrValue),
190183
Property(JsValue),
191184
}
@@ -233,7 +226,6 @@ impl Attributes {
233226
Self::Static(arr) => Box::new(arr.iter().filter_map(|(k, v)| match v {
234227
AttributeOrProperty::Attribute(v) => Some((*k, v.as_ref())),
235228
AttributeOrProperty::Property(_) => None,
236-
AttributeOrProperty::Static(v) => Some((*k, v)),
237229
})),
238230
Self::Dynamic { keys, values } => {
239231
Box::new(keys.iter().zip(values.iter()).filter_map(|(k, v)| match v {

0 commit comments

Comments
 (0)