From c39cae6c577309818ef9c30723d67df08be28272 Mon Sep 17 00:00:00 2001 From: Henry <56412856+mcmah309@users.noreply.github.com> Date: Sat, 4 Oct 2025 03:56:18 +0000 Subject: [PATCH] Improve use_server_future docs (#4558) Co-authored-by: Jonathan Kelley --- packages/fullstack-core/src/server_future.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/fullstack-core/src/server_future.rs b/packages/fullstack-core/src/server_future.rs index f4b4ec220..aa1fa1c19 100644 --- a/packages/fullstack-core/src/server_future.rs +++ b/packages/fullstack-core/src/server_future.rs @@ -4,10 +4,12 @@ use dioxus_signals::ReadableExt; use serde::{de::DeserializeOwned, Serialize}; use std::future::Future; -/// Runs a future with a manual list of dependencies and returns a resource with the result if the future is finished or a suspended error if it is still running. +/// Runs a future and returns a result with a resource if the future is finished or a suspended error if it is still running. The future may run on the server *during hydration*. +/// - When compiled as server, the closure's future is ran to completion and the resulting data is serialized on the server and sent to the client. +/// - When compiled as web client, the data is deserialized from the server if already available, otherwise runs on the client. Data is usually only available if this hook exists in a component during hydration. +/// - When otherwise compiled, the closure is run directly with no serialization. /// -/// -/// On the server, this will wait until the future is resolved before continuing to render. When the future is resolved, the result will be serialized into the page and hydrated on the client without rerunning the future. +/// On the server, this will wait until the future is resolved before continuing to render. Thus, this blocks other subsequent server hooks. The result is cached. /// /// ///
@@ -57,7 +59,6 @@ use std::future::Future; /// } /// } /// ``` -#[must_use = "Consider using `cx.spawn` to run a future without reading its value"] #[track_caller] pub fn use_server_future( mut future: impl FnMut() -> F + 'static,