Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributes: Don't warn against removeAttr if property false #484

Merged
merged 1 commit into from
Feb 23, 2023

Conversation

mgol
Copy link
Member

@mgol mgol commented Feb 22, 2023

Some frameworks, like AngularJS, invoke removeAttr on boolean attributes but only after setting the respective property to false. Such usage is not dangerous and would continue to work even after Migrate is removed. Therefore, only warn for removeAttr(booleanAttribute) if the property wasn't false already.

Fixes gh-471

@mgol mgol added this to the 3.4.1 milestone Feb 22, 2023
@mgol mgol requested a review from dmethvin February 22, 2023 14:02
Copy link
Member

@dmethvin dmethvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable to skip this if the attrprop is already false!

// something else than `false`. Otherwise, this Migrate patch
// doesn't influence the behavior and there's no need to set or warn.
self.each( function() {
if ( jQuery( this ).prop( attr ) !== false ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just use this.attr !== false here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was playing safe to not omit any possible prop hooks. We almost don't have any for boolean props... except for selected in IE:
https://github.com/jquery/jquery/blob/3.6.3/src/attributes/prop.js#L91-L125
It seems we should use the jQuery API then, shouldn't we?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I suppose we might add a prop hook so this is the safest way. 👍

Some frameworks, like AngularJS, invoke `removeAttr` on boolean attributes
but only after setting the respective property to `false`. Such usage is not
dangerous and would continue to work even after Migrate is removed. Therefore,
only warn for `removeAttr(booleanAttribute)` if the property wasn't `false`
already.

Fixes jquerygh-471
Closes jquerygh-484
@mgol mgol removed the Needs review label Feb 23, 2023
@mgol mgol merged commit 072e44d into jquery:main Feb 23, 2023
@mgol mgol deleted the removeAttr-limit-warnings branch February 23, 2023 14:34
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.

Only warn against removeAttr(booleanAttr) if property value not false
2 participants