-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Dimensions: ignore transforms when retrieving width/height #3561
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, thanks for your PR! By analyzing the history of the files in this pull request, we identified @markelog, @jeresig and @brandonaaron to be potential reviewers. |
src/css.js
Outdated
| if ( elem.getClientRects().length ) { | ||
| val = elem.getBoundingClientRect()[ name ]; | ||
| // Fall back to uncomputed css if necessary | ||
| if ( val < 0 || val == null ) { |
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.
This is dead code. curCSS will always get you a string so these conditions will always be false. curCSS will already get the inline style if the computed one is an empty string so this condition is already covered there.
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.
Isn't that a change for another ticket? This is legacy code that I left alone. I just wonder why this has been here so long if it wasn't necessary.
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.
It seems I forgot to simplify it when I migrated the code to use getBoundingClientRect.
That said, this is related to this PR - in my PR I should have just changed val <= 0 || val == null to val === nullas the code inside would be used in those cases, only the val <= 0 condition was never true. In your PR this becomes true dead code and since you even had to change this condition for the new logic to work, I think this should be removed here.
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.
you even had to change this condition for the new logic to work
I did? It seems to me the logic is the same.
Before:
- Try
getBoundingClientRect - If negative, zero, null, or undefined, try
getCSS. - If negative, null, or undefined, get inline style.
After:
- Try
getCSS - If negative, null, or undefined, get inline style.
Maybe I'm misunderstanding something, but it seems clear to me I haven't changed that condition.
That said, you may be right about this condition being dead code previously as well. I can check that and include it in this PR, but I still believe it is a separate ticket. At the very least, a separate commit.
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.
Ok, did some testing in Chrome and IE9. Yup, this looks like dead code, but I do believe it was dead code before this PR as well. I'll include it here, but as a separate commit.
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.
To sum up, since by changing getBoundingClientRect to getCSS the condition inside the if became always false while it wasn't that way before, I think the removal belongs in the same commit as the initial refactor.
Not that it's terribly important, though. :)
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 condition val <= 0 was made more strict: val < 0.
That was a different condition. The diff might make it look that way. If you look closer, you'll notice the condition with val <= 0 was completely removed because it was checking the result from getBoundingClientRect, which was also removed. The val < 0 condition was already there checking the result from getCSS, which we now do first.
By changing what's initially tried from getBoundingClientRect to getCSS you eliminated the possibility of the value not being defined.
This was essentially true before. Again, this condition was already there after getCSS.
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.
But I agree this is moot now since I've removed the condition. You approve now right?
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.
diff?w=1 might make my point more clear.
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.
Ahh, yeah, I totally mixed those two, you're right! They're so close to each other and somehow I didn't notice. 😄
LGTM then!
- getCSS already falls back to inline styles
- getCSS already falls back to inline styles Ref jquerygh-3561
gibson042
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.
I guess my comments mirror @mgol's observations about dead code. As for the other refactoring, I was referencing #3193 (comment) and suggesting that we introduce methods like .contentBoxWidth/.paddingBoxWidth/.borderBoxWidth/.marginBoxWidth. It can definitely wait for later.
| val = elem.getBoundingClientRect()[ name ]; | ||
| // Computed unit is not pixels. Stop here and return. | ||
| if ( rnumnonpx.test( val ) ) { | ||
| return val; |
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.
Out of curiosity, when does this happen?
| // Check for style in case a browser which returns unreliable values | ||
| // for getComputedStyle silently falls back to the reliable elem.style | ||
| valueIsBorderBox = isBorderBox && | ||
| ( support.boxSizingReliable() || val === elem.style[ name ] ); |
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.
Since you deleted the "uncomputed" block above, I think the elem.style branch can be dropped.
|
This PR introduced a big regression: it broke |
Fixes gh-3193
Summary
getBoundingClientRectingetWidthOrHeight. This is a stopgap that retrieves width/height ignoring transforms, without resorting tooffsetWidth/Height, and without breaking existing tests.Checklist