From 1afada528da8a66341075dbf3f892d8f7bd6fb42 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Fri, 2 Feb 2024 18:01:57 -0600 Subject: [PATCH] fix user server future --- packages/fullstack/src/hooks/server_future.rs | 7 +++++-- packages/fullstack/src/html_storage/mod.rs | 6 ++++-- packages/hooks/src/use_resource.rs | 7 ++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/fullstack/src/hooks/server_future.rs b/packages/fullstack/src/hooks/server_future.rs index 449f5002d..70d983a9b 100644 --- a/packages/fullstack/src/hooks/server_future.rs +++ b/packages/fullstack/src/hooks/server_future.rs @@ -18,8 +18,11 @@ where // We're doing this regardless so inputs get tracked, even if we drop the future before polling it let user_fut = cb.call(); + let currently_in_first_run = first_run.cloned(); + // If this is the first run and we are on the web client, the data might be cached - if *first_run.peek() { + if currently_in_first_run { + tracing::info!("First run of use_server_future"); // This is no longer the first run first_run.set(false); @@ -34,7 +37,7 @@ where // If this is the first run and we are on the server, cache the data #[cfg(feature = "ssr")] - if *first_run.peek() { + if currently_in_first_run { let _ = crate::server_context::server_context().push_html_data(&out); } diff --git a/packages/fullstack/src/html_storage/mod.rs b/packages/fullstack/src/html_storage/mod.rs index a6ae2ebe1..dfbfc5040 100644 --- a/packages/fullstack/src/html_storage/mod.rs +++ b/packages/fullstack/src/html_storage/mod.rs @@ -1,7 +1,8 @@ #![allow(unused)] - +use base64::Engine; use std::{io::Cursor, sync::atomic::AtomicUsize}; +use base64::engine::general_purpose::STANDARD; use serde::{de::DeserializeOwned, Serialize}; pub(crate) mod deserialize; @@ -45,8 +46,9 @@ impl HTMLDataCursor { return None; } let mut cursor = &self.data[current]; + let mut decoded = STANDARD.decode(cursor).unwrap(); self.index.fetch_add(1, std::sync::atomic::Ordering::SeqCst); - match ciborium::from_reader(Cursor::new(cursor)) { + match ciborium::from_reader(Cursor::new(decoded)) { Ok(x) => Some(x), Err(e) => { tracing::error!("Error deserializing data: {:?}", e); diff --git a/packages/hooks/src/use_resource.rs b/packages/hooks/src/use_resource.rs index c25aa947b..c0e871cc2 100644 --- a/packages/hooks/src/use_resource.rs +++ b/packages/hooks/src/use_resource.rs @@ -24,6 +24,7 @@ where let mut cb = use_callback(move || { // Create the user's task + #[allow(clippy::redundant_closure)] let fut = rc.run_in(|| future()); // Spawn a wrapper task that polls the innner future and watch its dependencies @@ -136,20 +137,20 @@ impl Resource { /// Reading this does not subscribe to the future's state pub fn finished(&self) -> bool { matches!( - self.state.peek().clone(), + *self.state.peek(), UseResourceState::Ready | UseResourceState::Stopped ) } /// Get the current state of the future. pub fn state(&self) -> ReadOnlySignal { - self.state.clone().into() + self.state.into() } /// Wait for this async memo to resolve, returning the inner signal value /// If the value is pending, returns none and suspends the current component pub fn suspend(&self) -> Option> { - let out = self.value.read().clone(); + let out = self.value.cloned(); if out.is_none() { suspend(); }