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
getAttribute("class") trims the value and returns "" when absent #342
issue: getAttribute("class") should return the attribute exactly as written. linkedom strips the whitespace (" ab" → "ab") and returns "" instead of null when there is no class. Selectors see the stripped value too, so [class^=" a"] misses.
I can reproduce both halves of this on 0.18.14 and on main at e2ee208, and I can open a PR. Which fix would you take?
Only the null half.getAttribute('class') returns null when the element has no class attribute. This is one line in Element#getAttribute. We ship it as a local patch today, because a parser that falls back to a default only on null (TipTap's Link mark, for one) reads '' as "class set to empty".
Both halves. The class attribute keeps the value as written, and the token list derives from it. Today the parser (parse-from-string.js), Element#setAttribute and the setAttribute helper in shared/attributes.js all write through className, which splits the value and joins it again. So the stored Attr value is already normalized, and the selector path, which since perf: read class attribute directly in selector adapter #339 reads getAttributeNode('class')?.value ?? null, also sees "ab". A fix would store the raw value and rewrite it only when classList itself is mutated. That overlaps the parse path perf: skip the token list while parsing class attributes #336 changes, so I would rebase on it, or wait for it, whichever you prefer.
Repro on 0.18.14 (unpatched) and on main at e2ee208 (Node 24.14.1), extended with an explicit empty class:
Activity
osazemeu commentedon Oct 26, 2026
I can reproduce both halves of this on 0.18.14 and on
mainat e2ee208, and I can open a PR. Which fix would you take?nullhalf.getAttribute('class')returnsnullwhen the element has no class attribute. This is one line inElement#getAttribute. We ship it as a local patch today, because a parser that falls back to a default only onnull(TipTap's Link mark, for one) reads''as "class set to empty".parse-from-string.js),Element#setAttributeand thesetAttributehelper inshared/attributes.jsall write throughclassName, which splits the value and joins it again. So the storedAttrvalue is already normalized, and the selector path, which since perf: read class attribute directly in selector adapter #339 readsgetAttributeNode('class')?.value ?? null, also sees"ab". A fix would store the raw value and rewrite it only whenclassListitself is mutated. That overlaps the parse path perf: skip the token list while parsing class attributes #336 changes, so I would rebase on it, or wait for it, whichever you prefer.Repro on 0.18.14 (unpatched) and on
mainat e2ee208 (Node 24.14.1), extended with an explicit empty class: