Skip to content

Change Key of Parent Element Does Not Unmount Children #622

Closed

Description

@rmorshea

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

Activity

  1. added
    priority-1-high
    on Jan 27, 2022
  2. rmorshea commented on Jan 27, 2022

    @rmorshea
    CollaboratorAuthor
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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions