dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Memos can give out of date values

Open ealmloff opened this issue 2 years ago • 0 comments

Problem

You can read an out of date value from a memo if you update a dependency and then immediately read the memo

Steps To Reproduce

  1. Create a memo
  2. Update a state the memo depends on
  3. Read an out of date value from the memo
use dioxus::prelude::*;

fn main() {
    launch(app);
}

fn app() -> Element {
    let mut count = use_signal(|| 0);

    let mut signal = use_signal(|| 0);
    let memo = use_memo({
        to_owned![counter];
        move || {
            counter.borrow_mut().effect += 1;
            println!("Signal: {:?}", signal);
            signal()
        }
    });
    assert_eq!(memo(), 0);
    signal += 1;
    assert_eq!(memo(), 1);

    None
}

Expected behavior

Memos should always have up to date values

Screenshots

If applicable, add screenshots to help explain your problem.

Environment:

  • Dioxus version: master
  • Rust version: nightly
  • OS info: MacOS
  • App platform: hooks

Questionnaire

  • [ ] I'm interested in fixing this myself but don't know where to start
  • [ ] I would like to fix and I have a solution
  • [ ] I don't have time to fix this right now, but maybe later

ealmloff avatar Feb 14 '24 17:02 ealmloff