Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@ function useResizeObserver<T extends Element>(
resizeObserverRef.current.box !== opts.box ||
resizeObserverRef.current.round !== round
) {
// It's possible that the global window is different than the window that the element is rendered in.
// Therefore we need to get the element's window's ResizeObserver constructor
const currentDocument = element.ownerDocument;
const currentWindow = currentDocument?.defaultView ?? window;
resizeObserverRef.current = {
box: opts.box,
round,
instance: new ResizeObserver((entries) => {
instance: new currentWindow.ResizeObserver((entries) => {
const entry = entries[0];

const boxProp =
Expand Down