diff --git a/Cargo.lock b/Cargo.lock index 39e929e..d21eac4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -297,7 +297,7 @@ dependencies = [ [[package]] name = "bard" -version = "0.3.7" +version = "0.3.9" dependencies = [ "dioxus", "tavern", diff --git a/bard/Cargo.toml b/bard/Cargo.toml index a939df9..fbb5a85 100644 --- a/bard/Cargo.toml +++ b/bard/Cargo.toml @@ -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" diff --git a/bard/src/components/list.rs b/bard/src/components/list.rs index b108a19..9bf8499 100644 --- a/bard/src/components/list.rs +++ b/bard/src/components/list.rs @@ -15,12 +15,12 @@ pub fn BlogItem(title: String, slug: String, author: String, summary: String, tags: Vec) -> 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>, children: Element) -> Element // Retrieve the provided settings from context. let settings = use_context::(); - let list = use_resource(move || + let list = use_server_future(move || { let tags = tags(); let categories: Vec = tags.iter().cloned().collect(); async move { get_blog_list(categories).await } - }); + })?; rsx! { @@ -199,27 +199,12 @@ pub fn ToggleTag(tag: String, toggled_tags: Signal>) -> 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, toggled_tags: Signal>) -> 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, } } } - }); + })?; // Separate effect to update toggled_tags when resource completes // This separates reading the resource from writing to toggled_tags