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

Panic updating signal in 0.9.0-beta.2 #645

Open
Jan-V2 opened this issue Oct 22, 2023 · 0 comments
Open

Panic updating signal in 0.9.0-beta.2 #645

Jan-V2 opened this issue Oct 22, 2023 · 0 comments
Labels
A-reactivity Area: reactivity and state handling C-bug Category: bug, something isn't working S-needs-mre Needs a MRE (Minimal Reproducible Example)

Comments

@Jan-V2
Copy link

Jan-V2 commented Oct 22, 2023

Describe the bug
Updating a signal in the following component causes a panic, which it didn't before updating.

The panic is: panicked at 'invalid SlotMap key used', ../sycamore-reactive-0.9.0-beta.2/src/root.rs:323:9

#[component(inline_props)]
pub fn ArmyPlacementStart<G: Html>(
    ui_state: Signal<UiState>,
    ui_info: Signal<StartArmyPlacementInfo>,
) -> View<G> {
    let cause_crash = true;

    gloo::console::log!("running place start");
    create_effect(move || {
        let mut _ui_info = ui_info.get();
        if _ui_info.armies_per_player[_ui_info.current_player as usize] == 0 {
            if _ui_info.current_player + 1 < _ui_info.num_players {
                ui_info.set(ui_info.get().update(|s| {
                    s.current_player = s.current_player + 1;
                    s.is_done = false;
                    log!("updating current player");
                }));
            } else {
                log!("updating ui state");
                if cause_crash{
                    ui_state.set(UiState::GAME_END);  // <- this lines causes a panic
                }
            }
        }
    });

    view! {
            h1{"Player " (ui_info.get().current_player + 1 )}
            div{"You still have " (ui_info.get().armies_per_player[ui_info.get().current_player as usize])  " armies to place"}
    }
}

To Reproduce
the bug can be reproduced as follows:

  1. clone the repo at https://github.com/johnvanderholt/wasm_risk/tree/3b9ad6a8e9e20546b28173ef234cae8df4473e3a and run the code using sh run.sh
  2. select two players in the setup menu until you get to the army placement menu
  3. place armies, until the last player runs out, and the panic happens.

Expected behavior
The signal gets updated, and different view is loaded.

Environment

  • Sycamore: {version = "0.8.2", features = ["wasm-bindgen", "web", "web-sys", "sycamore-web"]}
  • Browser:Firefox
  • OS: Lubuntu (flavor of ubuntu)

Additional context
The signal gets updated elsewhere, and the view gets changed without issue.
This happens at ui/player_setup.rs:154
This also didn't happen before updating to the beta.
It also doesn't matter which view i switch to, i always get the same panic.

@lukechu10 lukechu10 added C-bug Category: bug, something isn't working A-reactivity Area: reactivity and state handling S-needs-mre Needs a MRE (Minimal Reproducible Example) labels Oct 23, 2023
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 S-needs-mre Needs a MRE (Minimal Reproducible Example)
Projects
None yet
Development

No branches or pull requests

2 participants