Open MinaMatta98 opened 1 year ago
Thanks for this very detailed report!
The issue almost certainly has to do with the way you are cloning and reusing the fragment, I agree.
I'd recommend trying two things:
1) Is it possible for this to be an RwSignal<Vec<(HtmlElement<Div>, i32)>>
instead? i.e., to simply drop the wrapping <></>
fragment around the <div>
you are using? If so, this would likely work correctly.
2) It's worth checking whether this is an issue that's been fixed between 0.3 and the current main release by updating from 0.3
to a dependency on git main.
Otherwise, a minimal reproduction that doesn't require a 10-15 minute build process, creating user accounts, etc. to set up will make it more likely I'll get to this sooner.
Ah, I see.
Is there a difference between the implementation of Fragment and other view elements at compile?
Yes. Fragments are backed by a regular web DocumentFragment
, which are somewhat tricky to work with. (Although honestly, all DOM elements are hard to deal with). Appending a DocumentFragment
to the DOM somewhere moves its children out, so we have to gather them back in if you unmount it and move them somewhere else. It's possible there's an edge case that's missed here somewhere, and the discrepancy between debug and release mode suggests that's the case, but it's also just true that fragments are trickier than regular elements.
Ok,
I have found a solution, but it points to an issue within the intricacies within the implementations of collect_view(cx).
A slight modification to the initial implementation has been introduced from:
{ move ||
input_signal.get().iter().map(|val| {
val.0
})
.collect_view(cx)}
to:
<For
each=move || input_signal.get()
key=|input| input.1
view=move |cx, item: (HtmlElement<Div>, i32)| {
view! {
cx,
{item.0}
}}/>
seems to have fixed the issue.
Here's a simpler reproduction, for my own purposes in addressing this one:
#[component]
fn App(cx: Scope) -> impl IntoView {
let count = create_rw_signal(cx, 0);
let frags = create_rw_signal(cx, vec![]);
view! { cx,
<button on:click=move |_| {
count.update(|n| *n += 1);
frags.update(|f| f.push((
view! { cx, <><span>{count.get()}</span></> },
count.get()
)));
}>"+1"</button>
<div>
{move || frags.get().iter().map(|val| {
val.0.clone() // <--- Here
}).collect_view(cx)}
</div>
}
}
Describe the bug Hello,
I am currently working on a demonstrative chatting client using leptos.
I have an RwSignal<Vec<(Fragment, i32)>> (Don't judge me), being updated via the following
And rendered here:
Leptos Dependencies
As requested:
To Reproduce Steps to reproduce the behavior:
docker build -t zing .
. This may take 10-15 minutes to build depending on your system.docker run -p 8000:8000 zing
Expected behavior The expected behavior is that within the first image (Dev build).
The unexpected behavior is that within the second image (release build).
Screenshots
![image](https://github.com/leptos-rs/leptos/assets/81748812/7c13a689-2e88-439b-ba39-3bdcc084debc)
Additional context The component is the
GroupChatModal
on line 1295 of the following link.If I fix this issue, I will post the fix.