79387951

Date: 2025-01-26 04:10:34
Score: 0.5
Natty:
Report link

what about delaying the reading of the target.attribute value with setTimeout, works rather consistently for me:

const observer = new MutationObserver(records => {
    for (const record of records) {
        if (record.type !== 'attributes') continue

        setTimeout( 
            function(delayedRecord) { 
                handleAttributeChange(
                    delayedRecord.attributeName!,
                    delayedRecord.oldValue,
                    delayedRecord.target.attributes.getNamedItem (delayedRecord.attributeName).value
                )
            }, 0, record )
    }
})

I've found that setting the timeout delay for 0ms runs the code in the next tick - usually when the attribute value has been updated.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): what
  • Low reputation (1):
Posted by: Sp8cestation Crew