@@ -50,7 +50,7 @@ impl<'p> DomContext<'p> {
50
50
container
51
51
. insert_before ( & new_child, reference_sibling)
52
52
. unwrap_throw ( ) ;
53
- group. insert ( position, new_child) ;
53
+ panic_if_duplicate_node ( group. insert ( position, new_child) ) ;
54
54
}
55
55
DomContext :: Sibling {
56
56
parent,
@@ -67,7 +67,7 @@ impl<'p> DomContext<'p> {
67
67
. get_containing_node ( )
68
68
. insert_before ( & new_child, Some ( reference_sibling) )
69
69
. unwrap_throw ( ) ;
70
- group. insert ( position, new_child) ;
70
+ panic_if_duplicate_node ( group. insert ( position, new_child) ) ;
71
71
}
72
72
DomContext :: Child { parent, index } => {
73
73
position. wrap ( * index) ;
@@ -117,3 +117,22 @@ fn remove_children_here(
117
117
}
118
118
}
119
119
}
120
+
121
+ #[ cfg( debug_assertions) ]
122
+ fn panic_if_duplicate_node ( node : Option < web_sys:: Node > ) {
123
+ if let Some ( node) = node {
124
+ web_sys:: console:: error_2 (
125
+ & "Attempted to insert two nodes at the same position.\n \
126
+ You probably either used a `join` implementation from outside Async UI,\
127
+ or tried to render something in a spawned Future.\n \
128
+ This message is only shown in debug builds.\n \
129
+ Check the code where you render this node:\
130
+ "
131
+ . into ( ) ,
132
+ node. as_ref ( ) ,
133
+ ) ;
134
+ panic ! ( )
135
+ }
136
+ }
137
+ #[ cfg( not( debug_assertions) ) ]
138
+ fn panic_duplicate_node ( _node : Option < web_sys:: Node > ) { }
0 commit comments