···4949}
5050function morphAttributes(element, ref, context) {
5151 // Remove any excess attributes from the element that aren’t present in the reference.
5252- for (const { name } of element.attributes) ref.hasAttribute(name) || element.removeAttribute(name);
5252+ for (const { name, value } of element.attributes) {
5353+ if (!ref.hasAttribute(name) && (context.beforeAttributeUpdated?.({ attributeName: name, newValue: null, element }) ?? true)) {
5454+ element.removeAttribute(name);
5555+ context.afterAttributeUpdated?.({ attributeName: name, previousValue: value, element });
5656+ }
5757+ }
5358 // Copy attributes from the reference to the element, if they don’t already match.
5459 for (const { name, value } of ref.attributes) {
5560 const previousValue = element.getAttribute(name);
+7-2
src/morphlex.ts
···4747 element,
4848 }: {
4949 attributeName: string;
5050- newValue: string;
5050+ newValue: string | null;
5151 element: Element;
5252 }) => boolean;
5353···146146147147function morphAttributes(element: Element, ref: ReadonlyNode<Element>, context: Context): void {
148148 // Remove any excess attributes from the element that aren’t present in the reference.
149149- for (const { name } of element.attributes) ref.hasAttribute(name) || element.removeAttribute(name);
149149+ for (const { name, value } of element.attributes) {
150150+ if (!ref.hasAttribute(name) && (context.beforeAttributeUpdated?.({ attributeName: name, newValue: null, element }) ?? true)) {
151151+ element.removeAttribute(name);
152152+ context.afterAttributeUpdated?.({ attributeName: name, previousValue: value, element });
153153+ }
154154+ }
150155151156 // Copy attributes from the reference to the element, if they don’t already match.
152157 for (const { name, value } of ref.attributes) {