Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Key Error When Cleaning Up Event Handlers #640

Closed
rmorshea opened this issue Feb 3, 2022 Discussed in #639 · 1 comment · Fixed by #641
Closed

Fix Key Error When Cleaning Up Event Handlers #640

rmorshea opened this issue Feb 3, 2022 Discussed in #639 · 1 comment · Fixed by #641
Labels
priority-1-high Should be resolved ASAP. type-bug About something that isn't working
Milestone

Comments

@rmorshea
Copy link
Collaborator

rmorshea commented Feb 3, 2022

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

@rmorshea rmorshea added type-bug About something that isn't working priority-1-high Should be resolved ASAP. labels Feb 3, 2022
@rmorshea rmorshea added this to the 1.0 milestone Feb 3, 2022
@rmorshea
Copy link
Collaborator Author

rmorshea commented Feb 3, 2022

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
Labels
priority-1-high Should be resolved ASAP. type-bug About something that isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant