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:
@@ -5,18 +5,18 @@ use maud::html;
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::htmx::HXBoosted;
|
||||
use crate::htmx::HXTarget;
|
||||
use crate::models::entry::Entry;
|
||||
use crate::partials::{entry_list::entry_list, layout::Layout};
|
||||
|
||||
pub async fn get(
|
||||
State(pool): State<PgPool>,
|
||||
hx_boosted: Option<TypedHeader<HXBoosted>>,
|
||||
hx_target: Option<TypedHeader<HXTarget>>,
|
||||
layout: Layout,
|
||||
) -> Result<Response> {
|
||||
let options = Default::default();
|
||||
let entries = Entry::get_all(&pool, &options).await?;
|
||||
Ok(layout.boosted(hx_boosted).render(html! {
|
||||
Ok(layout.targeted(hx_target).render(html! {
|
||||
ul class="entries" {
|
||||
(entry_list(entries, &options))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user