You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
<svg><template> crashes: Cannot read properties of undefined (reading 'nodeName') #17
TypeError: Cannot read properties of undefined (reading 'nodeName')
at one (lib/index.js:72)
at element (lib/index.js:204)
Reachable through every HTML→hast path that uses this utility: hast-util-raw (so rehype-raw on markdown containing that raw HTML), hast-util-from-html, and rehype-parse — whole-document mode included.
Expected behavior
No crash; the foreign template converts like any other foreign element.
Cause
element() switches to the template-contents branch on the tag name alone:
parse5 — per the HTML spec — attaches template contents only to an HTML-namespace template. Inside foreign content a <template> is an ordinary foreign element: its children live in childNodes, and its content is undefined, so one(state, undefined) throws.
Fix
Guard the branch on the field actually being present:
The foreign template then takes the ordinary element path, and hastscript normalizes its children onto content anyway, so the converted shape matches the HTML form. PR with tests incoming.
Runtime / package manager
Node 22 / npm — but the crash is environment-independent.
Activity
AIEPhoenix commentedon Aug 24, 2026
Closing as a duplicate of #15, which reported the same crash three weeks earlier (I only found it after filing). #16 has a fix ready.
github-actions commentedon Aug 24, 2026
Hi! This was closed. Team: If this was fixed, please add
phase/solved. Otherwise, please add one of theno/*labels.