@@ -122,7 +122,7 @@ trait Mountable {
122
122
parent : Element ,
123
123
next_sibling : NodeRef ,
124
124
) -> Box < dyn Scoped > ;
125
- fn reuse ( self : Box < Self > , scope : & dyn Scoped , next_sibling : NodeRef ) ;
125
+ fn reuse ( self : Box < Self > , node_ref : NodeRef , scope : & dyn Scoped , next_sibling : NodeRef ) ;
126
126
}
127
127
128
128
struct PropsWrapper < COMP : Component > {
@@ -162,9 +162,13 @@ impl<COMP: Component> Mountable for PropsWrapper<COMP> {
162
162
Box :: new ( scope)
163
163
}
164
164
165
- fn reuse ( self : Box < Self > , scope : & dyn Scoped , next_sibling : NodeRef ) {
165
+ fn reuse ( self : Box < Self > , node_ref : NodeRef , scope : & dyn Scoped , next_sibling : NodeRef ) {
166
166
let scope: Scope < COMP > = scope. to_any ( ) . downcast ( ) ;
167
- scope. update ( ComponentUpdate :: Properties ( self . props , next_sibling) ) ;
167
+ scope. update ( ComponentUpdate :: Properties (
168
+ self . props ,
169
+ node_ref,
170
+ next_sibling,
171
+ ) ) ;
168
172
}
169
173
}
170
174
@@ -186,9 +190,9 @@ impl VDiff for VComp {
186
190
if let VNode :: VComp ( ref mut vcomp) = & mut ancestor {
187
191
// If the ancestor is the same type, reuse it and update its properties
188
192
if self . type_id == vcomp. type_id && self . key == vcomp. key {
189
- self . node_ref . link ( vcomp. node_ref . clone ( ) ) ;
193
+ self . node_ref . reuse ( vcomp. node_ref . clone ( ) ) ;
190
194
let scope = vcomp. scope . take ( ) . expect ( "VComp is not mounted" ) ;
191
- mountable. reuse ( scope. borrow ( ) , next_sibling) ;
195
+ mountable. reuse ( self . node_ref . clone ( ) , scope. borrow ( ) , next_sibling) ;
192
196
self . scope = Some ( scope) ;
193
197
return vcomp. node_ref . clone ( ) ;
194
198
}
@@ -311,14 +315,35 @@ mod tests {
311
315
}
312
316
313
317
fn change ( & mut self , _: Self :: Properties ) -> ShouldRender {
314
- unimplemented ! ( ) ;
318
+ true
315
319
}
316
320
317
321
fn view ( & self ) -> Html {
318
322
unimplemented ! ( ) ;
319
323
}
320
324
}
321
325
326
+ #[ test]
327
+ fn update_loop ( ) {
328
+ let document = crate :: utils:: document ( ) ;
329
+ let parent_scope: AnyScope = crate :: html:: Scope :: < Comp > :: new ( None ) . into ( ) ;
330
+ let parent_element = document. create_element ( "div" ) . unwrap ( ) ;
331
+
332
+ let mut ancestor = html ! { <Comp ></Comp > } ;
333
+ ancestor. apply ( & parent_scope, & parent_element, NodeRef :: default ( ) , None ) ;
334
+
335
+ for _ in 0 ..10000 {
336
+ let mut node = html ! { <Comp ></Comp > } ;
337
+ node. apply (
338
+ & parent_scope,
339
+ & parent_element,
340
+ NodeRef :: default ( ) ,
341
+ Some ( ancestor) ,
342
+ ) ;
343
+ ancestor = node;
344
+ }
345
+ }
346
+
322
347
#[ test]
323
348
fn set_properties_to_component ( ) {
324
349
html ! {
0 commit comments