Skip to content

Support element-dependent Window and Document objects (i.e. popup using React Portals) #442

@aszmyd

Description

@aszmyd

Description

It happens sometimes that the globally available window and document objects are not the ones we want to use when attaching listeners and searching through DOM.
In our application, we're using React Portals together with a blank pop-up window to have a multi-window experience. This works really well except for the fact that the window and document contexts in such an approach are not the global ones (because React renders HTML in the other context window than the javascript is still executing).

You've baked in the use of global window and document (i.e. here)

You can get the right context from any DOM element by accessing its ownerDocument (document, document.querySelectAll etc) and defaultView attribute of the document (to get the window object related to a document)

I think what could be done to support it is to store somewhere these objects (making a hook to make it easy to use), default to the global ones and update the references when the node is available (i.e. in setRef of the 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