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

Check if ResizeObserver is defined instead of checking window object #2222

Merged
merged 2 commits into from
Feb 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/core/src/hooks/useMeasure.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ export const useMeasure = () => {
})

const [observer] = useState(() => {
// Check if window is defined (so if in the browser or in node.js).
const isBrowser = typeof window !== 'undefined'
if (!isBrowser) return null
// Check if ResizeObserver is defined in current env (could be browser, node.js, jsdom etc.).
if (typeof ResizeObserver === 'undefined') return null

return new ResizeObserver(([entry]) => setBounds(entry.contentRect))
})
Expand Down