2022-11-27 05:22:39 +00:00
|
|
|
//! dynamic attributes in dioxus necessitate an allocated node ID.
|
|
|
|
//!
|
|
|
|
//! This tests to ensure we clean it up
|
|
|
|
|
2024-01-16 01:14:11 +00:00
|
|
|
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
2022-11-27 05:22:39 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn attrs_cycle() {
|
2024-01-11 18:40:36 +00:00
|
|
|
let mut dom = VirtualDom::new(|| {
|
2024-01-11 01:21:15 +00:00
|
|
|
let id = generation();
|
2024-01-15 15:59:50 +00:00
|
|
|
match id % 2 {
|
2024-01-11 01:21:15 +00:00
|
|
|
0 => render! { div {} },
|
|
|
|
1 => render! {
|
|
|
|
div { h1 { class: "{id}", id: "{id}" } }
|
|
|
|
},
|
2022-11-27 05:22:39 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-01-11 17:11:44 +00:00
|
|
|
dom.rebuild_to_vec().santize().edits,
|
2022-11-27 05:22:39 +00:00
|
|
|
[
|
|
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1,) },
|
2022-12-03 00:24:49 +00:00
|
|
|
AppendChildren { m: 1, id: ElementId(0) },
|
2022-11-27 05:22:39 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2022-11-27 05:22:39 +00:00
|
|
|
assert_eq!(
|
2024-01-11 01:21:15 +00:00
|
|
|
dom.render_immediate_to_vec().santize().edits,
|
2022-11-27 05:22:39 +00:00
|
|
|
[
|
|
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2,) },
|
|
|
|
AssignId { path: &[0,], id: ElementId(3,) },
|
2024-01-11 18:40:36 +00:00
|
|
|
SetAttribute { name: "class", value: "1".into_value(), id: ElementId(3,), ns: None },
|
|
|
|
SetAttribute { name: "id", value: "1".into_value(), id: ElementId(3,), ns: None },
|
2022-11-27 05:22:39 +00:00
|
|
|
ReplaceWith { id: ElementId(1,), m: 1 },
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2022-11-27 05:25:35 +00:00
|
|
|
assert_eq!(
|
2024-01-11 01:21:15 +00:00
|
|
|
dom.render_immediate_to_vec().santize().edits,
|
2022-11-27 05:22:39 +00:00
|
|
|
[
|
2022-12-19 19:14:01 +00:00
|
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1) },
|
2022-11-27 05:25:35 +00:00
|
|
|
ReplaceWith { id: ElementId(2), m: 1 }
|
2022-11-27 05:22:39 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2022-11-27 05:22:39 +00:00
|
|
|
assert_eq!(
|
2024-01-11 01:21:15 +00:00
|
|
|
dom.render_immediate_to_vec().santize().edits,
|
2022-11-27 05:22:39 +00:00
|
|
|
[
|
|
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2) },
|
2022-12-19 19:14:01 +00:00
|
|
|
AssignId { path: &[0], id: ElementId(3) },
|
2022-12-23 22:10:05 +00:00
|
|
|
SetAttribute {
|
|
|
|
name: "class",
|
2024-01-11 21:18:11 +00:00
|
|
|
value: dioxus_core::AttributeValue::Text("3".to_string()),
|
2022-12-23 22:10:05 +00:00
|
|
|
id: ElementId(3),
|
|
|
|
ns: None
|
|
|
|
},
|
|
|
|
SetAttribute {
|
|
|
|
name: "id",
|
2024-01-11 21:18:11 +00:00
|
|
|
value: dioxus_core::AttributeValue::Text("3".to_string()),
|
2022-12-23 22:10:05 +00:00
|
|
|
id: ElementId(3),
|
|
|
|
ns: None
|
|
|
|
},
|
2022-12-19 19:14:01 +00:00
|
|
|
ReplaceWith { id: ElementId(1), m: 1 }
|
2022-11-27 05:22:39 +00:00
|
|
|
]
|
|
|
|
);
|
2022-11-27 05:25:35 +00:00
|
|
|
|
|
|
|
// we take the node taken by attributes since we reused it
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2022-11-27 05:25:35 +00:00
|
|
|
assert_eq!(
|
2024-01-11 01:21:15 +00:00
|
|
|
dom.render_immediate_to_vec().santize().edits,
|
2022-11-27 05:25:35 +00:00
|
|
|
[
|
|
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1) },
|
|
|
|
ReplaceWith { id: ElementId(2), m: 1 }
|
|
|
|
]
|
|
|
|
);
|
2022-11-27 05:22:39 +00:00
|
|
|
}
|