-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 closest().parentNode null error #22264
Conversation
Size Change: +9 B (0%) Total Size: 824 kB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like it should be a relatively safe change, and I confirmed that boundaryElement
is used, it's expected that it could be falsey (source). It's not exactly clear to me the precise circumstances under which this could occur, but the result of closest()
could certainly produce an error, so the extra guarding is sensible.
cc @youknowriad @ellatrix who are likely more familiar with the implementation of __unstableBoundaryParent
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I verified boundaryElement can be falsy inside computePopoverPosition where it is used. I also did some smoke tests with popovers and everything seemed ok.
Thanks for the quick reviews, folks 🙇♂️ |
Description
Fix an issue in Popover that may throw an error under certain conditions.
Change the
.closest( '.popover-slot' ).parentNode
to use an optional chain?.parentNode
, which will keep theboundaryElement
asundefined
if no closest element is found.#19322 (merged to master via #19344) introduced a chained call that may get
parentNode
ofnull
, causing an error:gutenberg/packages/components/src/popover/index.js
Lines 330 to 335 in f6a401b
closest
may returnnull
if no matching element is found. See the MDN documentation for details.I'm unfamiliar with the
__unstableBoundaryParent
feature, so I'd appreciate specific testing in Gutenberg or instructions on how to reproduce a minimal test case. It's simple to confirm the logic behind this fix works as expected in a browser:How has this been tested?
node_modules
fixes error in fix(deps): update wordpress monorepo (take 2) Automattic/wp-calypso#41994Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: