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

'invalid SlotMap key used' when removing an item with nested reactivity from a list that has cleanup #739

Closed
lukechu10 opened this issue Oct 29, 2024 · 1 comment · Fixed by #742
Labels
A-reactivity Area: reactivity and state handling C-bug Category: bug, something isn't working P-high Priority: high
Milestone

Comments

@lukechu10
Copy link
Member

lukechu10 commented Oct 29, 2024

Reproducible example:

use sycamore::prelude::*;

fn main() {
    let _ = create_root(move || {
        let items = create_signal(vec![create_signal(()), create_signal(())]);

        map_indexed(items, |x| on_cleanup(move || x.dispose()));
        items.set(items.get_clone()[1..].to_vec());
    });
}

This is a pretty critical error since this is a common pattern for managing nested reactivity.

The error that appears is:

 panicked at /home/_/src/sycamore/packages/sycamore-reactive/src/root.rs:298:36:
invalid SlotMap key used
@lukechu10 lukechu10 added C-bug Category: bug, something isn't working A-reactivity Area: reactivity and state handling P-high Priority: high labels Oct 29, 2024
@lukechu10 lukechu10 added this to the v0.9 milestone Oct 29, 2024
@lukechu10
Copy link
Member Author

This turns out to actually be a super subtle bug where we accidentally track the nested signal inside of map_indexed/map_keyed because we perform a equality check between items which counts as a reactive access (i.e. the PartialEq implementation of Signal is reactive). This then tracks the nested signal as a dependency of the mapped memo. However, if the item is removed, it is disposed because of the on_cleanup and so we run into #741.

The solution would be to make sure that the update function of the memo only depends on the input list and nothing else.

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 P-high Priority: high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant