fix attribute diffs causing infinite loops with test

This commit is contained in:
Ege Gungordu committed 2024-01-22 01:19:37 +03:00
1 parent 6111bdfdf0
commit 43fe17d9c5
2 files changed
+78 -63

No files matched your search

+20 -16
View File
@@ -145,25 +145,29 @@ impl<'b> VirtualDom {
(Some(left), Some(right)) => { (Some(left), Some(right)) => {
// check which name is greater // check which name is greater
match left.name.cmp(right.name) { match left.name.cmp(right.name) {
std::cmp::Ordering::Less => self.remove_attribute( std::cmp::Ordering::Less => {
left.name, self.remove_attribute(
left.namespace, left.name,
mounted_id, left.namespace,
), mounted_id,
std::cmp::Ordering::Greater => self.write_attribute( );
right_template, left_iter.next();
right, }
idx, std::cmp::Ordering::Greater => {
mounted_id, self.write_attribute(
), right_template,
right,
idx,
mounted_id,
);
right_iter.next();
}
std::cmp::Ordering::Equal => { std::cmp::Ordering::Equal => {
self.diff_attribute(left, right, mounted_id) self.diff_attribute(left, right, mounted_id);
left_iter.next();
right_iter.next();
} }
} }
// consume both
left_iter.next();
right_iter.next();
} }
(Some(_), None) => { (Some(_), None) => {
let left = left_iter.next().unwrap(); let left = left_iter.next().unwrap();
+58 -47
View File
@@ -88,21 +88,32 @@ fn attribute_diff() {
fn app(cx: Scope) -> Element { fn app(cx: Scope) -> Element {
let gen = cx.generation(); let gen = cx.generation();
let attrs = cx.bump().alloc(match gen % 2 { // attributes have to be sorted by name
0 => vec![Attribute::new( let attrs = match gen % 5 {
"attr1", 0 => cx.bump().alloc([Attribute::new(
"a",
AttributeValue::Text("hello"), AttributeValue::Text("hello"),
None, None,
false, false,
)], )]) as &[Attribute],
1 => vec![ 1 => cx.bump().alloc([
Attribute::new("attr1", AttributeValue::Text("hello"), None, false), Attribute::new("a", AttributeValue::Text("hello"), None, false),
Attribute::new("attr2", AttributeValue::Float(1.0), None, false), Attribute::new("b", AttributeValue::Text("hello"), None, false),
Attribute::new("attr3", AttributeValue::Int(1), None, false), Attribute::new("c", AttributeValue::Text("hello"), None, false),
Attribute::new("attr4", AttributeValue::Bool(true), None, false), ]) as &[Attribute],
], 2 => cx.bump().alloc([
Attribute::new("c", AttributeValue::Text("hello"), None, false),
Attribute::new("d", AttributeValue::Text("hello"), None, false),
Attribute::new("e", AttributeValue::Text("hello"), None, false),
]) as &[Attribute],
3 => cx.bump().alloc([Attribute::new(
"d",
AttributeValue::Text("world"),
None,
false,
)]) as &[Attribute],
_ => unreachable!(), _ => unreachable!(),
}); };
cx.render(rsx!( cx.render(rsx!(
div { div {
@@ -120,22 +131,16 @@ fn attribute_diff() {
vdom.render_immediate().santize().edits, vdom.render_immediate().santize().edits,
[ [
SetAttribute { SetAttribute {
name: "attr2", name: "b",
value: (&AttributeValue::Float(1.0)).into(), value: (&AttributeValue::Text("hello",)).into(),
id: ElementId(1), id: ElementId(1,),
ns: None ns: None,
}, },
SetAttribute { SetAttribute {
name: "attr3", name: "c",
value: (&AttributeValue::Int(1)).into(), value: (&AttributeValue::Text("hello",)).into(),
id: ElementId(1), id: ElementId(1,),
ns: None ns: None,
},
SetAttribute {
name: "attr4",
value: (&AttributeValue::Bool(true)).into(),
id: ElementId(1),
ns: None
}, },
] ]
); );
@@ -145,22 +150,28 @@ fn attribute_diff() {
vdom.render_immediate().santize().edits, vdom.render_immediate().santize().edits,
[ [
SetAttribute { SetAttribute {
name: "attr2", name: "a",
value: (&AttributeValue::None).into(), value: (&AttributeValue::None).into(),
id: ElementId(1), id: ElementId(1,),
ns: None ns: None,
}, },
SetAttribute { SetAttribute {
name: "attr3", name: "b",
value: (&AttributeValue::None).into(), value: (&AttributeValue::None).into(),
id: ElementId(1), id: ElementId(1,),
ns: None ns: None,
}, },
SetAttribute { SetAttribute {
name: "attr4", name: "d",
value: (&AttributeValue::None).into(), value: (&AttributeValue::Text("hello",)).into(),
id: ElementId(1), id: ElementId(1,),
ns: None ns: None,
},
SetAttribute {
name: "e",
value: (&AttributeValue::Text("hello",)).into(),
id: ElementId(1,),
ns: None,
}, },
] ]
); );
@@ -170,22 +181,22 @@ fn attribute_diff() {
vdom.render_immediate().santize().edits, vdom.render_immediate().santize().edits,
[ [
SetAttribute { SetAttribute {
name: "attr2", name: "c",
value: (&AttributeValue::Float(1.0)).into(), value: (&AttributeValue::None).into(),
id: ElementId(1), id: ElementId(1,),
ns: None ns: None,
}, },
SetAttribute { SetAttribute {
name: "attr3", name: "d",
value: (&AttributeValue::Int(1)).into(), value: (&AttributeValue::Text("world",)).into(),
id: ElementId(1), id: ElementId(1,),
ns: None ns: None,
}, },
SetAttribute { SetAttribute {
name: "attr4", name: "e",
value: (&AttributeValue::Bool(true)).into(), value: (&AttributeValue::None).into(),
id: ElementId(1), id: ElementId(1,),
ns: None ns: None,
}, },
] ]
); );