Use HX-Target, not HX-Boost for Layout render

HX-Boost is not always sent in all AJAX requests that htmx sends, only
those initiated by an element with hx-boost enabled. It was not showing
up on requests following an HX-Redirect response.

After reading the docs more, I realized HX-Target was what I wanted. If
I can see that the request is targeting `#main-content` then I know to
only return HTML inside that element. Simple.
This commit is contained in:
2023-09-27 01:28:53 -04:00
parent bea3529e22
commit a72bfa15bd
10 changed files with 110 additions and 60 deletions

View File

@@ -7,7 +7,7 @@ use serde_with::{serde_as, NoneAsEmptyString};
use sqlx::PgPool;
use crate::error::{Error, Result};
use crate::htmx::{HXBoosted, HXRedirect};
use crate::htmx::{HXTarget, HXRedirect};
use crate::models::user::{AuthContext, CreateUser, User};
use crate::partials::layout::Layout;
use crate::partials::register_form::{register_form, RegisterFormProps};
@@ -22,10 +22,10 @@ pub struct Register {
pub name: Option<String>,
}
pub async fn get(hx_boosted: Option<TypedHeader<HXBoosted>>, layout: Layout) -> Result<Response> {
pub async fn get(hx_target: Option<TypedHeader<HXTarget>>, layout: Layout) -> Result<Response> {
Ok(layout
.with_subtitle("register")
.boosted(hx_boosted)
.targeted(hx_target)
.render(html! {
div class="center-horizontal" {
header class="center-text" {