From 02e2948e00d37333fc1614264b25634d47522bb6 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Fri, 3 Mar 2023 13:20:38 -0500 Subject: [PATCH] fix: suppress warnings caused by resource loading in `generate_route_list` (closes #582) (#621) --- leptos_dom/src/macro_helpers/into_class.rs | 2 -- leptos_reactive/src/resource.rs | 15 ++++++++++++++- router/src/components/link.rs | 6 ++++++ router/src/extract_routes.rs | 4 +++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/leptos_dom/src/macro_helpers/into_class.rs b/leptos_dom/src/macro_helpers/into_class.rs index a015bc544..7d76659ef 100644 --- a/leptos_dom/src/macro_helpers/into_class.rs +++ b/leptos_dom/src/macro_helpers/into_class.rs @@ -1,6 +1,4 @@ use leptos_reactive::Scope; -#[cfg(all(target_arch = "wasm32", feature = "web"))] -use wasm_bindgen::UnwrapThrowExt; /// Represents the different possible values a single class on an element could have, /// allowing you to do fine-grained updates to single items diff --git a/leptos_reactive/src/resource.rs b/leptos_reactive/src/resource.rs index 027066ef2..ca37cbb48 100644 --- a/leptos_reactive/src/resource.rs +++ b/leptos_reactive/src/resource.rs @@ -288,7 +288,11 @@ where S: PartialEq + Debug + Clone + 'static, T: 'static, { - r.load(false) + SUPPRESS_RESOURCE_LOAD.with(|s| { + if !s.get() { + r.load(false) + } + }); } #[cfg(feature = "hydrate")] @@ -741,3 +745,12 @@ impl UnserializableResource for ResourceState { self } } + +thread_local! { + static SUPPRESS_RESOURCE_LOAD: Cell = Cell::new(false); +} + +#[doc(hidden)] +pub fn suppress_resource_load(suppress: bool) { + SUPPRESS_RESOURCE_LOAD.with(|w| w.set(suppress)); +} diff --git a/router/src/components/link.rs b/router/src/components/link.rs index 50d49e2b3..645d62af2 100644 --- a/router/src/components/link.rs +++ b/router/src/components/link.rs @@ -77,6 +77,12 @@ where class: Option, children: Children, ) -> HtmlElement { + #[cfg(not(any(feature = "hydrate", feature = "csr")))] + _ = state; + + #[cfg(not(any(feature = "hydrate", feature = "csr")))] + _ = replace; + let location = use_location(cx); let is_active = create_memo(cx, move |_| match href.get() { None => false, diff --git a/router/src/extract_routes.rs b/router/src/extract_routes.rs index fa2783f99..79f0b613a 100644 --- a/router/src/extract_routes.rs +++ b/router/src/extract_routes.rs @@ -25,7 +25,9 @@ where let branches = PossibleBranchContext::default(); provide_context(cx, branches.clone()); - let _ = app_fn(cx).into_view(cx); + leptos::suppress_resource_load(true); + _ = app_fn(cx).into_view(cx); + leptos::suppress_resource_load(false); let branches = branches.0.borrow(); branches