Skip to content

Portal children cannot access the DOM in useEffect / componentDidMount #52

Open
@wilcoxmd

Description

@wilcoxmd

Describe the bug
Because the the portal element is appended to the DOM in useEffect, on the initial render, the portal is created in a detached DOM node. It's children render and run their useEffects first, and any access to the DOM will not work.

Codesandbox
https://codesandbox.io/s/objective-keldysh-0078v?file=/src/App.js

To Reproduce
Steps to reproduce the behavior:

  1. try to reference the DOM in a child of the Portal within useEffect or componentDidMount (or just checkout the codesandbox)

Expected behavior
The Portal doesn't render the children until it has attached the root element to the DOM

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions