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

componentDidMount called before backdropRef is set #5

Closed
awinograd opened this issue Oct 6, 2018 · 1 comment · Fixed by #6
Closed

componentDidMount called before backdropRef is set #5

awinograd opened this issue Oct 6, 2018 · 1 comment · Fixed by #6
Assignees
Labels
bug Something isn't working

Comments

@awinograd
Copy link
Contributor

I was checking out modal-enhanced-react-native web in an existing project and set rendered the following immediately on page load:

<Modal isVisible={true}>
...
</Modal>

I realized that backdrop didn't properly display and was trying to figure out why. It turns out, the componentDidMount lifecycle event is being called before ref={r => this.backDropRef = r} is executed. Because of that, backdropRef.transitionTo({ opacity }) is never called and the opacity is stuck at 0 until the modal closes/re-opens.

My understanding is that lifecycle/ref ordering shouldn't be possible (https://reactjs.org/docs/refs-and-the-dom.html)

Refs are guaranteed to be up-to-date before componentDidMount or componentDidUpdate fires.

But maybe that assumption does not hold true when using ReactDOM.createPortal? I haven't used that API myself yet.

Expected behavior is that the opacity properly transitions when the modal is open immediately on page load.

@rayandrew rayandrew added the bug Something isn't working label Oct 6, 2018
@rayandrew
Copy link
Contributor

rayandrew commented Oct 6, 2018

Thank you for looking into that issue @awinograd !

I myself found that bug about 3 months ago and still cannot look deep into that problems

Actually, I am not sure myself if ReactDOM.createPortal caused it as we know in the docs, ReactDOM.createPortal do not change any lifecycle at all.

If that assumption is true, I think we need to rewrite the library to support ReactDOM.createPortal and not overuse any refs at all as modal-enhanced-react-native-web is just a copy from react-native-modal that use refs with some additional changes.

Any kinds of help are appreciated! So feel free to contribute if you get the solution to fix it as I will seek the solution too @awinograd

I keep this issue opened to remind us about the bug, feel free to reference and close if any of us has solution to fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants