From 6e40e0d7b9e051d4a2c3f2adf5e84c6f83b32710 Mon Sep 17 00:00:00 2001 From: brofrain Date: Fri, 8 Mar 2024 16:39:59 +0100 Subject: [PATCH] fix: index out of range in CSR example --- examples/csr/Cargo.lock | 23 +++++++++++++++++++++++ examples/csr/Cargo.toml | 3 +++ examples/csr/src/main.rs | 4 +++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/examples/csr/Cargo.lock b/examples/csr/Cargo.lock index 112aeed..75cdafa 100644 --- a/examples/csr/Cargo.lock +++ b/examples/csr/Cargo.lock @@ -190,6 +190,26 @@ dependencies = [ "toml", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + +[[package]] +name = "console_log" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be8aed40e4edbf4d3b4431ab260b63fdc40f5780a4766824329ea0f1eefe3c0f" +dependencies = [ + "log", + "web-sys", +] + [[package]] name = "const_format" version = "0.2.32" @@ -229,9 +249,12 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" name = "csr-example" version = "0.0.0" dependencies = [ + "console_error_panic_hook", + "console_log", "getrandom", "leptos", "leptos_animated_for", + "log", "rand", ] diff --git a/examples/csr/Cargo.toml b/examples/csr/Cargo.toml index 8c14bed..88681a0 100644 --- a/examples/csr/Cargo.toml +++ b/examples/csr/Cargo.toml @@ -4,7 +4,10 @@ version = "0.0.0" edition = "2021" [dependencies] +console_error_panic_hook = "0.1.7" +console_log = "1" getrandom = { version = "0.2.12", features = ["js"], optional = true } leptos = { version = "0.6.9", features = ["csr", "nightly"] } leptos_animated_for = { path = "../.." } +log = "0.4.20" rand = "0.8.5" diff --git a/examples/csr/src/main.rs b/examples/csr/src/main.rs index 47fc7c5..d3962a7 100644 --- a/examples/csr/src/main.rs +++ b/examples/csr/src/main.rs @@ -93,7 +93,7 @@ fn App() -> impl IntoView { items.update(|items| { let item = create_new_item(()); rng.update_value(|rng| { - items.insert(rng.gen_range(0..items.len()), item); + items.insert(rng.gen_range(0..=items.len()), item); }); }); }; @@ -156,5 +156,7 @@ fn App() -> impl IntoView { } fn main() { + _ = console_log::init_with_level(log::Level::Debug); + console_error_panic_hook::set_once(); mount_to_body(App); }