Attributes: Support the until-found value for the hidden attribute#5607
Conversation
6ee4613 to
2aba711
Compare
|
Mentioning |
|
@gibson042 I pushed the smaller version in the second commit, you can compare the two & suggest improvements. |
gibson042
left a comment
There was a problem hiding this comment.
Compression pass:
raw gz Compared to last run
-52 -6 dist/jquery.js
-13 -17 dist/jquery.min.js
| } else if ( | ||
| name.toLowerCase() !== "hidden" || | ||
| String( value ).toLowerCase() !== "until-found" | ||
| ) { | ||
| elem.setAttribute( name, name ); | ||
| } else { | ||
| elem.setAttribute( name, value ); |
There was a problem hiding this comment.
| } else if ( | |
| name.toLowerCase() !== "hidden" || | |
| String( value ).toLowerCase() !== "until-found" | |
| ) { | |
| elem.setAttribute( name, name ); | |
| } else { | |
| elem.setAttribute( name, value ); | |
| } else { | |
| elem.setAttribute( name, name.toLowerCase() === "hidden" && | |
| strValue.toLowerCase() === "until-found" ? strValue : name ); |
(with var strValue = String( value );)
| if ( ret != null ) { | ||
| if ( lowercaseName !== "hidden" || | ||
| ret.toLowerCase() !== "until-found" | ||
| ) { | ||
| ret = lowercaseName; | ||
| } | ||
| } |
There was a problem hiding this comment.
| if ( ret != null ) { | |
| if ( lowercaseName !== "hidden" || | |
| ret.toLowerCase() !== "until-found" | |
| ) { | |
| ret = lowercaseName; | |
| } | |
| } | |
| ret = ret == null || lowercaseName === "hidden" && | |
| ret.toLowerCase() === "until-found" ? ret : lowercaseName; |
|
@gibson042 I applied your suggestions but I got a different diff compared to my second commit: I pushed it, can you have a look? The diff from |
32391cf to
e47c8b5
Compare
@mgol Confirmed your numbers; I must have been doing something slightly different before. I think we're close to a local maximum, but vs. the current state, is possible by refactoring variable declarations: boolHook = {
set: function( elem, value, name ) {
var strValue = String( value ),
lowercaseName = name.toLowerCase();
if ( value === false ) {
// Remove boolean attributes when set to false
jQuery.removeAttr( elem, name );
} else {
elem.setAttribute( name,
lowercaseName === "hidden" &&
strValue.toLowerCase() === "until-found" ?
strValue :
name
);
}
return name;
}
};
jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( _i, name ) {
var getter = attrHandle[ name ] || jQuery.find.attr;
attrHandle[ name ] = function( elem, name, isXML ) {
var ret,
lowercaseName = name.toLowerCase(),
handle = attrHandle[ lowercaseName ];
if ( !isXML ) {
// Avoid an infinite loop by temporarily removing this function from the getter
attrHandle[ lowercaseName ] = ret;
ret = getter( elem, name, isXML );
ret = ret == null ||
( lowercaseName === "hidden" && ret.toLowerCase() === "until-found" ) ?
ret :
lowercaseName;
attrHandle[ lowercaseName ] = handle;
}
return ret;
};
} ); |
The `hidden` attribute used to be a boolean one but it gained a new `until-found` eventually. This led us to change the way we handle boolean attributes in jQuery 4.0 in jquerygh-5452 to avoid these issues in the future. That said, currently from the attributes we treat as boolean only `hidden` has gained an extra value, let's support it. Ref jquerygh-5388 Ref jquerygh-5452
e47c8b5 to
9c8e3e3
Compare
|
@gibson042 I am getting a different diff for this version of |
|
I'm going to merge it as-is; feel free to submit a PR with various size improvements if you find them. |
The `hidden` attribute used to be a boolean one but it gained a new `until-found` eventually. This led us to change the way we handle boolean attributes in jQuery 4.0 in jquerygh-5452 to avoid these issues in the future. We haven't added an explicit test for the `"until-found"` value of the `hidden` attribute which triggered this decision so far, though. Backport the test from jquerygh-5607 which landed on `3.x-stable` so that we do test it. Ref jquerygh-5452 Ref jquerygh-5607 (cherry picked from commit 85290c5)
The `hidden` attribute used to be a boolean one but it gained a new `until-found` eventually. This led us to change the way we handle boolean attributes in jQuery 4.0 in jquerygh-5452 to avoid these issues in the future. We haven't added an explicit test for the `"until-found"` value of the `hidden` attribute which triggered this decision so far, though. Backport the test from jquerygh-5607 which landed on `3.x-stable` so that we do test it. Ref jquerygh-5452 Ref jquerygh-5607 (cherry picked from commit 85290c5)
The `hidden` attribute used to be a boolean one but it gained a new `until-found` eventually. This led us to change the way we handle boolean attributes in jQuery 4.0 in gh-5452 to avoid these issues in the future. We haven't added an explicit test for the `"until-found"` value of the `hidden` attribute which triggered this decision so far, though. Backport the test from gh-5607 which landed on `3.x-stable` so that we do test it. Closes gh-5619 Ref gh-5452 Ref gh-5607 (cherry picked from commit 85290c5)
Summary
The
hiddenattribute used to be a boolean one but it gained a newuntil-foundeventually. This led us to change the way we handle boolean attributes in jQuery 4.0 in gh-5452 to avoid these issues in the future.That said, currently from the attributes we treat as boolean only
hiddenhas gained an extra value, let's support it.Ref gh-5388
Ref gh-5452
The cost is currently quite high:
It's possible it could be lowered if we removed the infra for adding future attributes to the list and just mentioned
hidden&until-foundexplicitly in both the getter & setter.Another alternative is to avoid changing the
3.xline and instead add a note to the docs, showing how to define an attrHook forhiddenthat will achieve the same result.Checklist