Skip to content

Fix Key Error When Cleaning Up Event Handlers #640

Closed

Description

@rmorshea

Discussed in #639

Originally posted by jkrobicki February 2, 2022
KeyError appers when I try to display components, however it works with version 0.34.0

image

Activity

  1. added
    priority-1-high
    on Feb 3, 2022
  2. added this to the 1.0 milestone on Feb 3, 2022
  3. rmorshea commented on Feb 3, 2022

    @rmorshea
    CollaboratorAuthor

    The following will reproduce the error:

    toggle_type = idom.Ref()
    element_static_handler = StaticEventHandler()
    component_static_handler = StaticEventHandler()
    
    @idom.component
    def Root():
        toggle, toggle_type.current = use_toggle(True)
        handler = element_static_handler.use(lambda: None)
        if toggle:
            return html.div(html.button({"onEvent": handler}))
        else:
            return html.div(SomeComponent())
    
    @idom.component
    def SomeComponent():
        handler = component_static_handler.use(lambda: None)
        return html.button({"onAnotherEvent": handler})
    
    with idom.Layout(Root()) as layout:
        await layout.render()
    
        assert element_static_handler.target in layout._event_handlers
        assert component_static_handler.target not in layout._event_handlers
    
        toggle_type.current()
        await layout.render()
    
        assert element_static_handler.target not in layout._event_handlers
        assert component_static_handler.target in layout._event_handlers
    
        toggle_type.current()
        await layout.render()
    
        assert element_static_handler.target in layout._event_handlers
        assert component_static_handler.target not in layout._event_handlers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-1-high

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions