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

Bug in Element Key Identity #556

Closed
rmorshea opened this issue Dec 24, 2021 · 0 comments · Fixed by #563
Closed

Bug in Element Key Identity #556

rmorshea opened this issue Dec 24, 2021 · 0 comments · Fixed by #563
Labels
type-bug About something that isn't working

Comments

@rmorshea
Copy link
Collaborator

The following example is deeply flawed even when running with IDOM_FEATURE_INDEX_AS_DEFAULT_KEY=1:

from idom import component, html, run, use_state


@component
def Test():
    data, set_data = use_state(["one", "two", "three"])

    def make_handle_delete_click(index):
        def handle_click(event):
            set_data(data[:index] + data[index + 1 :])

        return handle_click

    return html.ul(
        [
            html.li(
                value,
                html.button({"onClick": make_handle_delete_click(index)}, "delete"),
                key=value,
            )
            for index, value in enumerate(data)
        ]
    )


run(Test)

Clicking the first delete button causes a client-side error:

index-6ddd8323.js:322 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'eventHandlers')
    at applyOperation (index-6ddd8323.js:322)
    at Object.applyPatch (index-6ddd8323.js:343)
    at applyNonMutativePatch (server-d63eddfd.js:48)
    at server-d63eddfd.js:32
    at server-d63eddfd.js:575

If you place the ul element inside a div even more strange behaviors occur regardless of which button is clicked.


Having investigated a bit it appears related to two different issues:

@rmorshea rmorshea added the type-bug About something that isn't working label Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug About something that isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant