htmx icon indicating copy to clipboard operation
htmx copied to clipboard

insertIndicatorStyles inserts styles on every request

Open hirasso opened this issue 4 years ago • 1 comments

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:

Screen Shot 2021-11-27 at 13 25 48

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>");
    }
}

hirasso avatar Nov 27 '21 12:11 hirasso

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

1cg avatar Jan 16 '22 22:01 1cg

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!

hirasso avatar Aug 22 '22 21:08 hirasso