Skip to content

fix: hide an attribute with a null bound value from getAttributeNames - #25818

Open
totally-not-ai[bot] wants to merge 2 commits into
mainfrom
23887-bind-boolean-attribute
Open

totally-not-ai[bot] wants to merge 2 commits into
mainfrom
23887-bind-boolean-attribute

Conversation

@totally-not-ai

Copy link
Copy Markdown
Contributor

Summary

When an attribute is bound to a signal and the signal value becomes null, the attribute is no longer set — but getAttributeNames() still listed it. It is now left out, so it matches what getAttribute() and hasAttribute() already report.

What changed

Behavior change: Element.getAttributeNames() no longer returns the name of an attribute whose bound signal value is null. This only affects code using attribute bindings (bindAttribute); attributes set the normal way are not touched. Code that relied on the old (inconsistent) listing will see one fewer name.

ElementAttributeMap.attributes() now filters the keys by has(...). A binding keeps its key in the map while the value is null so that the binding stays alive, and that key is now skipped when listing names.

Fixes #23887.

Test summary

  • Binding a Signal<Boolean> mapped to "" / null: while the value is "", the attribute is readable, reported as present, and listed among the attribute names.
  • When the signal turns the attribute off, it is absent from getAttribute, hasAttribute, and now also from getAttributeNames.
  • Toggling the signal back on restores the attribute in all three, confirming the binding survives.

Binding a Signal<Boolean> to an attribute today requires mapping it to
"" / null. The attribute is then correctly absent from getAttribute and
hasAttribute, but getAttributeNames still lists it. The added assertions
fail, documenting the gap behind #23887.
A signal binding keeps its key in ElementAttributeMap while the signal
value is null so that the binding survives, and getAttribute and
hasAttribute already treat that as "not set". getAttributeNames listed
the key anyway, so an attribute toggled off through its binding still
showed up among the attribute names.
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 1 455 files  ±0   1 539 suites  ±0   1h 28m 3s ⏱️ - 1m 7s
11 939 tests ±0  11 871 ✅ ±0  68 💤 ±0  0 ❌ ±0 
12 257 runs  ±0  12 189 ✅ ±0  68 💤 ±0  0 ❌ ±0 

Results for commit 2900281. ± Comparison against base commit 3eaccc5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support binding Signal<Boolean> with attributes

0 participants