Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map_keyed (and Keyed) does not update item if the key hasn't changed #717

Open
LHolten opened this issue Oct 12, 2024 · 0 comments
Open
Labels
A-reactivity Area: reactivity and state handling C-bug Category: bug, something isn't working

Comments

@LHolten
Copy link

LHolten commented Oct 12, 2024

Describe the bug
As the title says, the implementation of map_keyed assumes that if the new input has an item with the same key, then that item is only moved and not modified.
There don't seem to be any tests where the key function is not just the identify function.
So i think what likely happened is that the code was refactored and nobody noticed somehow?

To Reproduce
Steps to reproduce the behavior:

#[test]
fn update_keyed() {
    create_scope_immediate(|cx| {
        let a = create_signal(cx, vec![("a", 1), ("b", 2), ("c", 3)]);
        let mapped = map_keyed(cx, a, |_, x| x.1 * 2, |x| x.0);
        assert_eq!(*mapped.get(), vec![2, 4, 6]);

        a.set(vec![("a", 0), ("b", 0), ("c", 0)]);
        assert_eq!(*mapped.get(), vec![0, 0, 0]);
    });
}

This will give the error

assertion `left == right` failed
  left: [2, 4, 6]
 right: [0, 0, 0]

Expected behavior
The test passes

Environment

  • Sycamore: 0.8.2
@LHolten LHolten changed the title map_keyed (and Keyed) does not update items that have the same key map_keyed (and Keyed) does not update item if the key hasn't changed Oct 12, 2024
@lukechu10 lukechu10 added C-bug Category: bug, something isn't working A-reactivity Area: reactivity and state handling labels Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-reactivity Area: reactivity and state handling C-bug Category: bug, something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants