Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

CSS: Don't automatically add "px" to properties with a few exceptions#4055

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mgol merged 1 commit intojquery:masterfrommgol:css-no-autopx-v2
Apr 8, 2019

Conversation

mgol
Copy link
Member

@mgolmgol commentedApr 24, 2018
edited by timmywil
Loading

Summary

Don't automatically add "px" to properties with a few exceptions

Fixesgh-2795
Refgh-4009

This is an alternative to PR#4053.

Const over#4053:

Pros over#4053:

  • it only adds1 byte 6 bytes instead of 120

Checklist

deepsea887 and sanganinamrata reacted with laugh emoji
@mgolmgol added this to the4.0.0 milestoneApr 24, 2018
@mgolmgol requested a review fromdmethvinApril 24, 2018 08:32
@mgolmgolforce-pushed thecss-no-autopx-v2 branch 3 times, most recently froma1c0a1e to096afcfCompareApril 24, 2018 08:41
Copy link
Member

@dmethvindmethvin left a comment

Choose a reason for hiding this comment

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

LGTM, just the comment change

src/css.js Outdated
@@ -247,7 +231,7 @@ jQuery.extend( {

// If a number was passed in, add the unit (except for certain CSS properties)
Copy link
Member

Choose a reason for hiding this comment

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

Comment should be changed as well, something likeIf the value is a number, addpx for certain CSS properties.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Nice catch; changed.

// |-+-| Border |-+-+-| Bottom |-+-|-+-| |-+-END
// | \ Padding / \ Left / | \ Height /
// | |
// BEGIN -| /---------\ |
Copy link
Member

Choose a reason for hiding this comment

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

This does recognize some strings that are not currently CSS properties (like PaddingLeftWidth) but it's safe to assume they willnever be CSS properties. Besides it only comes into play if a number is passed in.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Hmm,border is a little special here in that it differs frommargin andpadding. I could try extracting it but we'll end up with more than +1 byte then. ;)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

There are also others non-existing values liketopWidth. That's not ideal but the important part is the list is finite and not that large.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I worry it also matchesmin &max - there are no such things in CSS but I wouldn't be surprised if they were added; it'd be worth to exclude them.

@mgolmgol changed the titleCSS: Don't automatically add "px" to properties with a few exceptionsWIP CSS: Don't automatically add "px" to properties with a few exceptionsApr 24, 2018
@mgolmgolforce-pushed thecss-no-autopx-v2 branch 2 times, most recently fromcd5c18a tob15c36bCompareApril 24, 2018 13:34
@mgol
Copy link
MemberAuthor

mgol commentedApr 24, 2018
edited
Loading

@dmethvin I updated the regexp (again). It now adds7 6 bytes instead of 1 but I think it catches exactly what we want and nothing else. :) I updated the graph for the regex as well.

@mgolmgolforce-pushed thecss-no-autopx-v2 branch 5 times, most recently from55af87f to9dcc840CompareApril 25, 2018 07:56
@dmethvin
Copy link
Member

Nice!


// Starting value computation is required for potential unit mismatches
initialInUnit = ( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) &&
initialInUnit = elem.nodeType &&
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Without this change, effects tests were failing on non-element objects on ana property. I've noticed they were already failing ifa was changed to anything fromjQuery.cssNumber and this PR makes almost everything "like fromjQuery.cssNumber".

ThenodeType check should most likely already be there, perhaps we should add it for 3.4.0 as well?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, ugh. Put another way, we only want to add "px" to property values if they're on DOM elements. I still wish we hadn't supported animating plain objects,.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I extracted this change to PR#4061.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

#4601 landed, this PR rebased so this particular change is no longer a part of this PR.

mgol added a commit to mgol/jquery that referenced this pull requestApr 26, 2018
mgol added a commit to mgol/jquery that referenced this pull requestApr 26, 2018
Without this change animating properties from jQuery.cssNumber on non-elementsthrows an error.Refjquerygh-4055
// The first test is used to ensure that:
// 1. The prop starts with a lowercase letter (as we uppercase it for the second regex).
// 2. The prop is not empty.
return /^[a-z]$/.test( prop[ 0 ] ) &&
Copy link
Member

Choose a reason for hiding this comment

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

Having a function is fine, but we should continue with the convention of creating regexes once outside of functions.

mgol and gvanderest reacted with thumbs up emoji
mgol added a commit that referenced this pull requestApr 30, 2018
Without this change animating properties from jQuery.cssNumber on non-elementsthrows an error.Refgh-4055Closesgh-4061
Copy link
Member

