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

Popover: fix exhaustive-deps warning #45656

Merged
merged 3 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### Internal

- `PaletteEditListView`: Update to ignore `exhaustive-deps` eslint rule ([#45467](https://github.com/WordPress/gutenberg/pull/45467)).
- `Popover`: Update to pass `exhaustive-deps` eslint rule ([#45656](https://github.com/WordPress/gutenberg/pull/45656)).
- `Flex`: Update to pass `exhaustive-deps` eslint rule ([#45528](https://github.com/WordPress/gutenberg/pull/45528)).
- `withNotices`: Update to pass `exhaustive-deps` eslint rule ([#45530](https://github.com/WordPress/gutenberg/pull/45530)).
- `ItemGroup`: Update to pass `exhaustive-deps` eslint rule ([#45531](https://github.com/WordPress/gutenberg/pull/45531)).
Expand Down
25 changes: 18 additions & 7 deletions packages/components/src/popover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,17 @@ const UnforwardedPopover = (

// When any of the possible anchor "sources" change,
// recompute the reference element (real or virtual) and its owner document.

const anchorRefTop = ( anchorRef as PopoverAnchorRefTopBottom | undefined )
?.top;
const anchorRefBottom = (
anchorRef as PopoverAnchorRefTopBottom | undefined
)?.bottom;
const anchorRefStartContainer = ( anchorRef as Range | undefined )
?.startContainer;
const anchorRefCurrent = ( anchorRef as PopoverAnchorRefReference )
?.current;

useLayoutEffect( () => {
const resultingReferenceOwnerDoc = getReferenceOwnerDocument( {
anchor,
Expand All @@ -401,11 +412,11 @@ const UnforwardedPopover = (
setReferenceOwnerDocument( resultingReferenceOwnerDoc );
}, [
anchor,
anchorRef as Element | undefined,
( anchorRef as PopoverAnchorRefTopBottom | undefined )?.top,
( anchorRef as PopoverAnchorRefTopBottom | undefined )?.bottom,
( anchorRef as Range | undefined )?.startContainer,
( anchorRef as PopoverAnchorRefReference )?.current,
anchorRef,
anchorRefTop,
anchorRefBottom,
anchorRefStartContainer,
anchorRefCurrent,
anchorRect,
getAnchorRect,
fallbackReferenceElement,
Expand All @@ -420,7 +431,7 @@ const UnforwardedPopover = (
// Reference and root documents are the same.
referenceOwnerDocument === document ||
// Reference and floating are in the same document.
referenceOwnerDocument === refs?.floating?.current?.ownerDocument ||
referenceOwnerDocument === refs.floating.current?.ownerDocument ||
// The reference's document has no view (i.e. window)
// or frame element (ie. it's not an iframe).
! referenceOwnerDocument?.defaultView?.frameElement
Expand All @@ -442,7 +453,7 @@ const UnforwardedPopover = (
return () => {
defaultView.removeEventListener( 'resize', updateFrameOffset );
};
}, [ referenceOwnerDocument, update ] );
}, [ referenceOwnerDocument, update, refs.floating ] );

const mergedFloatingRef = useMergeRefs( [
floating,
Expand Down