Skip to content

Commit 583f733

Browse files
committed
Assert there are no circular references (#3025)
* assert there are no circular references the check is costly in release builds and should always fail note that the current PartialEq impl is *not* symmetric! should be fixed as well, with an improved design * remove internal test for cyclic node refs wasm_bindgen does not yet support #[should_panic] see also wasm-bindgen/wasm-bindgen#2286
1 parent f7eb0c2 commit 583f733

File tree

1 file changed

+4
-30
lines changed

1 file changed

+4
-30
lines changed

packages/yew/src/html/mod.rs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ mod feat_csr {
134134
/// Link a downstream `NodeRef`
135135
pub(crate) fn link(&self, node_ref: Self) {
136136
// Avoid circular references
137-
if self == &node_ref {
138-
return;
139-
}
137+
debug_assert!(
138+
self != &node_ref,
139+
"no circular references allowed! Report this as a bug in yew"
140+
);
140141

141142
let mut this = self.0.borrow_mut();
142143
this.node = None;
@@ -203,30 +204,3 @@ mod feat_hydration {
203204
pub fn create_portal(child: Html, host: Element) -> Html {
204205
VNode::VPortal(VPortal::new(child, host))
205206
}
206-
207-
#[cfg(target_arch = "wasm32")]
208-
#[cfg(test)]
209-
mod tests {
210-
use gloo::utils::document;
211-
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
212-
213-
use super::*;
214-
215-
wasm_bindgen_test_configure!(run_in_browser);
216-
217-
#[test]
218-
fn self_linking_node_ref() {
219-
let node: Node = document().create_text_node("test node").into();
220-
let node_ref = NodeRef::new(node.clone());
221-
let node_ref_2 = NodeRef::new(node.clone());
222-
223-
// Link to self
224-
node_ref.link(node_ref.clone());
225-
assert_eq!(node, node_ref.get().unwrap());
226-
227-
// Create cycle of two node refs
228-
node_ref.link(node_ref_2.clone());
229-
node_ref_2.link(node_ref);
230-
assert_eq!(node, node_ref_2.get().unwrap());
231-
}
232-
}

0 commit comments

Comments
 (0)