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

useMeasure does not update when rendering an element conditionally #755

Closed
andbjer opened this issue May 12, 2022 · 3 comments · Fixed by #759
Closed

useMeasure does not update when rendering an element conditionally #755

andbjer opened this issue May 12, 2022 · 3 comments · Fixed by #759
Assignees
Labels
🪲 bug Something isn't working released

Comments

@andbjer
Copy link

andbjer commented May 12, 2022

Prior Issues

No prior issues

What is the current behavior?

useMeasure does not update when rendering an element conditionally.

Steps to Reproduce

When using the ref returned by useMeasure on an element that is rendered conditionally the measurements are not updated when the ref.current updates.

I believe the issue is in the useResizeObserver where ref.current is not added to the dependency list, hence the useEffect is not triggered when the ref updates.

Here's a simple reproduction

What is the expected behavior?

The values returned from useMeasure should be updated if the current prop of the ref changes.

Environment Details

  • @react-hookz/web version: 13.2.1
  • react version: 17.0.2
  • react-dom version: 17.0.2
  • typescript version: 4.6.3
  • OS: macOS Monterey (12.3.1)
  • Browser: Google Chrome Version 101.0.4951.64
  • Did this work in previous versions? No
@xobotyi xobotyi self-assigned this May 12, 2022
@xobotyi xobotyi added the 🪲 bug Something isn't working label May 12, 2022
github-actions bot pushed a commit that referenced this issue May 12, 2022
## [14.2.2](v14.2.1...v14.2.2) (2022-05-12)

### Bug Fixes

* `useResizeObserver` now respects element changes within ref object ([#759](#759)) ([2a4e848](2a4e848)), closes [#755](#755)
@xobotyi
Copy link
Contributor

xobotyi commented May 12, 2022

🎉 This issue has been resolved in version 14.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Spaubleit
Copy link

The problem is still exist. You can check it if you change library version in provided reproduction sandbox. https://codesandbox.io/s/usemeasure-bug-forked-9umt38

@xobotyi xobotyi reopened this Jun 30, 2022
xobotyi added a commit that referenced this issue Jun 30, 2022
github-actions bot pushed a commit that referenced this issue Jun 30, 2022
## [14.5.1](v14.5.0...v14.5.1) (2022-06-30)

### Bug Fixes

* **useMeasure:** support conditional rendering ([76ac155](76ac155)), closes [#755](#755)
@xobotyi
Copy link
Contributor

xobotyi commented Jun 30, 2022

🎉 This issue has been resolved in version 14.5.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working released
Development

Successfully merging a pull request may close this issue.

3 participants