lucasmerlin / hello_egui

A collection of useful crates for egui
https://lucasmerlin.github.io/hello_egui/
MIT License
272 stars 24 forks source link

Infinite Scroll elements only show once on some platforms #26

Closed mdegans closed 2 months ago

mdegans commented 3 months ago

On Microsoft Edge (macOS), Chrome (macOS) as well as macOS native. instances of InfiniteScroll only show up the first time the executable is run. To repro, my website is here and the commit to repro here.

The first time the site is run, the infinite scroll elements display:

Screenshot 2024-06-04 at 2 41 16 PM

After a refresh, the area where they should be shows as blank:

Screenshot 2024-06-04 at 2 41 38 PM

Clearing the site cookies resolves the issue once, but after a refresh, the widgets are gone again. This happens on native as well (at least macOS).

To aid in debugging and to point you to where the elements are used in my source, egui settings are available under the right navbar.

Screenshot 2024-06-04 at 2 45 04 PM

I'll investigate this myself but would appreciate input if the cause is known or if I'm "holding it wrong".

mdegans commented 3 months ago

Turning off persistence solved this. Not really a fix, but for me it's fine since nothing needs to persist.

lucasmerlin commented 2 months ago

Hmm, I guess the size of some widgets get's persisted by egui in a weird state, I had something like this before, where the size of some widget was nan in egui's persistent memory and only resetting memory would bring it back. Not sure if this is something caused directly by infinite scroll. But I never tried using the infinite scroll with collapsible headers, I'll try and see if that breaks something.

mdegans commented 2 months ago

That would make sense. I just investigated the .ron with a commit just before I disabled persistance. There's almost no app state, which is why I disabled it. The elements that are broken aren't serialized. By deleting keys, I found the line that was causing the problem:

{
...
    "app": "(navbar:(expanded:false,selected_tab:Info,state:{}),central:())",
...

No NAN/Infinity, but somehow that breaks it. If I delete that and everything defaults, it works. And now that I check, I have derived Default (on the Gallery), which skips the new which loads the actual data. But If i delete Panel, this implementation of Default is used which loads the data correctly:

impl Default for Panel {
    fn default() -> Self {
        Self {
            commonmark_cache: Default::default(),
            gallery: Gallery::new(include_str!("../../assets/gallery.json")),
            doggos: Gallery::new(include_str!("../../assets/doggos.json")),
            blog: Blog::new(),
        }
    }
}

So, this is on me. I could fix this by just removing serde from the parent Panel and then Default gets called every time. Closing as the issue is not with your library.