8000 isDOM doesn't work on elements outside of current window · Issue #644 · react-component/util · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
isDOM doesn't work on elements outside of current window #644
Open
@yourWaifu

Description

@yourWaifu

This code

export function isDOM(node: any): node is HTMLElement | SVGElement {
// https://developer.mozilla.org/en-US/docs/Web/API/Element
// Since XULElement is also subclass of Element, we only need HTMLElement and SVGElement
return node instanceof HTMLElement || node instanceof SVGElement;
}

Fails when node is not inside the current window. The main use case is using one screen for presentation and another screen for information that the presenter see.

an idea of a fix:

const nodeWindow = node?.ownerDocument?.defaultView;
return node instanceof nodeWindow.HTMLElement || node instanceof nodeWindow.SVGElement;

The issue is that the above code doesn't really work because you need to know if node is an Element first before getting the window, so we'll need a better idea for a fix.

a fix that I feel like is a hack:

return "nodeType" in node && node === Node.ELEMENT_NODE && "tagName" in node;

I don't know if this is good enough, but it works, fixes the bug.

same thing also happens here

if (element instanceof Element) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0