Repository navigation
Description
(Sonnet 5.5)
Suggested for 1.4.0.
When a boolean attribute is bound to a string, such as :disabled="'false'", citry check tells the author to "Bind a JavaScript boolean instead, such as :disabled="false"". That advice works for most names. For seven names it does not turn the attribute off.
Example
<input type="checkbox" :switch="'false'">
citry.template.invalid-attribute-value reports that switch is on whenever it is present and suggests :switch="false". An author who follows the advice gets switch="false" in the page, and the browser reads that as on.
Affected names
BOOLEAN_ATTRIBUTES in packages/py/citry/citry/_html_attribute_values.py holds 31 names, generated from the HTML Standard. Vue's own boolean list holds 26 names, and 24 of the 31 are in it. The other seven are the ones where the advice is wrong:
switchoninput. The HTML tables refresh for 1.3.0 adds it, which is how this showed up in review.alphaoninput.headingreseton any element.shadowrootclonable,shadowrootcustomelementregistry,shadowrootdelegatesfocusandshadowrootserializableontemplate.
How Vue's client renderer treats false on these names
I read @vue/runtime-dom 3.5.44 (patchProp, shouldSetAsProp, patchAttr) and ran it. For a bound false:
- If the element has a DOM property with the attribute's name (
name in el), Vue sets that property tofalse. A property that reflects a boolean attribute removes the attribute. - Otherwise
patchAttrruns, and only seven names get boolean treatment there (itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly). Every other name goes throughsetAttribute(name, false), which writes the textfalse. Onlynullandundefinedremove the attribute.
I mounted <tag :name="value"> with Vue 3.5.44's global build in Playwright 1.65.0 browsers. Results for false, and for the two values that behave the same everywhere:
| Name (element) | Chromium 158 | Firefox 159 | WebKit 27.2 |
|---|---|---|---|
switch (input) |
switch="false" |
switch="false" |
removed (input.switch exists) |
alpha (input) |
alpha="false" |
alpha="false" |
removed (input.alpha exists) |
headingreset (div) |
headingreset="false" |
headingreset="false" |
headingreset="false" |
the four shadowroot* (template) |
="false" |
="false" |
="false" |
disabled, hidden, novalidate (control) |
removed | removed | removed |
In all three browsers, null and undefined remove all seven attributes, and '' writes the bare attribute (on). A bound string 'false' on a control such as disabled writes the bare attribute, which is what the existing advice is about.
What the server writes
I read this in the source and did not render it, because the citry-core build I had has no Vue module.
server_attributeincrates/citry_vue_compiler/src/server_render.rsleaves an attribute out forfalseonly for the 26 names inBOOLEAN_ATTRIBUTESthere. Every other name goes toattribute_text, which writesfalseas text. So the server writesswitch="false",headingreset="false"and the fourshadowroot*the same way, which matches Chromium and Firefox.crates/citry_vue_compiler/src/dom_members.rsmarksalphaoninputasUnknown, so the server reports it cannot predict the attribute, instead of writing text.dom_members.rshas no entry forswitch. WebKit 27.2 already hasinput.switch, so there the client render would remove the attribute where the server wroteswitch="false". The next refresh of that table may pick it up.
Proposed fix
Give these seven names different advice in the boolean-binding variant of the message: bind null or undefined to leave the attribute off and '' to turn it on, such as :switch="on ? '' : null", or use v-if to render the element with and without it. Keep the current advice for the 24 names in Vue's list. The plain boolean variant ("leave it out to turn it off") is correct for every name.
Pieces to change:
- The lint needs to know which names are in Vue's boolean list. A set kept in
scripts/generate_html_attribute_values.pyand written into the generated module fits how the other hand-kept lists work, and a test should compare it withBOOLEAN_ATTRIBUTESinserver_render.rsso the two cannot drift. - The rule is in
packages/py/citry/citry/analysis.py(theboolean-bindingbranch of the attribute-value check). The message text is inpackages/protocol/diagnostics/v1/catalog.json, and_diagnostic_catalog.pyfollows it. - A test per variant, with
:switch="'false'"for the new advice and:disabled="'false'"for the current one.
This changes a message only, so it is not a 1.x break.
🤖 Generated with Claude Code
Activity