Closed mgol closed 2 months ago
Size comparison:
main @f80e78ef3e7ded1fc693465d02dfb07510ded0ab
raw gz Filename
-30 -29 dist/jquery.min.js
-30 -26 dist/jquery.slim.min.js
-30 -25 dist-module/jquery.module.min.js
-30 -25 dist-module/jquery.slim.module.min.js
The PR - if this approach is accepted - still needs unit tests to confirm the new behavior. It is a bit reassuring that it didn't break any of our existing tests.
We've decided against this approach; closing.
Summary
The HTML spec defines boolean attributes: https://html.spec.whatwg.org/#boolean-attributes that often correlate with boolean properties. If the attribute is missing, it correlates with the
false
property value, if it's present - thetrue
property value. The only valid values are an empty string or the attribute name.jQuery tried to be helpful here and treated boolean attributes in a special way in the
.attr()
API:false
was passed; otherwise, it was ignoring the passed value and set the attribute - interestingly, in jQuery>=3
not lowercased anymore.The problem is the spec occasionally converts boolean attributes into ones with additional attribute values with special behavior - one such example is the new
"until-found"
value for thehidden
attribute. Our setter normalization means passing those values is impossible with jQuery.This patch takes a conservative approach, with backwards compatibility in mind, and makes the following changes:
false
as mean attribute removal andtrue
as setting the value to the attribute name. All the other inputs are aplied unchanged.With this change, all existing jQuery unit tests were already passing.
Checklist