Compare commits

...

1 Commits
4326 ... 3013

Author SHA1 Message Date
Greg Johnston
557371887a fix: suppress resource loading during route generation (closes #3013) 2024-09-24 19:56:58 -04:00
2 changed files with 38 additions and 2 deletions

View File

@@ -24,7 +24,35 @@ use reactive_graph::{
prelude::*,
signal::{ArcRwSignal, RwSignal},
};
use std::{future::IntoFuture, ops::Deref, panic::Location};
use std::{
future::{pending, IntoFuture},
ops::Deref,
panic::Location,
sync::atomic::{AtomicBool, Ordering},
};
static IS_SUPPRESSING_RESOURCE_LOAD: AtomicBool = AtomicBool::new(false);
pub struct SuppressResourceLoad;
impl SuppressResourceLoad {
pub fn new() -> Self {
IS_SUPPRESSING_RESOURCE_LOAD.store(true, Ordering::Relaxed);
Self
}
}
impl Default for SuppressResourceLoad {
fn default() -> Self {
Self::new()
}
}
impl Drop for SuppressResourceLoad {
fn drop(&mut self) {
IS_SUPPRESSING_RESOURCE_LOAD.store(false, Ordering::Relaxed);
}
}
pub struct ArcResource<T, Ser = JsonSerdeCodec> {
ser: PhantomData<Ser>,
@@ -116,7 +144,14 @@ where
let source = source.clone();
move || {
let (_, source) = source.get();
fetcher(source)
let fut = fetcher(source);
async move {
if IS_SUPPRESSING_RESOURCE_LOAD.load(Ordering::Relaxed) {
pending().await
} else {
fut.await
}
}
}
};

View File

@@ -224,6 +224,7 @@ impl RouteList {
where
T: RenderHtml,
{
let _resource_guard = leptos::server::SuppressResourceLoad::new();
Self::IS_GENERATING.set(true);
// run the app once, but throw away the HTML
// the router won't actually route, but will fill the listing