Skip to content

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

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

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

Conversation

@iliaal

@iliaal iliaal commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Mutating an element's class through the reflected className property, classList mutations, or removing attributes via 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. This invalidates the node list caches at each of these mutation points, matching what setAttribute() already does via dom_attr_value_will_change(). Other attribute write paths (Attr::$value, setAttributeNode, 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, matching what setAttribute() already does through
dom_attr_value_will_change(). Sibling audit: Attr:: writes,
setAttribute(), setAttributeNode() and setAttributeNS() were verified to
already invalidate; php_dom_ns_compat_mark_attribute() only mirrors
namespace declarations during reconciliation and is not user-visible.
@iliaal iliaal closed this Aug 24, 2026
@iliaal iliaal reopened this Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant