diff --git a/leptos_macro/src/view/mod.rs b/leptos_macro/src/view/mod.rs index 74db49a85..3a8454156 100644 --- a/leptos_macro/src/view/mod.rs +++ b/leptos_macro/src/view/mod.rs @@ -300,7 +300,7 @@ fn inert_element_to_tokens( node: &Node, escape_text: bool, global_class: Option<&TokenTree>, -) -> Option { +) -> TokenStream { let mut html = InertElementBuilder::new(global_class); let mut nodes = VecDeque::from([Item::Node(node, escape_text)]); @@ -396,9 +396,9 @@ fn inert_element_to_tokens( html.finish(); - Some(quote! { + quote! { ::leptos::tachys::html::InertElement::new(#html) - }) + } } fn element_children_to_tokens( @@ -597,7 +597,7 @@ fn node_to_tokens( let escape = el_name != "script" && el_name != "style" && el_name != "textarea"; - inert_element_to_tokens(node, escape, global_class) + Some(inert_element_to_tokens(node, escape, global_class)) } else { element_to_tokens( el_node, diff --git a/router/src/components.rs b/router/src/components.rs index bc4ed7a98..c7f80f48e 100644 --- a/router/src/components.rs +++ b/router/src/components.rs @@ -144,16 +144,12 @@ impl RouterContext { resolve_path("", path, None) }; - let mut url = match resolved_to.map(|to| BrowserUrl::parse(&to)) { - Some(Ok(url)) => url, - Some(Err(e)) => { + let mut url = match BrowserUrl::parse(&resolved_to) { + Ok(url) => url, + Err(e) => { leptos::logging::error!("Error parsing URL: {e:?}"); return; } - None => { - leptos::logging::error!("Error resolving relative URL."); - return; - } }; let query_mutations = mem::take(&mut *self.query_mutations.write_value()); @@ -203,7 +199,7 @@ impl RouterContext { &'a self, path: &'a str, from: Option<&'a str>, - ) -> Option> { + ) -> Cow<'a, str> { let base = self.base.as_deref().unwrap_or_default(); resolve_path(base, path, from) } diff --git a/router/src/form.rs b/router/src/form.rs index 2ac2d7bd9..87ddd9cfa 100644 --- a/router/src/form.rs +++ b/router/src/form.rs @@ -87,7 +87,7 @@ where fn inner( has_router: bool, method: Option<&'static str>, - action: ArcMemo>, + action: ArcMemo, enctype: Option, version: Option>, error: Option>>>, @@ -311,7 +311,7 @@ where let action = if has_router { use_resolved_path(move || action.to_href()()) } else { - ArcMemo::new(move |_| Some(action.to_href()())) + ArcMemo::new(move |_| action.to_href()()) }; inner( has_router, diff --git a/router/src/hooks.rs b/router/src/hooks.rs index 98d5b5d66..ff5cf2454 100644 --- a/router/src/hooks.rs +++ b/router/src/hooks.rs @@ -240,7 +240,7 @@ pub(crate) struct Matched(pub ArcMemo); #[track_caller] pub(crate) fn use_resolved_path( path: impl Fn() -> String + Send + Sync + 'static, -) -> ArcMemo> { +) -> ArcMemo { let router = use_context::() .expect("called use_resolved_path outside a "); // TODO make this work with flat routes too? @@ -248,14 +248,14 @@ pub(crate) fn use_resolved_path( ArcMemo::new(move |_| { let path = path(); if path.starts_with('/') { - Some(path) + path } else { router .resolve_path( &path, matched.as_ref().map(|n| n.get()).as_deref(), ) - .map(|n| n.to_string()) + .to_string() } }) } diff --git a/router/src/link.rs b/router/src/link.rs index 31ce27467..a51575cba 100644 --- a/router/src/link.rs +++ b/router/src/link.rs @@ -102,7 +102,7 @@ where H: ToHref + Send + Sync + 'static, { fn inner( - href: ArcMemo>, + href: ArcMemo, target: Option>, exact: bool, children: Children, @@ -114,23 +114,22 @@ where let is_active = { let href = href.clone(); move || { - href.read().as_deref().is_some_and(|to| { - let path = to.split(['?', '#']).next().unwrap_or_default(); - current_url.with(|loc| { - let loc = loc.path(); - if exact { - loc == path - } else { - is_active_for(path, loc, strict_trailing_slash) - } - }) + let to = href.read(); + let path = to.split(['?', '#']).next().unwrap_or_default(); + current_url.with(|loc| { + let loc = loc.path(); + if exact { + loc == path + } else { + is_active_for(path, loc, strict_trailing_slash) + } }) } }; view! { ( base: &'a str, path: &'a str, from: Option<&'a str>, -) -> Option> { +) -> Cow<'a, str> { if has_scheme(path) { - Some(path.into()) + path.into() } else { let base_path = normalize(base, false); let from_path = from.map(|from| normalize(from, false)); @@ -25,7 +25,7 @@ pub fn resolve_path<'a>( let result_empty = result.is_empty(); let prefix = if result_empty { "/".into() } else { result }; - Some(prefix + normalize(path, result_empty)) + prefix + normalize(path, result_empty) } }