Skip to content

dom: invalidate node list caches on class attribute mutations - #23501

Open
iliaal wants to merge 1 commit into
php:PHP-8.5from
iliaal:fix/aph-t6j-class-cache-85
Open

dom: invalidate node list caches on class attribute mutations#23501
iliaal wants to merge 1 commit into
php:PHP-8.5from
iliaal:fix/aph-t6j-class-cache-85

Conversation

@iliaal

@iliaal iliaal commented Aug 29, 2026

Copy link
Copy Markdown
Member

Mutating an element class through the reflected className property, classList mutations, or removeAttribute(), removeAttributeNS() and removeAttributeNode() modified the underlying attribute without bumping the document cache tag, so live collections such as getElementsByClassName() kept returning stale lengths and items afterwards. Each of these mutation points now invalidates the node list caches with php_libxml_invalidate_node_list_cache(). Attr::$value, setAttributeNode and setAttributeNS were audited and already invalidate correctly.

Reflected attribute writes such as className and id, classList
mutations, and removeAttribute()/removeAttributeNS()/removeAttributeNode()
modified attributes without bumping the document cache tag, so live
HTMLCollection caches like getElementsByClassName() kept serving stale
lengths and items. Invalidate the node list caches at every one of these
mutation points. Sibling audit: Attr:: writes, setAttribute(),
setAttributeNode() and setAttributeNS() already invalidate;
php_dom_ns_compat_mark_attribute() only mirrors namespace declarations
during reconciliation and is not user-visible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants