From 4e7007bbfc7e7e4168df45095fdab30be0049e55 Mon Sep 17 00:00:00 2001 From: giles Date: Sat, 14 Mar 2026 17:16:13 +0000 Subject: [PATCH] Fix duplicate sx-cssx-live style tags 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) --- shared/static/scripts/sx-browser.js | 5 ++--- shared/sx/ref/boot.sx | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/shared/static/scripts/sx-browser.js b/shared/static/scripts/sx-browser.js index ed3eb02..ad1653c 100644 --- a/shared/static/scripts/sx-browser.js +++ b/shared/static/scripts/sx-browser.js @@ -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:23:24Z"; function isNil(x) { return x === NIL || x === null || x === undefined; } function isSxTruthy(x) { return x !== false && !isNil(x); } @@ -3686,9 +3686,8 @@ callExpr.push(dictGet(kwargs, k)); } } var flushCssxToDom = function() { return (function() { var rules = sxCollected("cssx"); return (isSxTruthy(!isSxTruthy(isEmpty(rules))) ? ((function() { - var style = sxOr(domQuery("#sx-cssx-live"), (function() { + var style = sxOr(domQuery("[data-cssx]"), (function() { var s = domCreateElement("style", NIL); - domSetAttr(s, "id", "sx-cssx-live"); domSetAttr(s, "data-cssx", ""); domAppendToHead(s); return s; diff --git a/shared/sx/ref/boot.sx b/shared/sx/ref/boot.sx index 19ab753..7704038 100644 --- a/shared/sx/ref/boot.sx +++ b/shared/sx/ref/boot.sx @@ -431,9 +431,8 @@ (fn () (let ((rules (collected "cssx"))) (when (not (empty? rules)) - (let ((style (or (dom-query "#sx-cssx-live") + (let ((style (or (dom-query "[data-cssx]") (let ((s (dom-create-element "style" nil))) - (dom-set-attr s "id" "sx-cssx-live") (dom-set-attr s "data-cssx" "") (dom-append-to-head s) s))))