Fix optional callback props implementation (#5225)
* fix optional event handler diffing * add regression test
This commit is contained in:
1 parent
f77a9162f5
commit
8eb4322de2
2 files changed
+30
-1
No files matched your search
@@ -215,3 +215,28 @@ fn cloning_read_signal_components_work() {
|
||||
}
|
||||
dom.render_immediate(&mut dioxus_core::NoOpMutations);
|
||||
}
|
||||
|
||||
// Regression test for https://github.com/DioxusLabs/dioxus/issues/5222
|
||||
#[tokio::test]
|
||||
async fn optional_event_handler_diff() {
|
||||
use dioxus_core::Properties;
|
||||
|
||||
#[derive(Props, Clone, PartialEq)]
|
||||
struct CompProps {
|
||||
callback: Option<Callback>,
|
||||
}
|
||||
|
||||
let dom = VirtualDom::new(|| rsx! {});
|
||||
|
||||
dom.in_scope(ScopeId::APP, || {
|
||||
// Diffing from None to Some should be different and copy the callback
|
||||
let mut props = CompProps::builder().callback(None).build();
|
||||
assert!(!props.memoize(&CompProps::builder().callback(|_| {}).build()));
|
||||
assert!(props.inner.callback.is_some());
|
||||
|
||||
// Diffing from Some to None should be different and remove the callback
|
||||
let mut props = CompProps::builder().callback(|_| {}).build();
|
||||
assert!(!props.memoize(&CompProps::builder().callback(None).build()));
|
||||
assert!(props.inner.callback.is_none());
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user