-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
hx-boost is useful, but can easily cause issues when used together with regular swaps.
Details
Here is the originally motivating example:
<body hx-ext="head-support"
hx-boost="true" hx-target="#main" hx-select="#main"
hx-swap="outerHTML transition:true show:window:top">
<nav>...</nav>
<div id="main" hx-history-elt>...</div>
<footer>...</footer>
<div hx-get="/player"
hx-swap="outerHTML transition:false settle:0"
hx-target="this" hx-select="unset"
hx-trigger="load[!!window.Alpine], alpine:init from:document"></div>
</body>Because I'm using hx-boost together with hx-target, hx-select and hx-swap,
everytime I want do a non-boosted swap, I have to explicitly set them to undo the boost values.
(Most obviously, needing to use hx-target="this" and hx-select="unset".)
These workarounds can quickly become tedious if you have more than a few swaps and aren't obvious to a lot of users.
Even when not using target/select, swap modifiers impact any normal swap where hx-swap isn't explicitly specified.
Note: I can't just use hx-disinherit high up in the tree since hx-boost generally relies on inheritence to work.
Note: Perhaps this particular situation could instead use hx-preserve, but it doesn't affect the underlying argument.
Attempted solution
Instead of being forced to use attributes to set these values, I propose boost-specific defaults that can be specified in the config.
These would only apply for boosts and would be ignored if their equivalent attribute was found and hence would prioritize locality of behavior. An alternative approach of prioritizing config values would further separate boost and regular swaps, but would require more thought.
Here is an example implementation that adds defaultBoostSwap, defaultBoostTarget and defaultBoostSelect to the config (feel free to bike-shed).
Note: This implementation needs to be updated to have the correct value for htmx:targetError but is waiting for PR #3178 to be merged first.
Note: Even though hx-history-elt may often be used in conjunction, currently no effort is made to avoid still having to specify it as an attribute.
<meta name="htmx-config" content='{
"defaultBoostTarget": "#main",
"defaultBoostSelect": "#main",
"defaultBoostSwap": "outerHTML transition:true show:window:top"
}'>
</head>
<body hx-ext="head-support" hx-boost="true">
<nav>...</nav>
<div id="main" hx-history-elt>...</div>
<footer>...</footer>
<div hx-get="/player"
hx-swap="outerHTML transition:false settle:0"
hx-trigger="load[!!window.Alpine], alpine:init from:document"></div>
</body>If the idea for this feature is approved then I could start work adding updates for the docs.