@@ -361,7 +361,7 @@ def _render_model_children(
361361 [old_state .children_by_key [key ] for key in old_keys ]
362362 )
363363
364- new_children = new_state .model .current ["children" ] = []
364+ new_state .model .current ["children" ] = []
365365 for index , (child , child_type , key ) in enumerate (child_type_key_tuples ):
366366 old_child_state = old_state .children_by_key .get (key )
367367 if child_type is _DICT_TYPE :
@@ -388,7 +388,7 @@ def _render_model_children(
388388 index ,
389389 )
390390 self ._render_model (exit_stack , old_child_state , new_child_state , child )
391- new_children . append (new_child_state .model .current )
391+ new_state . append_child (new_child_state .model .current )
392392 new_state .children_by_key [key ] = new_child_state
393393 elif child_type is _COMPONENT_TYPE :
394394 child = cast (ComponentType , child )
@@ -428,7 +428,7 @@ def _render_model_children(
428428 old_child_state = old_state .children_by_key .get (key )
429429 if old_child_state is not None :
430430 self ._unmount_model_states ([old_child_state ])
431- new_children . append (child )
431+ new_state . append_child (child )
432432
433433 def _render_model_children_without_old_state (
434434 self ,
@@ -446,20 +446,20 @@ def _render_model_children_without_old_state(
446446 f"Duplicate keys { duplicate_keys } at { new_state .patch_path or '/' !r} "
447447 )
448448
449- new_children = new_state .model .current ["children" ] = []
449+ new_state .model .current ["children" ] = []
450450 for index , (child , child_type , key ) in enumerate (child_type_key_tuples ):
451451 if child_type is _DICT_TYPE :
452452 child_state = _make_element_model_state (new_state , index , key )
453453 self ._render_model (exit_stack , None , child_state , child )
454- new_children . append (child_state .model .current )
454+ new_state . append_child (child_state .model .current )
455455 new_state .children_by_key [key ] = child_state
456456 elif child_type is _COMPONENT_TYPE :
457457 child_state = _make_component_model_state (
458458 new_state , index , key , child , self ._rendering_queue .put
459459 )
460460 self ._render_component (exit_stack , None , child_state , child )
461461 else :
462- new_children . append (child )
462+ new_state . append_child (child )
463463
464464 def _unmount_model_states (self , old_states : List [_ModelState ]) -> None :
465465 to_unmount = old_states [::- 1 ] # unmount in reversed order of rendering
@@ -661,6 +661,9 @@ def parent(self) -> _ModelState:
661661 assert parent is not None , "detached model state"
662662 return parent
663663
664+ def append_child (self , child : Any ) -> None :
665+ self .model .current ["children" ].append (child )
666+
664667 def __repr__ (self ) -> str : # pragma: no cover
665668 return f"ModelState({ {s : getattr (self , s , None ) for s in self .__slots__ } } )"
666669
0 commit comments