8000 Selector: Make `selector.js` module depend on `attributes/attr.js` by mgol · Pull Request #5384 · jquery/jquery · GitHub
[go: up one dir, main page]

Skip to content

Selector: Make selector.js module depend on attributes/attr.js #5384

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

Merged
merged 2 commits into from
Jan 12, 2024

Conversation

mgol
Copy link
Member
@mgol mgol commented Jan 4, 2024

Summary

This fixes custom builds using the --include switch that don't include the attributes module.

Note: as of this change, jQuery.expr.match.bool is no longer defined.

Fixes gh-5379

Checklist

@mgol mgol added Selector Needs review Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labels Jan 4, 2024
@mgol mgol self-assigned this Jan 4, 2024
@mgol mgol changed the title Selector: Eliminate selector.js depenencies from various modules Selector: Make selector.js module depend on attributes/attr.js Jan 4, 2024
@mgol
Copy link
Member Author
mgol commented Jan 4, 2024

The size report for this is pretty surprising...

main @e8b7db4b0f1e1b8e08578641b30a92b955ccc4ec
   raw     gz Filename
   -51    +51 dist/jquery.min.js
   -47     +8 dist/jquery.slim.min.js
   -51    +51 dist-module/jquery.module.min.js
   -47    +10 dist-module/jquery.slim.module.min.js

I could use some gzip magic from @gibson042 here. 😉

@mgol mgol force-pushed the selector-attr-dependency branch from 91fa203 to 2a54f5d Compare January 4, 2024 00:35
@mgol
Copy link
Member Author
mgol commented Jan 4, 2024

After the latest changes:

main @e8b7db4b0f1e1b8e08578641b30a92b955ccc4ec
   raw     gz Filename
   -68    +37 dist/jquery.min.js
   -64    -10 dist/jquery.slim.min.js
   -68    +37 dist-module/jquery.module.min.js
   -64     -8 dist-module/jquery.slim.module.min.js

+37 bytes is still significant for something that in theory should remove bytes.

@mgol mgol force-pushed the selector-attr-dependency branch 2 times, most recently from 36c55f1 to f192303 Compare January 4, 2024 10:50
This fixes custom builds using the `--include` switch that don't include
the `attributes` module.

Fixes jquerygh-5379
@mgol mgol force-pushed the selector-attr-dependency branch from f192303 to d7557b0 Compare January 4, 2024 10:52
@mgol
Copy link
Member Author
mgol commented Jan 4, 2024

OK, without the addition of a dependency on attributes/attr.js to selector.js the size difference is as follows:

main @e8b7db4b0f1e1b8e08578641b30a92b955ccc4ec
   raw     gz Filename
   -51    -13 dist/jquery.min.js
   -51    -25 dist/jquery.slim.min.js
   -51    -16 dist-module/jquery.module.min.js
   -51    -25 dist-module/jquery.slim.module.min.js

so it looks this part is to blame.

Copy link
Member
@timmywil timmywil left a comment

Choose a reason for hiding this comment

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

LGTM

@timmywil timmywil removed the Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. label Jan 8, 2024
Comment on lines +100 to +103
jQuery.each( (
"checked selected async autofocus autoplay controls defer disabled " +
"hidden ismap loop multiple open readonly required scoped"
).split( " " ), function( _i, name ) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
jQuery.each( (
"checked selected async autofocus autoplay controls defer disabled " +
"hidden ismap loop multiple open readonly required scoped"
).split( " " ), function( _i, name ) {
// HTML boolean attributes have special behavior:
// we consider the lowercase name to be the only valid value, so
// getting (if the attribute is present) normalizes to that, as does
// setting to any non-`false` value (and setting to `false` removes the attribute).
// See https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes
jQuery.each( (
"checked selected async autofocus autoplay controls defer disabled " +
"hidden ismap loop multiple open readonly required scoped"
).split( " " ), function( _i, name ) {

Note also that our list is outdated; it is missing several boolean attributes from HTML Attributes, includes a scoped that isn't even present there, and treats hidden as boolean despite the expansion of that attribute to be an enumeration including "until-found" by whatwg/html@f5def65 .

Copy link
Member Author
@mgol mgol Jan 10, 2024

Choose a reason for hiding this comment

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

Oh, interesting. Perhaps we should update this list for 4.0 as this can be considered a breaking change.

Or we should get rid of this manual normalization, depending on users doing the right thing here. The biggest issue are possibly falsy checks on values since an empty string is also a valid value. If we're worried about compat for such things, my guess would be we could limit this list to just a few entries like checked & selected. Thoughts, @timmywil @gibson042?

EDIT: extracted to #5388, let's discuss this issue there

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 extracted the issue about the list itself into #5388; let's limit this PR to just the issue at hand and keep the list the same here.

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
@mgol mgol added this to the 4.0.0 milestone Jan 12, 2024
@mgol mgol removed the Needs review label Jan 12, 2024
@mgol mgol merged commit e06ff08 into jquery:main Jan 12, 2024
@mgol mgol deleted the selector-attr-dependency branch January 12, 2024 00:18
mgol added a commit to mgol/jquery-migrate that referenced this pull request Feb 3, 2024
In jquery/jquery#5384, `jQuery.expr.match.bool` stopped being defined and the
regex matching boolean attributes is no longer exposed. Inline it in Migrate
to avoid it crashing on jQuery 4.x.

Fixes jquerygh-495
mgol added a commit to jquery/jquery-migrate that referenced this pull request Feb 3, 2024
In jquery/jquery#5384, `jQuery.expr.match.bool` stopped being defined and the
regex matching boolean attributes is no longer exposed. Inline it in Migrate
to avoid it crashing on jQuery 4.x.

Fixes gh-495
Closes gh-496
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

Strange error behavior of event delegation when customizing jQuery
3 participants
0