Remove unnecessary Option wrapping (#4035)

* Remove unnecessary Option wrapping.

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Moritz Hedtke
2025-06-16 19:37:26 +02:00
committed by GitHub
parent 5587ccd1eb
commit 40ea20057f
6 changed files with 27 additions and 32 deletions

View File

@@ -300,7 +300,7 @@ fn inert_element_to_tokens(
node: &Node<impl CustomNode>, node: &Node<impl CustomNode>,
escape_text: bool, escape_text: bool,
global_class: Option<&TokenTree>, global_class: Option<&TokenTree>,
) -> Option<TokenStream> { ) -> TokenStream {
let mut html = InertElementBuilder::new(global_class); let mut html = InertElementBuilder::new(global_class);
let mut nodes = VecDeque::from([Item::Node(node, escape_text)]); let mut nodes = VecDeque::from([Item::Node(node, escape_text)]);
@@ -396,9 +396,9 @@ fn inert_element_to_tokens(
html.finish(); html.finish();
Some(quote! { quote! {
::leptos::tachys::html::InertElement::new(#html) ::leptos::tachys::html::InertElement::new(#html)
}) }
} }
fn element_children_to_tokens( fn element_children_to_tokens(
@@ -597,7 +597,7 @@ fn node_to_tokens(
let escape = el_name != "script" let escape = el_name != "script"
&& el_name != "style" && el_name != "style"
&& el_name != "textarea"; && el_name != "textarea";
inert_element_to_tokens(node, escape, global_class) Some(inert_element_to_tokens(node, escape, global_class))
} else { } else {
element_to_tokens( element_to_tokens(
el_node, el_node,

View File

@@ -144,16 +144,12 @@ impl RouterContext {
resolve_path("", path, None) resolve_path("", path, None)
}; };
let mut url = match resolved_to.map(|to| BrowserUrl::parse(&to)) { let mut url = match BrowserUrl::parse(&resolved_to) {
Some(Ok(url)) => url, Ok(url) => url,
Some(Err(e)) => { Err(e) => {
leptos::logging::error!("Error parsing URL: {e:?}"); leptos::logging::error!("Error parsing URL: {e:?}");
return; return;
} }
None => {
leptos::logging::error!("Error resolving relative URL.");
return;
}
}; };
let query_mutations = let query_mutations =
mem::take(&mut *self.query_mutations.write_value()); mem::take(&mut *self.query_mutations.write_value());
@@ -203,7 +199,7 @@ impl RouterContext {
&'a self, &'a self,
path: &'a str, path: &'a str,
from: Option<&'a str>, from: Option<&'a str>,
) -> Option<Cow<'a, str>> { ) -> Cow<'a, str> {
let base = self.base.as_deref().unwrap_or_default(); let base = self.base.as_deref().unwrap_or_default();
resolve_path(base, path, from) resolve_path(base, path, from)
} }

View File

@@ -87,7 +87,7 @@ where
fn inner( fn inner(
has_router: bool, has_router: bool,
method: Option<&'static str>, method: Option<&'static str>,
action: ArcMemo<Option<String>>, action: ArcMemo<String>,
enctype: Option<String>, enctype: Option<String>,
version: Option<RwSignal<usize>>, version: Option<RwSignal<usize>>,
error: Option<RwSignal<Option<Box<dyn Error + Send + Sync>>>>, error: Option<RwSignal<Option<Box<dyn Error + Send + Sync>>>>,
@@ -311,7 +311,7 @@ where
let action = if has_router { let action = if has_router {
use_resolved_path(move || action.to_href()()) use_resolved_path(move || action.to_href()())
} else { } else {
ArcMemo::new(move |_| Some(action.to_href()())) ArcMemo::new(move |_| action.to_href()())
}; };
inner( inner(
has_router, has_router,

View File

@@ -240,7 +240,7 @@ pub(crate) struct Matched(pub ArcMemo<String>);
#[track_caller] #[track_caller]
pub(crate) fn use_resolved_path( pub(crate) fn use_resolved_path(
path: impl Fn() -> String + Send + Sync + 'static, path: impl Fn() -> String + Send + Sync + 'static,
) -> ArcMemo<Option<String>> { ) -> ArcMemo<String> {
let router = use_context::<RouterContext>() let router = use_context::<RouterContext>()
.expect("called use_resolved_path outside a <Router>"); .expect("called use_resolved_path outside a <Router>");
// TODO make this work with flat routes too? // TODO make this work with flat routes too?
@@ -248,14 +248,14 @@ pub(crate) fn use_resolved_path(
ArcMemo::new(move |_| { ArcMemo::new(move |_| {
let path = path(); let path = path();
if path.starts_with('/') { if path.starts_with('/') {
Some(path) path
} else { } else {
router router
.resolve_path( .resolve_path(
&path, &path,
matched.as_ref().map(|n| n.get()).as_deref(), matched.as_ref().map(|n| n.get()).as_deref(),
) )
.map(|n| n.to_string()) .to_string()
} }
}) })
} }

View File

@@ -102,7 +102,7 @@ where
H: ToHref + Send + Sync + 'static, H: ToHref + Send + Sync + 'static,
{ {
fn inner( fn inner(
href: ArcMemo<Option<String>>, href: ArcMemo<String>,
target: Option<Oco<'static, str>>, target: Option<Oco<'static, str>>,
exact: bool, exact: bool,
children: Children, children: Children,
@@ -114,23 +114,22 @@ where
let is_active = { let is_active = {
let href = href.clone(); let href = href.clone();
move || { move || {
href.read().as_deref().is_some_and(|to| { let to = href.read();
let path = to.split(['?', '#']).next().unwrap_or_default(); let path = to.split(['?', '#']).next().unwrap_or_default();
current_url.with(|loc| { current_url.with(|loc| {
let loc = loc.path(); let loc = loc.path();
if exact { if exact {
loc == path loc == path
} else { } else {
is_active_for(path, loc, strict_trailing_slash) is_active_for(path, loc, strict_trailing_slash)
} }
})
}) })
} }
}; };
view! { view! {
<a <a
href=move || href.get().unwrap_or_default() href=move || href.get()
target=target target=target
aria-current=move || if is_active() { Some("page") } else { None } aria-current=move || if is_active() { Some("page") } else { None }
data-noscroll=!scroll data-noscroll=!scroll

View File

@@ -4,9 +4,9 @@ pub fn resolve_path<'a>(
base: &'a str, base: &'a str,
path: &'a str, path: &'a str,
from: Option<&'a str>, from: Option<&'a str>,
) -> Option<Cow<'a, str>> { ) -> Cow<'a, str> {
if has_scheme(path) { if has_scheme(path) {
Some(path.into()) path.into()
} else { } else {
let base_path = normalize(base, false); let base_path = normalize(base, false);
let from_path = from.map(|from| normalize(from, 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 result_empty = result.is_empty();
let prefix = if result_empty { "/".into() } else { result }; let prefix = if result_empty { "/".into() } else { result };
Some(prefix + normalize(path, result_empty)) prefix + normalize(path, result_empty)
} }
} }