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

All child states wiped upon any child key change #652

Closed
Archmonger opened this issue Feb 7, 2022 · 1 comment · Fixed by #672
Closed

All child states wiped upon any child key change #652

Archmonger opened this issue Feb 7, 2022 · 1 comment · Fixed by #672
Labels
priority-1-high Should be resolved ASAP. type-bug About something that isn't working
Milestone

Comments

@Archmonger
Copy link
Contributor

Archmonger commented Feb 7, 2022

Current Situation

If two children obtain their key from a parent, both children's use_state are wiped if either child changes key.

from idom import component, html, run, hooks


@component
def Parent():
    state, set_state = hooks.use_state(1)
    return html.div(
        html.button({"onClick": lambda event: set_state(state + 1)}, "click me"),
        Child("key-0"),
        Child(f"key-{state}"),
    )


@component
def Child(child_key):
    state, set_state = hooks.use_state(0)

    @hooks.use_effect
    async def whatever():
        if state:
            return
        print(f"Child {child_key!r} has no state")
        set_state(1)

    return html.div(
        child_key,
        key=child_key,
    )


run(Parent)

Proposed Actions

Investigate and resolve this parent-child key abnormality

Work Items

See above

@Archmonger Archmonger added the flag-triage Not prioritized. label Feb 7, 2022
@Archmonger Archmonger changed the title All child states wiped upon any child mutation All child states wiped upon any child key change Feb 7, 2022
@rmorshea rmorshea added priority-1-high Should be resolved ASAP. type-bug About something that isn't working and removed flag-triage Not prioritized. labels Feb 7, 2022
@rmorshea rmorshea added this to the 1.0 milestone Feb 7, 2022
@rmorshea
Copy link
Collaborator

rmorshea commented Feb 9, 2022

I think this is related to #663

@rmorshea rmorshea mentioned this issue Feb 16, 2022
rmorshea added a commit that referenced this issue Feb 16, 2022
In short, because components do not have a node in the model state tree
managed by the layout, keys for elements in the components were being
registered to the parent of the component rather than to a node for
the component which contained the elements.

The short-term solution was to make it so components wrap their
contents in a div without a key. The long-term solution is to
refactor the Layout() and give components a dedicated node in the
model state tree
rmorshea added a commit that referenced this issue Feb 18, 2022
In short, because components do not have a node in the model state tree
managed by the layout, keys for elements in the components were being
registered to the parent of the component rather than to a node for
the component which contained the elements.

The short-term solution was to make it so components wrap their
contents in a div without a key. The long-term solution is to
refactor the Layout() and give components a dedicated node in the
model state tree
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.

2 participants