@@ -118,9 +118,15 @@ function getWidthOrHeight( elem, dimension, extra ) {
118118
119119 // Start with computed style
120120 var styles = getStyles ( elem ) ,
121- val = curCSS ( elem , dimension , styles ) ,
122- isBorderBox = jQuery . css ( elem , "boxSizing" , false , styles ) === "border-box" ,
121+
122+ // To avoid forcing a reflow, only fetch boxSizing if we need it (gh-4322).
123+ // Fake content-box until we know it's needed to know the true value.
124+ boxSizingNeeded = ! support . boxSizingReliable ( ) || extra ,
125+ isBorderBox = boxSizingNeeded &&
126+ jQuery . css ( elem , "boxSizing" , false , styles ) === "border-box" ,
123127 valueIsBorderBox = isBorderBox ,
128+
129+ val = curCSS ( elem , dimension , styles ) ,
124130 offsetProp = "offset" + dimension [ 0 ] . toUpperCase ( ) + dimension . slice ( 1 ) ;
125131
126132 // Support: Firefox <=54
@@ -141,10 +147,13 @@ function getWidthOrHeight( elem, dimension, extra ) {
141147 // Also use offsetWidth/offsetHeight for when box sizing is unreliable
142148 // We use getClientRects() to check for hidden/disconnected.
143149 // In those cases, the computed value can be trusted to be border-box
144- if ( ( isBorderBox && ! support . boxSizingReliable ( ) || val === "auto" ||
150+ if ( ( ! support . boxSizingReliable ( ) && isBorderBox ||
151+ val === "auto" ||
145152 ! parseFloat ( val ) && jQuery . css ( elem , "display" , false , styles ) === "inline" ) &&
146153 elem . getClientRects ( ) . length ) {
147154
155+ isBorderBox = jQuery . css ( elem , "boxSizing" , false , styles ) === "border-box" ;
156+
148157 // Where available, offsetWidth/offsetHeight approximate border box dimensions.
149158 // Where not available (e.g., SVG), assume unreliable box-sizing and interpret the
150159 // retrieved value as a content box dimension.
0 commit comments