web+host: fix raw! HTML dropped in client SX render (dom-parse-html returned a NodeList)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 41s

dom-parse-html returned body.childNodes — a NodeList, not a Node — so the client
SX render did appendChild(NodeList) and threw "Argument 1 does not implement
interface Node", silently dropping every raw! HTML block (e.g. a post's <article>
body). It surfaced only now because the blog renders fragments client-side
(text/sx) since this session; before, fragments were server HTML so sx-render
never ran on raw!. The error is caught/non-fatal, and the spa-check suite only
asserted the footer + URL behaviour, so it passed through a dropped post body.

- dom-parse-html now returns a DocumentFragment (moves the parsed nodes in): a
  real Node, appendChild-able as one unit, and queryable — which also fixes the
  already-broken hs-htmx callers that did (dom-query doc ...) / (dom-first-child
  doc) on what was a NodeList.
- spa-check: assert #content article is visible after a boosted nav, so a dropped
  post body fails the suite (closes the test gap).
- .sxbc regenerated; bundle dom.sx synced to canonical web/lib/dom.sx.

Verified: spa-check 4/4 (incl. the new article assertion).
This commit is contained in:
2026-06-29 13:27:13 +00:00
parent 59ac51a8ba
commit f5b6612ee1
4 changed files with 40 additions and 6 deletions

View File

@@ -51,6 +51,10 @@ test.describe('blog SPA', () => {
expect(await page.evaluate(() => window.__noReload)).toBe(true); // no reload expect(await page.evaluate(() => window.__noReload)).toBe(true); // no reload
// content was swapped into #content (a post page carries the post footer) // content was swapped into #content (a post page carries the post footer)
await expect(page.locator('#content')).toContainText(/all posts/i, { timeout: 15000 }); await expect(page.locator('#content')).toContainText(/all posts/i, { timeout: 15000 });
// the post BODY itself rendered — the <article> comes from raw! HTML, which
// exercises the client SX raw-HTML path (dom-parse-html). If that drops the
// content (NodeList-vs-Node bug), the footer still shows but this fails.
await expect(page.locator('#content article').first()).toBeVisible({ timeout: 15000 });
}); });
test('back button restores the listing', async ({ page }) => { test('back button restores the listing', async ({ page }) => {

View File

@@ -359,12 +359,27 @@
(define dom-focus (fn (el) (when el (host-call el "focus")))) (define dom-focus (fn (el) (when el (host-call el "focus"))))
(define (define
dom-parse-html dom-parse-html
;; Returns a DocumentFragment of the parsed nodes — a real Node, so it can
;; be appendChild-ed as one unit AND queried (querySelector/firstChild).
;; (Was body.childNodes — a NodeList, which appendChild rejects with
;; "Argument 1 does not implement interface Node", silently dropping raw!
;; HTML in the client SX render; dom-query on it in hs-htmx was a no-op too.)
(fn (fn
(html) (html)
(let (let
((parser (host-new "DOMParser")) ((parser (host-new "DOMParser"))
(doc (host-call parser "parseFromString" html "text/html"))) (doc (host-call parser "parseFromString" html "text/html"))
(host-get (host-get doc "body") "childNodes")))) (frag (create-fragment)))
(let
((body (host-get doc "body")))
(let
loop
((node (host-get body "firstChild")))
(when
(not (nil? node))
(host-call frag "appendChild" node) ;; appendChild MOVES the node
(loop (host-get body "firstChild"))))
frag))))
(define (define
dom-listen dom-listen
(fn (fn

File diff suppressed because one or more lines are too long

View File

@@ -359,12 +359,27 @@
(define dom-focus (fn (el) (when el (host-call el "focus")))) (define dom-focus (fn (el) (when el (host-call el "focus"))))
(define (define
dom-parse-html dom-parse-html
;; Returns a DocumentFragment of the parsed nodes — a real Node, so it can
;; be appendChild-ed as one unit AND queried (querySelector/firstChild).
;; (Was body.childNodes — a NodeList, which appendChild rejects with
;; "Argument 1 does not implement interface Node", silently dropping raw!
;; HTML in the client SX render; dom-query on it in hs-htmx was a no-op too.)
(fn (fn
(html) (html)
(let (let
((parser (host-new "DOMParser")) ((parser (host-new "DOMParser"))
(doc (host-call parser "parseFromString" html "text/html"))) (doc (host-call parser "parseFromString" html "text/html"))
(host-get (host-get doc "body") "childNodes")))) (frag (create-fragment)))
(let
((body (host-get doc "body")))
(let
loop
((node (host-get body "firstChild")))
(when
(not (nil? node))
(host-call frag "appendChild" node) ;; appendChild MOVES the node
(loop (host-get body "firstChild"))))
frag))))
(define (define
dom-listen dom-listen
(fn (fn