Fix duplicate sx-cssx-live style tags
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 4m40s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 4m40s
Cache the style element reference in _cssx-style-el so flush-cssx-to-dom never creates more than one. Previous code called dom-query on every flush, which could miss the element during rapid successive calls, creating duplicates. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
// =========================================================================
|
||||
|
||||
var NIL = Object.freeze({ _nil: true, toString: function() { return "nil"; } });
|
||||
var SX_VERSION = "2026-03-14T15:35:55Z";
|
||||
var SX_VERSION = "2026-03-14T17:15:49Z";
|
||||
|
||||
function isNil(x) { return x === NIL || x === null || x === undefined; }
|
||||
function isSxTruthy(x) { return x !== false && !isNil(x); }
|
||||
@@ -3682,19 +3682,22 @@ callExpr.push(dictGet(kwargs, k)); } }
|
||||
})() : NIL);
|
||||
})() : NIL); };
|
||||
|
||||
// _cssx-style-el
|
||||
var _cssxStyleEl = NIL;
|
||||
|
||||
// flush-cssx-to-dom
|
||||
var flushCssxToDom = function() { return (function() {
|
||||
var rules = sxCollected("cssx");
|
||||
return (isSxTruthy(!isSxTruthy(isEmpty(rules))) ? ((function() {
|
||||
var style = sxOr(domQuery("#sx-cssx-live"), (function() {
|
||||
return (isSxTruthy(!isSxTruthy(isEmpty(rules))) ? ((isSxTruthy(isNil(_cssxStyleEl)) ? (function() {
|
||||
var found = domQuery("#sx-cssx-live");
|
||||
return (isSxTruthy(found) ? (_cssxStyleEl = found) : (function() {
|
||||
var s = domCreateElement("style", NIL);
|
||||
domSetAttr(s, "id", "sx-cssx-live");
|
||||
domSetAttr(s, "data-cssx", "");
|
||||
domAppendToHead(s);
|
||||
return s;
|
||||
return (_cssxStyleEl = s);
|
||||
})());
|
||||
return domSetProp(style, "textContent", (String(sxOr(domGetProp(style, "textContent"), "")) + String(join("", rules))));
|
||||
})(), sxClearCollected("cssx")) : NIL);
|
||||
})() : NIL), domSetProp(_cssxStyleEl, "textContent", (String(sxOr(domGetProp(_cssxStyleEl, "textContent"), "")) + String(join("", rules)))), sxClearCollected("cssx")) : NIL);
|
||||
})(); };
|
||||
|
||||
// boot-init
|
||||
|
||||
Reference in New Issue
Block a user