We are not appropriately updating the location of a given component within the overall VDOM when it changes position. This particular line is at fault - it just blindly copies the path from the old model instead of recomputing that path given the new parent and index (f"{new_parent.patch_path}/children/{new_index}").
Discussed in #1081
Originally posted by numpde July 2, 2023
I'm confused about what's happening here. Consider this App:
fromreactpyimportcomponent, use_statefromreactpy.htmlimportdiv, buttonfromreactpy.core.typesimportState@componentdefItem(item: str, items: State):
color=use_state(None)
defdeleteme(event):
items.set_value(lambdaitems: [iforiinitemsif (i!=item)])
defcolorize(event):
color.set_value(lambdac: "blue"ifnotcelseNone)
returndiv(
{'style': {'background-color': color.valueor"transparent", 'padding': "5px"}},
div(
button({'onClick': colorize}, f"Color {item}"),
button({'onClick': deleteme}, f"Delete {item}"),
),
)
@componentdefApp():
items=use_state(["A", "B", "C"])
returndiv(
[
Item(item, items, key=item)
foriteminitems.value
]
)I embed it from a Django template. Here's the equivalent ReactJS implementation for reference.
Now, when I delete Item A then click to color Item B, then unexpectedly, Item C appears overwritten.
reactpy==1.0.1
reactpy-django==3.2.0
We are not appropriately updating the location of a given component within the overall VDOM when it changes position. This particular line is at fault - it just blindly copies the path from the old model instead of recomputing that path given the new parent and index (
f"{new_parent.patch_path}/children/{new_index}").Discussed in #1081
Originally posted by numpde July 2, 2023
I'm confused about what's happening here. Consider this App:
I embed it from a Django template. Here's the equivalent ReactJS implementation for reference.
Now, when I delete Item A then click to color Item B, then unexpectedly, Item C appears overwritten.
reactpy==1.0.1
reactpy-django==3.2.0