File tree Expand file tree Collapse file tree 2 files changed +51
-5
lines changed Expand file tree Collapse file tree 2 files changed +51
-5
lines changed Original file line number Diff line number Diff line change @@ -355,11 +355,18 @@ def _render_model_children(
355355 else :
356356 if old_child_state .is_component_state :
357357 self ._unmount_model_states ([old_child_state ])
358- new_child_state = _update_element_model_state (
359- old_child_state ,
360- new_state ,
361- index ,
362- )
358+ new_child_state = _make_element_model_state (
359+ new_state ,
360+ index ,
361+ key ,
362+ )
363+ old_child_state = None
364+ else :
365+ new_child_state = _update_element_model_state (
366+ old_child_state ,
367+ new_state ,
368+ index ,
369+ )
363370 self ._render_model (old_child_state , new_child_state , child )
364371 new_children .append (new_child_state .model .current )
365372 new_state .children_by_key [key ] = new_child_state
Original file line number Diff line number Diff line change 88import pytest
99
1010import idom
11+ from idom import html
1112from idom .config import IDOM_DEBUG_MODE
1213from idom .core .dispatcher import render_json_patch
1314from idom .core .hooks import use_effect
@@ -838,3 +839,41 @@ def HasState():
838839 root_hook .latest .schedule_render ()
839840 await layout .render ()
840841 assert last_state != state .current
842+
843+
844+ async def test_switching_node_type_with_event_handlers ():
845+ toggle_type = idom .Ref ()
846+ element_static_handler = StaticEventHandler ()
847+ component_static_handler = StaticEventHandler ()
848+
849+ @idom .component
850+ def Root ():
851+ toggle , toggle_type .current = use_toggle (True )
852+ handler = element_static_handler .use (lambda : None )
853+ if toggle :
854+ return html .div (html .button ({"onEvent" : handler }))
855+ else :
856+ return html .div (SomeComponent ())
857+
858+ @idom .component
859+ def SomeComponent ():
860+ handler = component_static_handler .use (lambda : None )
861+ return html .button ({"onAnotherEvent" : handler })
862+
863+ with idom .Layout (Root ()) as layout :
864+ await layout .render ()
865+
866+ assert element_static_handler .target in layout ._event_handlers
867+ assert component_static_handler .target not in layout ._event_handlers
868+
869+ toggle_type .current ()
870+ await layout .render ()
871+
872+ assert element_static_handler .target not in layout ._event_handlers
873+ assert component_static_handler .target in layout ._event_handlers
874+
875+ toggle_type .current ()
876+ await layout .render ()
877+
878+ assert element_static_handler .target in layout ._event_handlers
879+ assert component_static_handler .target not in layout ._event_handlers
You can’t perform that action at this time.
0 commit comments