fix: suppress warnings caused by resource loading in generate_route_list (closes #582) (#621)

This commit is contained in:
Greg Johnston 2023-03-03 13:20:38 -05:00 committed by GitHub
parent bd86125629
commit 02e2948e00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 4 deletions

View file

@ -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

View file

@ -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<S, T> UnserializableResource for ResourceState<S, T> {
self
}
}
thread_local! {
static SUPPRESS_RESOURCE_LOAD: Cell<bool> = Cell::new(false);
}
#[doc(hidden)]
pub fn suppress_resource_load(suppress: bool) {
SUPPRESS_RESOURCE_LOAD.with(|w| w.set(suppress));
}

View file

@ -77,6 +77,12 @@ where
class: Option<AttributeValue>,
children: Children,
) -> HtmlElement<leptos::html::A> {
#[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,

View file

@ -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