fix: <ActionForm/> should check origin correctly before doing a full-page refresh (#1304)

This commit is contained in:
Greg Johnston 2023-07-08 08:00:48 -04:00 committed by GitHub
parent da9183f4b5
commit b29eb8e032
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -143,10 +143,7 @@ where
match Url::try_from(resp_url.as_str()) {
Ok(url) => {
if url.origin
!= window()
.location()
.origin()
.unwrap_or_default()
!= current_window_origin()
{
_ = window()
.location()
@ -227,10 +224,7 @@ where
match Url::try_from(resp_url.as_str()) {
Ok(url) => {
if url.origin
!= window()
.location()
.hostname()
.unwrap_or_default()
!= current_window_origin()
{
_ = window()
.location()
@ -328,6 +322,20 @@ where
)
}
fn current_window_origin() -> String {
let location = window().location();
let protocol = location.protocol().unwrap_or_default();
let hostname = location.hostname().unwrap_or_default();
let port = location.port().unwrap_or_default();
format!(
"{}//{}{}{}",
protocol,
hostname,
if port.is_empty() { "" } else { ":" },
port
)
}
/// Automatically turns a server [Action](leptos_server::Action) into an HTML
/// [`form`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form)
/// progressively enhanced to use client-side routing.