Skip to content

Commit 600de1b

Browse files
authored
fix(Popper): add null & connected checks for document (#12284)
1 parent e8f083e commit 600de1b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/react-core/src/helpers/Popper/thirdparty/popper-core/dom-utils/getDocumentElement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ import { Window } from '../types';
77
*/
88
export default function getDocumentElement(element: Element | Window): HTMLElement {
99
// $FlowFixMe: assume body is always available
10-
return (isElement(element) ? element.ownerDocument : element.document).documentElement;
10+
return ((isElement(element) ? element.ownerDocument : element.document) || window.document).documentElement;
1111
}

packages/react-core/src/helpers/Popper/thirdparty/react-popper/usePopper.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ type State = {
3535

3636
const EMPTY_MODIFIERS: any = [];
3737

38+
function isReferenceConnected(reference: Element | VirtualElement): boolean {
39+
if (reference instanceof Element) {
40+
return reference.isConnected;
41+
}
42+
const { contextElement } = reference;
43+
if (contextElement instanceof Element) {
44+
return contextElement.isConnected;
45+
}
46+
return true;
47+
}
48+
3849
export const usePopper = (
3950
referenceElement: (Element | VirtualElement) | null | undefined,
4051
popperElement: HTMLElement | null | undefined,
@@ -114,6 +125,10 @@ export const usePopper = (
114125
return;
115126
}
116127

128+
if (!isReferenceConnected(referenceElement) || !popperElement.isConnected) {
129+
return;
130+
}
131+
117132
const createPopper = options.createPopper || defaultCreatePopper;
118133
const popperInstance = createPopper(referenceElement, popperElement, popperOptions);
119134

0 commit comments

Comments
 (0)