Switching all server function calls.
Now server function calls use, use_server_future. It seems to be working now, unlike in 0.6.3
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "bard"
|
||||
version = "0.3.8"
|
||||
version = "0.3.9"
|
||||
edition = "2024"
|
||||
description = "Dioxus components that will display a Tavern blogging system Blog."
|
||||
repository = "/CyberMages/tavern"
|
||||
|
||||
@ -15,12 +15,12 @@ pub fn BlogItem(title: String, slug: String, author: String, summary: String,
|
||||
tags: Vec<String>)
|
||||
-> Element
|
||||
{
|
||||
let author_future = use_resource(move ||
|
||||
let author_future = use_server_future(move ||
|
||||
{
|
||||
let handle: String = author.clone();
|
||||
|
||||
async move { get_author(handle).await }
|
||||
});
|
||||
})?;
|
||||
|
||||
rsx!
|
||||
{
|
||||
@ -80,13 +80,13 @@ pub fn BlogList(tags: Signal<HashSet<String>>, children: Element) -> Element
|
||||
// Retrieve the provided settings from context.
|
||||
let settings = use_context::<BardSettings>();
|
||||
|
||||
let list = use_resource(move ||
|
||||
let list = use_server_future(move ||
|
||||
{
|
||||
let tags = tags();
|
||||
let categories: Vec<String> = tags.iter().cloned().collect();
|
||||
|
||||
async move { get_blog_list(categories).await }
|
||||
});
|
||||
})?;
|
||||
|
||||
rsx!
|
||||
{
|
||||
@ -199,27 +199,12 @@ pub fn ToggleTag(tag: String, toggled_tags: Signal<HashSet<String>>) -> Element
|
||||
}
|
||||
|
||||
|
||||
// Using use_resource instead of use_server_future for URL-dependent tag selection
|
||||
//
|
||||
// While use_server_future should theoretically be reactive when reading signals in the
|
||||
// closure (per Dioxus docs), in practice it doesn't reliably re-run when the url_tag
|
||||
// signal changes, especially during direct URL navigation (typing URLs in browser).
|
||||
//
|
||||
// use_resource provides more reliable reactivity for this use case because:
|
||||
// 1. It explicitly depends on url_tag and consistently re-runs when it changes
|
||||
// 2. It handles both async data fetching AND selection logic in a single atomic operation
|
||||
// 3. It works consistently across all navigation methods (links, direct URLs, etc.)
|
||||
// 4. It avoids timing coordination issues between separate hooks
|
||||
//
|
||||
// This approach combines fetching available tags from the server with determining
|
||||
// which tags should be selected based on the current URL, returning both pieces
|
||||
// of data together for clean state management.
|
||||
#[component]
|
||||
pub fn TagSelector(url_tag: ReadSignal<String>,
|
||||
toggled_tags: Signal<HashSet<String>>) -> Element
|
||||
{
|
||||
// Use use_resource to handle both fetching tags AND initializing selection
|
||||
let tags_and_selection = use_resource(move ||
|
||||
let tags_and_selection = use_server_future(move ||
|
||||
{
|
||||
let current_url = url_tag();
|
||||
|
||||
@ -257,7 +242,7 @@ pub fn TagSelector(url_tag: ReadSignal<String>,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
})?;
|
||||
|
||||
// Separate effect to update toggled_tags when resource completes
|
||||
// This separates reading the resource from writing to toggled_tags
|
||||
|
||||
Reference in New Issue
Block a user