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
nodes inserted at position 0 have broken events #47
Comments
Thank you @vwpix for a very detailed report on the issue. We will be working on this. |
So, after some fiddling I realize that this is one of the case where the DOM diffing fails. This will be the behavior of the framework for now, while I haven't found a better way to solution. For now, you can use the work around to mark the element with let buttons = self
.nodes
.iter()
.map(|&x| {
button(
[
id(format!("btn_{}", x)),
replace(true),
on_click(move |_| Msg::ClickNode(x)),
],
[text(x)],
)
})
.collect::<Vec<_>>(); |
Also, I couldn't re-create the crash error: Hint: you can rewrite your view like this to make it cleaner. fn view(&self) -> Node<Msg> {
div(
[],
[
text(&self.last),
button(
[on_click(|_| Msg::InsertNode)],
[text("add item (broken)")],
),
button(
[on_click(|_| Msg::AddNode)],
[text("add item (working)")],
),
div(
[id("buttons")],
self.nodes.iter().map(|&x| {
button(
[
id(format!("btn_{}", x)),
replace(true),
on_click(move |_| Msg::ClickNode(x)),
],
[text(x)],
)
}),
),
],
)
} |
thank u for looking into it, and the workaround tip will be useful for now
the crash show up if i add the "key(x)" attribute to the generated buttons , tested in latest firefox nightly and chromium edit: |
After hours of hard-work revising and improving the diffing algorithm for keyed elements and tracking down the bug for the I created a repo for issues like this, which contain the actual code for the use-case. Thank you @vwpix again, for filing this issue, this has solved multiple long-standing bug in |
crate version where this is fixed:
|
the new closures created at view() don't get passed to the corresponding elements
instead, every new node acts like the original first node, or panic on keyed nodes
i made an example code for this problem, also a video preview to illustrate it better
video preview
only tested this for position 0 so im not sure about the rest
The text was updated successfully, but these errors were encountered: