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:
@@ -373,16 +373,15 @@
|
||||
(loop (+ i 2))))
|
||||
;; Evaluate spread components (e.g. ~cssx/tw) and apply to element
|
||||
(for-each (fn (sp)
|
||||
(let ((rendered (render-to-dom sp (make-env) nil)))
|
||||
(when (and rendered (spread? rendered))
|
||||
(let ((sattrs (spread-attrs rendered)))
|
||||
(let ((result (eval-expr sp (make-env))))
|
||||
(when (and result (spread? result))
|
||||
(let ((sattrs (spread-attrs result)))
|
||||
(for-each (fn (k)
|
||||
(if (= k "class")
|
||||
(dom-set-attr el "class"
|
||||
(str (or (dom-get-attr el "class") "") " " (get sattrs k)))
|
||||
(dom-set-attr el k (get sattrs k))))
|
||||
(keys sattrs))))
|
||||
nil))
|
||||
(keys sattrs))))))
|
||||
spreads)
|
||||
(when parent (dom-append parent el))
|
||||
(set! dom-stack (append dom-stack (list el)))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; SX app boot — styles and behaviors injected on page load
|
||||
;; SX app boot — styles, behaviors, and post-render hooks
|
||||
;;
|
||||
;; Replaces inline_css and init_sx from Python app config.
|
||||
;; Called as a data-init script on every page.
|
||||
@@ -11,6 +11,25 @@
|
||||
(collect! "cssx" "@keyframes sxJiggle{0%,100%{transform:translateX(0)}25%{transform:translateX(-.5px)}75%{transform:translateX(.5px)}}")
|
||||
(collect! "cssx" "a.sx-request{animation:sxJiggle .3s ease-in-out infinite}")
|
||||
|
||||
;; CSSX flush hook — inject collected CSS rules into a <style> tag.
|
||||
;; The spec calls (run-post-render-hooks) after hydration/swap/mount.
|
||||
;; This is the application's CSS injection strategy.
|
||||
(console-log "init-client: registering cssx flush hook, type:" (type-of (fn () nil)))
|
||||
(register-post-render-hook
|
||||
(fn ()
|
||||
(console-log "cssx flush: running, rules:" (len (collected "cssx")))
|
||||
(let ((rules (collected "cssx")))
|
||||
(when (not (empty? rules))
|
||||
(let ((style (or (dom-query "[data-cssx]")
|
||||
(let ((s (dom-create-element "style" nil)))
|
||||
(dom-set-attr s "data-cssx" "")
|
||||
(dom-append-to-head s)
|
||||
s))))
|
||||
(dom-set-prop style "textContent"
|
||||
(str (or (dom-get-prop style "textContent") "")
|
||||
(join "" rules))))
|
||||
(clear-collected! "cssx")))))
|
||||
|
||||
;; Nav link aria-selected update on client-side routing
|
||||
(dom-listen (dom-body) "sx:clientRoute"
|
||||
(fn (e)
|
||||
|
||||
Reference in New Issue
Block a user