@gibson042gibson042 left a comment

Choose a reason for hiding this comment

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

It would be nice to see explicit tests covering "px" appending for these 14 + 6 + 10 properties and non-appending for other properties (both real ones like "line-height" and similarly-named fakes like "MarginLeftWidth" and "BorderTopHeight").

// The first test is used to ensure that:
// 1. The prop starts with a lowercase letter (as we uppercase it for the second regex).
// 2. The prop is not empty.
return /^[a-z]$/.test( prop[ 0 ] ) &&
Copy link
Member

Choose a reason for hiding this comment

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

Small savings here by replacing/^[a-z]$/.test( prop[ 0 ] ) with/^[a-z]/.test( prop ).

mgol reacted with thumbs up emoji
// 1. The prop starts with a lowercase letter (as we uppercase it for the second regex).
// 2. The prop is not empty.
return /^[a-z]$/.test( prop[ 0 ] ) &&
/^(?:((?:Margin|Padding)?(?:Top|Right|Bottom|Left)?)|(?:Min|Max)?(?:Width|Height)|Border(?:Top|Right|Bottom|Left)?(?:Width)?)$/.test( prop[ 0 ].toUpperCase() + prop.substr( 1 ) );
Copy link
Member

Choose a reason for hiding this comment

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

Moderate savings here by replacingprop.substr( 1 ) withprop.slice( 1 ), and small savings by changing the order of alternatives. Suggested gzip-friendly representation:

/^(?:Border(?:Top|Right|Bottom|Left)?(?:Width|)|(?:Margin|Padding)?(?:Top|Right|Bottom|Left)?|(?:Min|Max)?(?:Width|Height))$/.test(prop[0].toUpperCase()+prop.slice(1))

@mgol
Copy link
MemberAuthor

It would be nice to see explicit tests covering "px" appending for these 14 + 6 + 10 properties and non-appending for other properties (both real ones like "line-height" and similarly-named fakes like "MarginLeftWidth" and "BorderTopHeight").

I intend to write the test for all matched props (I'll take the list from#4053) and add a few negative ones to the props from outside of the set. I just haven't gotten to it yet.

Thanks for the size reduction tips, I'll try them!

@mgol
Copy link
MemberAuthor

mgol commentedApr 30, 2018
edited
Loading

PR updated, tests were added, all remarks by@timmywil &@gibson042 addressed.

Thanks to@gibson042's clever remarks we're now down from +6 bytes to -9. 😲

@mgol
Copy link
MemberAuthor

@gibson042

It would be nice to see explicit tests covering "px" appending for these 14 + 6 + 10 properties and non-appending for other properties (both real ones like "line-height" and similarly-named fakes like "MarginLeftWidth" and "BorderTopHeight").

Most of these were added but it's hard to test fake ones as the browser throws them away so there's no observable effect.

@mgolmgol changed the titleWIP CSS: Don't automatically add "px" to properties with a few exceptionsCSS: Don't automatically add "px" to properties with a few exceptionsMay 1, 2018
@mgol
Copy link
MemberAuthor

mgol commentedJun 4, 2018

PR rebased with a revert of the fix from PR#4064 as it's no longer needed when we switch to the whitelist.

-7 bytes as of now (compared to master @75b77b4).

@timmywil are your concerns resolved? Your re-review is needed.

@timmywil
Copy link
Member

@mgol yes, that addressed my concern.

@mgolmgolforce-pushed thecss-no-autopx-v2 branch 2 times, most recently fromd3458b9 toad41ce9CompareMarch 11, 2019 19:04
@mgol
Copy link
MemberAuthor

mgol commentedApr 8, 2019

Good news, suddenly it got down to -45 bytes compared to currentmaster (c4f2fa2).

@mgolmgol merged commit00a9c2e intojquery:masterApr 8, 2019
@mgolmgol deleted the css-no-autopx-v2 branchApril 8, 2019 17:31
@mgolmgol mentioned this pull requestApr 17, 2019
2 tasks
@locklockbot locked asresolvedand limited conversation to collaboratorsOct 5, 2019
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@dmethvindmethvindmethvin approved these changes

@timmywiltimmywiltimmywil approved these changes

@gibson042gibson042gibson042 approved these changes

Assignees
No one assigned
Milestone
4.0.0
Development

Successfully merging this pull request may close these issues.

Stop appendingpx to everything except a blocklist?
4 participants
@mgol@dmethvin@timmywil@gibson042

[8]ページ先頭

©2009-2025 Movatter.jp