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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user