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

feat: Add check for ResizeObserver availability to prevent reference errors #455

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

ryo-manba
Copy link
Contributor

@ryo-manba ryo-manba commented Feb 26, 2024

Summary

This PR introduces a check for the availability of ResizeObserver in the window object within our custom useResize hook. This change aims to prevent errors in environments where ResizeObserver is not defined, such as server-side rendering contexts or older browsers, and during Jest testing without specific mocks.

Background

While implementing the useResize hook for element resize observation, we encountered errors in environments lacking ResizeObserver support. Specifically, Jest tests failed with a ReferenceError: ResizeObserver is not defined, unless a mock implementation was provided:

window.ResizeObserver = jest.fn().mockImplementation(() => ({
  disconnect: jest.fn(),
  observe: jest.fn(),
}));

reference

Copy link
Collaborator

@prc5 prc5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 🚀🙌

@prc5 prc5 merged commit acecc35 into BetterTyped:master Feb 26, 2024
Copy link

🎉 This PR is included in version 3.4.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ryo-manba ryo-manba deleted the feature/resize-observer-check branch February 27, 2024 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants