The TagSelector needed to stay a use_resource.
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "bard"
|
||||
version = "0.3.9"
|
||||
version = "0.3.10"
|
||||
edition = "2024"
|
||||
description = "Dioxus components that will display a Tavern blogging system Blog."
|
||||
repository = "/CyberMages/tavern"
|
||||
|
||||
@ -199,12 +199,27 @@ 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_server_future(move ||
|
||||
let tags_and_selection = use_resource(move ||
|
||||
{
|
||||
let current_url = url_tag();
|
||||
|
||||
@ -242,7 +257,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