Fix duplicate sx-cssx-live style tags
Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled
Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled
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:47:47Z";
|
||||
|
||||
function isNil(x) { return x === NIL || x === null || x === undefined; }
|
||||
function isSxTruthy(x) { return x !== false && !isNil(x); }
|
||||
@@ -2354,7 +2354,7 @@ return (function() {
|
||||
})();
|
||||
}
|
||||
{ var _c = extraKeys; for (var _i = 0; _i < _c.length; _i++) { var k = _c[_i]; domSetAttr(el, k, (String(dictGet(attrs, k)))); } }
|
||||
return flushCssxToDom();
|
||||
return runPostRenderHooks();
|
||||
})() : ((prevClasses = []), (prevExtraKeys = [])));
|
||||
})(); });
|
||||
})(); };
|
||||
@@ -3065,7 +3065,7 @@ return postSwap(target); });
|
||||
sxProcessScripts(root);
|
||||
sxHydrate(root);
|
||||
sxHydrateIslands(root);
|
||||
flushCssxToDom();
|
||||
runPostRenderHooks();
|
||||
return processElements(root); };
|
||||
|
||||
// process-settle-hooks
|
||||
@@ -3300,7 +3300,7 @@ return logWarn((String("sx:offline sync failed ") + String(get(entry, "action"))
|
||||
})(); };
|
||||
|
||||
// swap-rendered-content
|
||||
var swapRenderedContent = function(target, rendered, pathname) { return (disposeIslandsIn(target), domSetTextContent(target, ""), domAppend(target, rendered), hoistHeadElementsFull(target), processElements(target), sxHydrateElements(target), flushCssxToDom(), domDispatch(target, "sx:clientRoute", {["pathname"]: pathname}), logInfo((String("sx:route client ") + String(pathname)))); };
|
||||
var swapRenderedContent = function(target, rendered, pathname) { return (disposeIslandsIn(target), domSetTextContent(target, ""), domAppend(target, rendered), hoistHeadElementsFull(target), processElements(target), sxHydrateElements(target), runPostRenderHooks(), domDispatch(target, "sx:clientRoute", {["pathname"]: pathname}), logInfo((String("sx:route client ") + String(pathname)))); };
|
||||
|
||||
// resolve-route-target
|
||||
var resolveRouteTarget = function(targetSel) { return (isSxTruthy((isSxTruthy(targetSel) && !isSxTruthy((targetSel == "true")))) ? domQuery(targetSel) : NIL); };
|
||||
@@ -3520,7 +3520,7 @@ return processEmitElements(root); };
|
||||
processElements(el);
|
||||
sxHydrateElements(el);
|
||||
sxHydrateIslands(el);
|
||||
return flushCssxToDom();
|
||||
return runPostRenderHooks();
|
||||
})() : NIL);
|
||||
})(); };
|
||||
|
||||
@@ -3536,7 +3536,7 @@ return (function() {
|
||||
processElements(el);
|
||||
sxHydrateElements(el);
|
||||
sxHydrateIslands(el);
|
||||
flushCssxToDom();
|
||||
runPostRenderHooks();
|
||||
return domDispatch(el, "sx:resolved", {"id": id});
|
||||
})() : logWarn((String("resolveSuspense: no element for id=") + String(id))));
|
||||
})(); };
|
||||
@@ -3682,23 +3682,26 @@ callExpr.push(dictGet(kwargs, k)); } }
|
||||
})() : NIL);
|
||||
})() : 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() {
|
||||
var s = domCreateElement("style", NIL);
|
||||
domSetAttr(s, "id", "sx-cssx-live");
|
||||
domSetAttr(s, "data-cssx", "");
|
||||
domAppendToHead(s);
|
||||
return s;
|
||||
})());
|
||||
return domSetProp(style, "textContent", (String(sxOr(domGetProp(style, "textContent"), "")) + String(join("", rules))));
|
||||
})(), sxClearCollected("cssx")) : NIL);
|
||||
})(); };
|
||||
// *pre-render-hooks*
|
||||
var *preRenderHooks* = [];
|
||||
|
||||
// *post-render-hooks*
|
||||
var *postRenderHooks* = [];
|
||||
|
||||
// register-pre-render-hook
|
||||
var registerPreRenderHook = function(hookFn) { return append_b(*preRenderHooks*, hookFn); };
|
||||
|
||||
// register-post-render-hook
|
||||
var registerPostRenderHook = function(hookFn) { return append_b(*postRenderHooks*, hookFn); };
|
||||
|
||||
// run-pre-render-hooks
|
||||
var runPreRenderHooks = function() { return forEach(function(hook) { return hook(); }, *preRenderHooks*); };
|
||||
|
||||
// run-post-render-hooks
|
||||
var runPostRenderHooks = function() { return forEach(function(hook) { return hook(); }, *postRenderHooks*); };
|
||||
|
||||
// boot-init
|
||||
var bootInit = function() { return (logInfo((String("sx-browser ") + String(SX_VERSION))), initCssTracking(), processPageScripts(), processSxScripts(NIL), sxHydrateElements(NIL), sxHydrateIslands(NIL), flushCssxToDom(), processElements(NIL)); };
|
||||
var bootInit = function() { return (logInfo((String("sx-browser ") + String(SX_VERSION))), initCssTracking(), processPageScripts(), processSxScripts(NIL), sxHydrateElements(NIL), sxHydrateIslands(NIL), runPostRenderHooks(), processElements(NIL)); };
|
||||
|
||||
|
||||
// === Transpiled from deps (component dependency analysis) ===
|
||||
@@ -5256,6 +5259,10 @@ return (function() {
|
||||
// Environment (for creating eval contexts)
|
||||
PRIMITIVES["make-env"] = function() { return merge(componentEnv, PRIMITIVES); };
|
||||
|
||||
// Render hooks (from boot.sx)
|
||||
PRIMITIVES["register-pre-render-hook"] = registerPreRenderHook;
|
||||
PRIMITIVES["register-post-render-hook"] = registerPostRenderHook;
|
||||
|
||||
|
||||
// =========================================================================
|
||||
// Platform interface — DOM adapter (browser-only)
|
||||
|
||||
Reference in New Issue
Block a user