diff --git a/Cargo.lock b/Cargo.lock index d21eac4..60241bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -297,7 +297,7 @@ dependencies = [ [[package]] name = "bard" -version = "0.3.9" +version = "0.3.10" dependencies = [ "dioxus", "tavern", diff --git a/bard/Cargo.toml b/bard/Cargo.toml index fbb5a85..04e38af 100644 --- a/bard/Cargo.toml +++ b/bard/Cargo.toml @@ -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" diff --git a/bard/src/components/list.rs b/bard/src/components/list.rs index 9bf8499..f861848 100644 --- a/bard/src/components/list.rs +++ b/bard/src/components/list.rs @@ -199,12 +199,27 @@ 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_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, } } } - })?; + }); // Separate effect to update toggled_tags when resource completes // This separates reading the resource from writing to toggled_tags