Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal render children is not sync which break getting ref in useEffect #26545

Closed
1 task done
NE-SmallTown opened this issue Sep 2, 2020 · 4 comments
Closed
1 task done

Comments

@NE-SmallTown
Copy link
Contributor

NE-SmallTown commented Sep 2, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

Open the codesandbox link , and then check the console output

What is expected?

Can successfully get the ref.current of Modal's children

What is actually happening?

It's null, so have to use a setTimeout

Environment Info
antd 4.6.2
React 16.12.0
System Windows 10
Browser Google Chrome 84.0.4147.135

This bug is because when the getContainer prop to Modal is not false, the Modal component will call createContainer in the cDM which will call getContainer to create a new DOM element and append it to the document.body. But, it will not render the children at that time, on the contrary, it will trigger the forceUpdate after that, and so, the useEffect in our component will be triggered before the children be mounted to the DOM because forceUpdate is not a "sync" operation(same as setState). So, when the useEffect fired, we cant get the children DOM instance

@NE-SmallTown NE-SmallTown changed the title Modal render children it not sync which break getting ref in useEffect Modal render children is not sync which break getting ref in useEffect Sep 3, 2020
@NE-SmallTown
Copy link
Contributor Author

friendly ping~

@zombieJ
Copy link
Member

zombieJ commented Sep 24, 2020

+ rc-util@5.3.1

Add forceRender in your code.

@zombieJ zombieJ closed this as completed Sep 24, 2020
@NE-SmallTown
Copy link
Contributor Author

ok,close for react-component/util#150

@mikedeng
Copy link

How to solve this , I got the same problem in the latest antd@4.23.6, it doesn't work after forceUpdate added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants