🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@jbedard
Copy link
Contributor

@jbedard jbedard commented Mar 14, 2018

  • this avoids forcing a reflow in some cases

Fixes #3991

 raw     gz Compared to 3991 @ 625e19cd9be4898939a7c40dbeb2b17e40df9d54
+147    +63 dist/jquery.js
 +12    +12 dist/jquery.min.js

Adds a bit of size but I think it's worth it...

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.

I like it


// Only fetch boxSizing if required to avoid forcing a reflow (gh-3991)
isBorderBox = ( extra || scrollBoxSize ) &&
jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
Copy link
Member

Choose a reason for hiding this comment

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

I like what the code is doing, but the reasons could be a little more clear. Suggestion to improve that (and reduce size a little bit as well):

diff --git i/src/css.js w/src/css.js
index fc000be..d7181f4 100644
--- i/src/css.js
+++ w/src/css.js
@@ -380,8 +380,9 @@ jQuery.each( [ "height", "width" ], function( i, dimension ) {
 				styles = getStyles( elem ),
 				scrollBoxSize = support.scrollboxSize() === styles.position,
 
-				// Only fetch boxSizing if required to avoid forcing a reflow (gh-3991)
-				isBorderBox = ( extra || scrollBoxSize ) &&
+				// To avoid forcing a reflow, only fetch boxSizing if we need it (gh-3991)
+				boxSizingNeeded = scrollBoxSize || extra,
+				isBorderBox = boxSizingNeeded &&
 					jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
 				subtract = extra && boxModelAdjustment(
 					elem,
@@ -393,7 +394,7 @@ jQuery.each( [ "height", "width" ], function( i, dimension ) {
 
 			// Account for unreliable border-box dimensions by comparing offset* to computed and
 			// faking a content-box to get border and padding (gh-3699)
-			if ( scrollBoxSize && isBorderBox ) {
+			if ( isBorderBox && scrollBoxSize ) {
 				subtract -= Math.ceil(
 					elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ] -
 					parseFloat( styles[ dimension ] ) -

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That reduces size? Interesting, I thought an extra var would do the opposite...

I agree that is clearer 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding the var and changing the comment:

   +38    +11 dist/jquery.js
     =      = dist/jquery.min.js

Then changing the order in the if:

   raw     gz Compared to last run
     =     -1 dist/jquery.js
     =      = dist/jquery.min.js

So it didn't really change the size at all (but does make it more readable, so 👍)... @gibson042 is that the results you were getting?

Copy link
Member

Choose a reason for hiding this comment

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

I don't remember exactly, but this looks good to me.

- this avoids forcing a reflow in some cases

Fixes jquery#3991
@jbedard jbedard merged commit 73d7e62 into jquery:master Mar 25, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Sep 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants