react-overlays: Modal does not work with React 16
Probably the same issue as https://github.com/facebook/react/issues/9808.
When the Modal is shown and tries to get focus (via componentDidUpdate -> onShow - focus), setModalNode will not have been called and getDialogElement will return undefined.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 24
- Comments: 44 (10 by maintainers)
Commits related to this issue
- trying to upgrade to React 16 blocked by https://github.com/react-bootstrap/react-overlays/issues/188 — committed to Datawheel/mondrian-rest-ui by jazzido 7 years ago
- Upgrade react-overlays to 0.7.3, needed to fix https://github.com/react-bootstrap/react-overlays/issues/188 (thanks to react 16). — committed to jfly/worldcubeassociation.org by jfly 7 years ago
- Upgrade react-overlays to 0.7.3, needed to fix https://github.com/react-bootstrap/react-overlays/issues/188 (thanks to react 16). — committed to jfly/worldcubeassociation.org by jfly 7 years ago
- Upgrade react-overlays to 0.7.3, needed to fix https://github.com/react-bootstrap/react-overlays/issues/188 (thanks to react 16). — committed to thewca/worldcubeassociation.org by jfly 7 years ago
- trying to upgrade to React 16 blocked by https://github.com/react-bootstrap/react-overlays/issues/188 — committed to Datawheel/mondrian-rest-ui by jazzido 7 years ago
FYI React 16 is released, so this just became a blocker for people to be able to upgrade.
Fo v16 we’ll want to switch to the new (YAH!) portal api
I threw this in my startup file for now:
That way I don’t have to change every single place I import Modal(there’s a lot of em!).
version 0.7.3 seems to have fixed the issue.
Thanks for the work on this!
This shim has worked fine for us - it bypasses some functionality but it got us unblocked.
If you are using webpack you need to use this fix like this:
I dug into this a bit to see what the root problem was. The core problem is
react-dom’scommitAllLifeCyclesinvokescommitAttachRefaftercommitLifeCycles. This means thatsetModalNode(which assigns the localmodalNodefield) is invoked aftercomponentDidMount(which callsonShowand by extensionfocus).What this means is that (given that
react-domdoes not change itscommitAllLifeCyclesfunction), we remove theonShowfromcomponentDidMountand move it tosetModalNode. I have tested this and it most definitely works as expected.as a temporary shim, this should work for most setups.
you can see that there are a few efforts to fix this. IF you want stuff to go faster jump in on the PR’s and review/test them
@geminiyellow this has been fixed in 0.7.3, but not yet in the 0.8 branch (as of 0.8.2).
I worked around that issue by creating a custom
Modalwrapper component which monkey-patches cDM and cDU as outlined above:Once 0.7.3 was released, I just downgraded the react-overlays version from ^0.8.2 to ^0.7.3, so that patch isn’t needed any more.
@seeden i try to use your solution in the component but i get some error, below is the error i got
i have put the code out of render in component.
@connorjburton actually i urgently need to fix the issue in my project. so if i get any working patch solution than that’s fine, we can fix the temporary with the official update later. but right now i need a fix. if you can give me some idea it will be great.
i already try to integrate the patches mentioned above in my project, but couldn’t be able to make it workable.
still not working
@nelsongustavo maybe try