htmx
htmx copied to clipboard
insertIndicatorStyles inserts styles on every request
Hi there! Just noticed, that on my site with hx-boost enabled, insertIndicatorStyles inserts it's style tag on every request, resulting in endless duplicate styles. Here's a screenshot of my dev tools:

Giving the style tag an ID and bailing early if it was already there, could solve this. Something like:
function insertIndicatorStyles() {
var id = 'hx-indicator-styles';
if( getDocument().getElementById(id) ) return;
if (htmx.config.includeIndicatorStyles !== false) {
getDocument().head.insertAdjacentHTML("beforeend",
"<style id='"+ id + "'>\
." + htmx.config.indicatorClass + "{opacity:0;transition: opacity 200ms ease-in;}\
." + htmx.config.requestClass + " ." + htmx.config.indicatorClass + "{opacity:1}\
." + htmx.config.requestClass + "." + htmx.config.indicatorClass + "{opacity:1}\
</style>");
}
}
Hmmm. Are you by any chance including htmx in multiple responses? This should only be invoked here:
https://github.com/bigskysoftware/htmx/blob/851ec5d5ab2d663e6286701380139414820f3504/src/htmx.js#L2746
which is only fired when htmx is first loaded
You are totally right. Tried to re-produce it just now, with version 1.8.0, with no success. So good news, works as expected!