Coder Social home page Coder Social logo

Comments (2)

gbj avatar gbj commented on July 30, 2024

Steps I took to debug:

  1. Saw that this was a keyed list, and that the issue was solved by fixing the keys. Wondered whether there could be duplicated keys.
  2. In <BadTable/>, I added an effect to log out the keys:
    create_effect(move |_| {
        leptos::logging::log!(
            "{:?}",
            rows().into_iter().map(|tuple| tuple.0).collect::<Vec<_>>()
        );
    });
  1. Saw that this logs twice when I resize. This is because you update two separate signals in the event handler, and read from both of those signals in the let rows definition. In Leptos 0.6 and earlier, signal updates/effects are not batched by default but run synchronously — so the rows are basically updated twice when you click, one for each signal they depend on. Note that rows reads from the grid signal, but the keys don't depend on the grid signal (unlike in GoodTable), so an "old" row sticks around.
  2. I added batch(move || { ... }) inside the resize function:
    let resize = move |dim: Dimensions| {
        batch(move || {
            set_dimensions.update(|dimensions| *dimensions = dim); // this can be .set() btw
            let mut new_vec = vec![];
            for _ in 0..dimensions.with(|d| d.width * d.height) {
                new_vec.push(create_signal(Cell { example: false }));
            }
            set_grid.update(|grid| *grid = new_vec); // this can be .set() btw
        });
    };

Works as expected.


Broader point: There's no reason to use <For/> here, as you are invalidating every key on every dimension change anyway, so all of them will be replaced when the dimensions change. If you use plain iteration it will perform exactly the same and you won't have the key or batching issue.

from leptos.

Neighborkid01 avatar Neighborkid01 commented on July 30, 2024

Thanks so much!

from leptos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.