You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Nested for-loops in RSX seem to render in an incorrect order 🤔 This was initially found by @DogeDark on dioxus-web, and I was able to reproduce and simplify the example on dioxus-desktop. Freya however doesn't seem to be affected, so this seems like a post-v0.6 bug.
Looking at the implementation, the for-loop is converted to an iterator of VNodes. My hunch is having the outer iterator call the inner one is leading to the ordering bug but the logic looks correct to me.
If you add many lists to the first render, they render correctly:
use dioxus::prelude::*;#[component]fnApp() -> Element{letmut data = use_signal(|| {(0..100).step_by(10).map(|i| (i..i + 10).collect::<Vec<_>>()).collect::<Vec<_>>()});letmut load_more = move || {letmut new_row = Vec::new();let last = {let binding = data.last().unwrap();*binding.last().unwrap()};for i in1..11{
new_row.push(last + i);}
data.push(new_row);};rsx!{
button {
onclick: move |_| load_more(),
"load more",
}
div {
style: "display: grid; grid-template-columns: repeat(10, auto);",
for(i, row) in data.iter().enumerate(){for column in row.iter(){
div{"{column}"}}}}}}fnmain(){launch(App)}
Diouxs SSR doesn't use core diffing and it also renders the lists correctly. I think this is a bug with keyed list diffing (here). If it was a bug with rsx, then the initial list would render incorrectly as well
ealmloff
added
core
relating to the core implementation of the virtualdom
and removed
rsx
Related to rsx or the dioxus-rsx crate
labels
Oct 2, 2024
Problem
Nested for-loops in RSX seem to render in an incorrect order 🤔 This was initially found by @DogeDark on
dioxus-web
, and I was able to reproduce and simplify the example ondioxus-desktop
. Freya however doesn't seem to be affected, so this seems like a post-v0.6 bug.Looking at the implementation, the for-loop is converted to an iterator of
VNode
s. My hunch is having the outer iterator call the inner one is leading to the ordering bug but the logic looks correct to me.https://github.com/DioxusLabs/dioxus/blob/c2b131f249cc757716ca2c4d917cc9b8db98aa08/packages/rsx/src/forloop.rs#L52C31-L52C32
Steps To Reproduce
Expected behavior
Separating the above nested loops with a temporary variable results in the following correct output:
Screenshots
However with the nested loop:
Environment:
Questionnaire
The text was updated successfully, but these errors were encountered: