fix: Explicitly handle null attribute values (#1157)

* fix: Explicitly handle removed attributes

The attribute `value` can be null when a mutation observer triggers due to a removed attribute. This is currently not reflected by types and code.

* Apply formatting changes

* fix

* add changeset
This commit is contained in:
Francesco Novy
2026-04-01 12:00:00 +08:00
committed by GitHub
parent 7dca0f37c4
commit 8b55751a40
7 changed files with 256 additions and 15 deletions

View File

@@ -149,7 +149,7 @@ function buildNode(
* They often overwrite other attributes on the element.
* We need to parse them last so they can overwrite conflicting attributes.
*/
const specialAttributes: attributes = {};
const specialAttributes: { [key: string]: string | number } = {};
for (const name in n.attributes) {
if (!Object.prototype.hasOwnProperty.call(n.attributes, name)) {
continue;
@@ -165,6 +165,11 @@ function buildNode(
continue;
}
// null values mean the attribute was removed
if (value === null) {
continue;
}
/**
* Boolean attributes are considered to be true if they're present on the element at all.
* We should set value to the empty string ("") or the attribute's name, with no leading or trailing whitespace.