瀏覽代碼

fix user server future

Evan Almloff 1 年之前
父節點
當前提交
1afada528d

+ 5 - 2
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);
             }
 

+ 4 - 2
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);

+ 4 - 3
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<T> Resource<T> {
     /// 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<UseResourceState> {
-        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<ReadOnlySignal<T>> {
-        let out = self.value.read().clone();
+        let out = self.value.cloned();
         if out.is_none() {
             suspend();
         }