Skip to content

Commit

Permalink
Go further
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessOne1917 committed Jan 14, 2024
1 parent c00a696 commit 29df4a5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/action-form-error-handling/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ fn HomePage() -> impl IntoView {
.to_string())
>
{value}
</ErrorBoundary>
<ActionForm action=do_something_action class="form">
<label>Should error: <input type="checkbox" name="should_error"/></label>
<button type="submit">Submit</button>
</ActionForm>
</ErrorBoundary>
}
}

Expand Down
4 changes: 2 additions & 2 deletions integrations/actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ pub fn handle_server_fns_with_context(
let url = req
.headers()
.get(header::REFERER)
.and_then(|referrer| {
referrer_to_url(referrer, fn_name.as_str())
.map(|referrer| {
referrer_to_url(referrer.to_str(), fn_name.as_str())
});

if let Some(url) = url {
Expand Down
7 changes: 3 additions & 4 deletions integrations/utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use futures::{Stream, StreamExt};
use http::HeaderValue;
use leptos::{
nonce::use_nonce, server_fn::error::ServerFnUrlError, use_context,
RuntimeId, ServerFnError,
Expand Down Expand Up @@ -164,13 +163,13 @@ pub async fn build_async_response(
format!("{head}<body{body_meta}>{buf}{tail}")
}

pub fn referrer_to_url(referer: &HeaderValue, fn_name: &str) -> Option<Url> {
pub fn referrer_to_url(referer: &str, fn_name: &str) -> Url {
Url::parse(
&Regex::new(&format!(r"(?:\?|&)?server_fn_error_{fn_name}=[^&]+"))
.unwrap()
.replace(referer.to_str().ok()?, ""),
.replace(referer, ""),
)
.ok()
.expect("Could not parse URL!")
}

pub trait WithServerFn {
Expand Down
3 changes: 3 additions & 0 deletions leptos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,6 @@ where
(self)(props).into_view()
}
}

#[doc(hidden)]
pub const WASM_LOADED_NAME: &'static str = "leptos_client_wasm_loaded";
6 changes: 3 additions & 3 deletions router/src/components/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ where
})
.flatten() {
leptos::logging::log!("In iso effect with error = {url_error:?}");
value.try_set(Some(Err(url_error.error().clone())));
value.set(Some(Err(url_error.error().clone())));
}
});

Expand All @@ -480,8 +480,8 @@ where

view!{
<input
id={format!("leptos_wasm_has_loaded_{}", action_url.split('/').last().unwrap_or(""))}
name="leptos_wasm_has_loaded"
id={format!("{WASM_LOADED_NAME}_{}", action_url.split('/').last().unwrap_or(""))}
name=WASM_LOADED_NAME
type="hidden"
value=move || with!(|wasm_has_loaded|
if *wasm_has_loaded {
Expand Down

0 comments on commit 29df4a5

Please sign in to comment.