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

Change Key of Parent Element Does Not Unmount Children #622

Closed
rmorshea opened this issue Jan 27, 2022 · 1 comment · Fixed by #623
Closed

Change Key of Parent Element Does Not Unmount Children #622

rmorshea opened this issue Jan 27, 2022 · 1 comment · Fixed by #623
Labels
priority-1-high Should be resolved ASAP. type-bug About something that isn't working

Comments

@rmorshea
Copy link
Collaborator

rmorshea commented Jan 27, 2022

Current Situation

Currently changing the key of a parent element does not cause the state of child components to get refreshed:

from idom import component, html, run, hooks
from random import random


@component
def Demo():
    h = hooks.current_hook()
    return html.div(
        html.button({"onClick": lambda event: h.schedule_render()}, "re-render"),
        HasState(),
        key=str(random()),
    )


@component
def HasState():
    state = hooks.use_state(random)[0]
    return html.p(state)


run(Demo)

Every time the button is clicked HasState should display a new random value because they key of its parent div is random, and thus its identity should always change. This does not happen though.

Only by placing the random key in HasState directly do we get the expected behavior.

Proposed Actions

Debug and fix.

Work Items

No response

@rmorshea rmorshea added type-bug About something that isn't working priority-1-high Should be resolved ASAP. labels Jan 27, 2022
@rmorshea
Copy link
Collaborator Author

cc: @Archmonger

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