react-component / util

Common Utils For React Component
util.vercel.app
MIT License
623 stars 178 forks source link

function inShadow throws error when shadowRoot is undefined #462

Open mazengh opened 1 year ago

mazengh commented 1 year ago

I am using latest antd library version 5.8.6 which is dependent on rc-util. There is an edge case where shadowRoot is undefined. When inShadow function is called, the whole page breaks throwing the error below.

VM107071:1 Uncaught TypeError: Right-hand side of 'instanceof' is not an object

It used to work when function returned return getRoot(ele) !== ele?.ownerDocument;

Version: rc-util: 5.37.0

mazengh commented 1 year ago

is it possible to create a PR to change the logic as below?

export function inShadow(ele: Node) {
  const root = getRoot(ele);
  return ShadowRoot ? root instanceof ShadowRoot : root !== ele?.ownerDocument;
}