Fix handler aser keyword loss: re-serialize evaluated HTML elements
When handler bodies use (let ((rows (map ...))) (<> rows)), the let binding evaluates the map via CEK, which converts :class keywords to "class" strings. The aser fragment serializer then outputs "class" as text content instead of :class as an HTML attribute. Fix: add aser-reserialize function that detects string pairs in evaluated element lists where the first string matches known HTML attribute names (class, id, sx-*, data-*, style, href, src, type, name, value, etc.) and restores them as :keyword syntax. All 7 handler response tests now pass: - bulk-update, delete-row, click-to-load, active-search - form-submission, edit-row, tabs Total Playwright: 79/79 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -134,6 +134,64 @@
|
||||
:else (error (str "Not callable: " (inspect f)))))))))))
|
||||
|
||||
|
||||
;; Re-serialize an evaluated HTML element list, restoring keyword syntax.
|
||||
;; The CEK evaluates keywords to strings, so (tr :class "row") becomes
|
||||
;; (list Symbol("tr") String("class") String("row")). This function
|
||||
;; detects string pairs where the first string is an HTML attribute name
|
||||
;; and restores them as :keyword syntax for the SX wire format.
|
||||
(define aser-reserialize :effects []
|
||||
(fn (val)
|
||||
(if (not (= (type-of val) "list"))
|
||||
(serialize val)
|
||||
(if (empty? val)
|
||||
"()"
|
||||
(let ((head (first val)))
|
||||
(if (not (= (type-of head) "symbol"))
|
||||
(serialize val)
|
||||
(let ((tag (symbol-name head))
|
||||
(parts (list tag))
|
||||
(args (rest val))
|
||||
(skip false)
|
||||
(i 0))
|
||||
(for-each
|
||||
(fn (arg)
|
||||
(if skip
|
||||
(do (set! skip false) (set! i (inc i)))
|
||||
(if (and (= (type-of arg) "string")
|
||||
(< (inc i) (len args))
|
||||
;; Heuristic: if the next arg is also a string or a list,
|
||||
;; and this arg looks like an attribute name (no spaces,
|
||||
;; starts with lowercase or is a known attr pattern)
|
||||
(not (contains? arg " "))
|
||||
(or (starts-with? arg "class")
|
||||
(starts-with? arg "id")
|
||||
(starts-with? arg "sx-")
|
||||
(starts-with? arg "data-")
|
||||
(starts-with? arg "style")
|
||||
(starts-with? arg "href")
|
||||
(starts-with? arg "src")
|
||||
(starts-with? arg "type")
|
||||
(starts-with? arg "name")
|
||||
(starts-with? arg "value")
|
||||
(starts-with? arg "placeholder")
|
||||
(starts-with? arg "action")
|
||||
(starts-with? arg "method")
|
||||
(starts-with? arg "target")
|
||||
(starts-with? arg "role")
|
||||
(starts-with? arg "for")
|
||||
(starts-with? arg "on")))
|
||||
(do
|
||||
(append! parts (str ":" arg))
|
||||
(append! parts (serialize (nth args (inc i))))
|
||||
(set! skip true)
|
||||
(set! i (inc i)))
|
||||
(do
|
||||
(append! parts (aser-reserialize arg))
|
||||
(set! i (inc i))))))
|
||||
args)
|
||||
(str "(" (join " " parts) ")"))))))))
|
||||
|
||||
|
||||
(define aser-fragment :effects [render]
|
||||
(fn ((children :as list) (env :as dict))
|
||||
;; Serialize (<> child1 child2 ...) to sx source string
|
||||
@@ -153,7 +211,7 @@
|
||||
(when (not (nil? item))
|
||||
(if (= (type-of item) "sx-expr")
|
||||
(append! parts (sx-expr-source item))
|
||||
(append! parts (serialize item)))))
|
||||
(append! parts (aser-reserialize item)))))
|
||||
result)
|
||||
;; Everything else — serialize normally (quotes strings)
|
||||
:else
|
||||
|
||||
Reference in New Issue
Block a user