Fix morph-children: treat empty-string element IDs as nil
dom-id returns "" for elements without an id attribute, and "" is truthy in SX. This caused morph-children to build spurious entries in old-by-id keyed by "", then match unrelated children via the empty key — advancing oi past id-keyed children like #main-content and skipping them in cleanup. Three changes in morph-children (engine.sx): - old-by-id reduce: normalize empty dom-id to nil so id-less elements are excluded from the lookup dict - match-id binding: normalize empty dom-id to nil so new children without ids don't spuriously match old children - Case 2 skip condition: use (not (empty? ...)) instead of bare (dom-id old-child) to avoid treating "" as a real id Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -416,7 +416,7 @@
|
||||
(fn
|
||||
((acc :as dict) kid)
|
||||
(let
|
||||
((id (dom-id kid)))
|
||||
((id (let ((raw (dom-id kid))) (if (empty? raw) nil raw))))
|
||||
(if id (do (dict-set! acc id kid) acc) acc)))
|
||||
(dict)
|
||||
old-kids))
|
||||
@@ -425,7 +425,7 @@
|
||||
(fn
|
||||
(new-child)
|
||||
(let
|
||||
((match-id (dom-id new-child))
|
||||
((match-id (let ((raw-id (dom-id new-child))) (if (empty? raw-id) nil raw-id)))
|
||||
(match-by-id (if match-id (dict-get old-by-id match-id) nil)))
|
||||
(cond
|
||||
(and match-by-id (not (nil? match-by-id)))
|
||||
@@ -444,7 +444,7 @@
|
||||
(let
|
||||
((old-child (nth old-kids oi)))
|
||||
(if
|
||||
(and (dom-id old-child) (not match-id))
|
||||
(and (not (empty? (dom-id old-child))) (not match-id))
|
||||
(dom-insert-before
|
||||
old-parent
|
||||
(dom-clone new-child)
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user