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
The numbers are arranged in the correct order (from 1 to 5) after being rendered, but the order in which each is rendered, reported by gloo_console::debug!, are reversed (from 5 to 1).
I currently maintain a file managing application that display files in a grid.
When a directory contains images, their thumbnails will be rendered as img elements, but in the aforementioned order.
Because the browser sees the last element first, it also downloads and displays image data from last to first.
Over a weak internet connection, this becomes really noticeable, which is undesirable.
Steps To Reproduce
Run the following code (with trunk).
Depending on the exact render-order of each item sounds like a not-so-good idea. I agree that it is unintuitive to see the specific components render in opposite order, but from a contract perspective, yew does so far not guarantee any order, they might also render "randomly" or not even in a consistent order. This has to do with the order in which we traverse the component tree and we might change it at any time, due to e.g. changing the format in which we render SSR and other details.
To give a potential solution to this problem: You might get away with add replacement images by first rendering a placeholder with inline data, such as (you can probably golf this a little and have better size constraints)
and then, after you initially rendered in an use_effect, replace the src with your actual image src but trigger it only when your image is actually on screen or close to being relevant. This should already noticably improve your UX. I suspect that in your use case, these effects might again trigger in an undesirable order for items that are initially on screen. Perhaps you can slightly delay setting the src and fix the order by collecting into a buffer in the use_effect and wasm_bindgen_futures::spawn_local` the part that drains this buffer (in your desired order) and sets the src.
Again, this sounds like a work-around, but as a framework we try to not commit to a specific render order. While unintuitive, the problem is not super straight-forward to answer in any case once you try to argue for post/pre/in-order or depth-first/breadth-first creation of component hierarchies (keep in mind that the creation of the actual DOM and the calls to the view function which returns virtual DOM might also not happen in the same order. As such, your debug statement in the component's view function does not necessarily capture the order in which the <img> elements are created).
Problem
The numbers are arranged in the correct order (from 1 to 5) after being rendered, but the order in which each is rendered, reported by
gloo_console::debug!
, are reversed (from 5 to 1).I currently maintain a file managing application that display files in a grid.
When a directory contains images, their thumbnails will be rendered as
img
elements, but in the aforementioned order.Because the browser sees the last element first, it also downloads and displays image data from last to first.
Over a weak internet connection, this becomes really noticeable, which is undesirable.
Steps To Reproduce
Run the following code (with
trunk
).Expected behavior
I expect the debug messages to appear in the same order as the numbers.
Screenshots
Taken from the browser web console (
Ctrl+Shift+K
).Environment:
yew = { version = "0.21.0", features = ["csr"] }
cargo 1.81.0-nightly (a1f47ec3f 2024-06-15)
wasm32-unknown-unknown
trunk
Linux 6.9.4-hardened1-1-hardened
Firefox 126.0.1
Questionnaire
The text was updated successfully, but these errors were encountered: