Skip to content
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

Rounded widths and heights #61

Closed
DrewVartanian opened this issue Feb 9, 2021 · 4 comments
Closed

Rounded widths and heights #61

DrewVartanian opened this issue Feb 9, 2021 · 4 comments
Labels

Comments

@DrewVartanian
Copy link

Would it be possible to use getBoundingClientRect() to measure widths and heights, so that the values are not rounded? I have run into situations where not having the floating-point values has caused issues when using those measurements. If there is a situation where users may want the rounded value that I am not thinking of, then having an option to get the floating-point values would also work.

@ZeeCoder
Copy link
Owner

There's something in the works for this, I'm just way to strained to take a proper look. :(

See also: #46 (comment)

We're not using getBoundingClientRect as one of the big selling points to using uRO is it not triggering a layout in the browser like getBoundingClientRect does.

@DrewVartanian
Copy link
Author

@ZeeCoder Don't worry at all about not being able to get to this. You are in no way obligated to do anything here, and I appreciate you taking the time to respond in the first place.

Just for posterity's sake, I'm going to include my current work around, in case it helps eventually solve this issue, or provides help to anyone else who is facing it. I am currently getting a width from the useResizeObserver, and use that width as a dependent in my useEffect hook, where I am reacting to the change. In that useEffect hook, after checking to make sure the ref provided too useResizeObserver has an element at current, I get the non rounded width with ref.current.getBoundingClientRect().width. This means that my component will react to changes in the rounded width, and use the floating-point width for my calculations. While this obviously is not perfect, as it will not respond to width changes that are small enough that don't change the rounded width, for my use case it is more than good enough.

Two last caveat to leave behind for other people to consider, and possible explain if they understand better. First, I do not completely understand the issue of "uRO is it not triggering a layout in the browser like getBoundingClientRect does", and thus any issues that come out of that fact are not taking into consideration in my solution above. Second, an alternative too using getBoundingClientRect seems to be getComputedStyle, as in parseFloat(window.getComputedStyle(ref.current).width). This also provides a floating-point value for the width, although the number is slightly different from that obtained by getBoundingClientRect. As for the cause of the difference, and any other differentiating aspect of the two methods, I don't have good enough understanding to offer an explanation. That said, hopefully this helps anyone who is facing this issue or looking to create a PR on this library, as a point of reference.

@ZeeCoder
Copy link
Owner

@DrewVartanian really appreciate you taking the time to write all that feedback. 👌
If you're interested, a good starting point to learn about the performance issues about "layout trashing" could be this.

ZeeCoder added a commit that referenced this issue Aug 28, 2021
ZeeCoder added a commit that referenced this issue Aug 28, 2021
ZeeCoder added a commit that referenced this issue Aug 28, 2021
github-actions bot pushed a commit that referenced this issue Aug 28, 2021
# [7.1.0](v7.0.1...v7.1.0) (2021-08-28)

### Bug Fixes

* The `onResize` callback is no longer incorrectly called with the same values. ([29938a1](29938a1))

### Features

* Added the `box` option ([f873597](f873597)), closes [#31](#31) [#57](#57)
* Added the `round` option. ([1224bc8](1224bc8)), closes [#55](#55) [#46](#46) [#61](#61)
ZeeCoder added a commit that referenced this issue Aug 28, 2021
ZeeCoder pushed a commit that referenced this issue Aug 28, 2021
# [7.1.0](v7.0.1...v7.1.0) (2021-08-28)

### Bug Fixes

* The `onResize` callback is no longer incorrectly called with the same values. ([29938a1](29938a1))

### Features

* Added the `box` option ([f873597](f873597)), closes [#31](#31) [#57](#57)
* Added the `round` option. ([1224bc8](1224bc8)), closes [#55](#55) [#46](#46) [#61](#61)
github-actions bot pushed a commit that referenced this issue Aug 28, 2021
# [8.0.0](v7.0.1...v8.0.0) (2021-08-28)

### Bug Fixes

* Removed `resize-observer-polyfill` in favour of `@juggle/resize-observer`. ([8afc8f6](8afc8f6))
* The `onResize` callback is no longer incorrectly called with the same values. ([bd0f3c8](bd0f3c8))

### Features

* Added the `box` option ([0ca6c23](0ca6c23)), closes [#31](#31) [#57](#57)
* Added the `round` option. ([aa38199](aa38199)), closes [#55](#55) [#46](#46) [#61](#61)
* Triggering the v8 release ([4373a1f](4373a1f))

### BREAKING CHANGES

* Triggering the v8 release, which was published as 7.1.0 by accident.
@github-actions
Copy link

🎉 This issue has been resolved in version 8.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Repository owner deleted a comment from github-actions bot Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants