-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Dimensions: fix computing outerWidth on SVGs #4096
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
Conversation
timmywil
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/css.js
Outdated
|
|
||
| // Account for positive content-box scroll gutter when requested by providing computedVal | ||
| if ( !isBorderBox && computedVal >= 0 ) { | ||
| var val = elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The offsetWidth/offsetHeight comment seems misplaced now, doesn't it?
Also, a comment about why the fallback is needed (below, at line 138) would be useful, it's not clear now.
src/css.js
Outdated
|
|
||
| // Account for positive content-box scroll gutter when requested by providing computedVal | ||
| if ( !isBorderBox && computedVal >= 0 ) { | ||
| var val = elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @mgol on comment placement, and also observe that
- defining a new variable here is against our general style, and
valis an overly generic name, and- it provides little benefit anyway, since
deltawill never be modified when offsetWidth/offsetHeight is unknown (computedVal - computedVal - delta - extra - 0.5is guaranteed to be negative in this case, soMath.ceilwill not be positive, soMath.maxwill be 0).
I think we should keep things simpler:
// offsetWidth/offsetHeight is a rounded sum of content, padding, scroll gutter, and border
// Scroll gutter is that value minus the other properties, rounded half-down to the nearest integer
delta += Math.max( 0, Math.ceil(
elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ] -
computedVal -
delta -
extra -
0.5
// If offsetWidth/offsetHeight is unknown, then we can't determine content-box scroll gutter
// Use an explicit zero to avoid NaN (gh-3964)
) ) || 0;|
Updated @gibson042 I agree with everything you said. At one point the fix I had needed the var and I never really cleaned it up after. Thanks for pointing it out 👍 |
|
👋 Hey folks, are there plans to release a patch version that includes this fix? |
|
@sduquej It will be included in 3.4.0 which we'll hopefully release soon (but it's hard to predict exact timing). |
|
thanks Michał, appreciate the quick follow-up! Will keep an eye out as we're running into this issue in our app and decided to fall back to |
Fixes gh-3964
Summary
Checklist