Modal Error: Cannot read property 'parentNode' of undefined
See original GitHub issueIssue description
- components:
Modal
- reactstrap version
#4.8.0
- import method
es
- react version
#16.0.0
- bootstrap version
#4.0.0-beta.2
What is happening?
I encountered the ‘Uncaught TypeError: Cannot read property ‘parentNode’ of undefined’ error when trying the Modal examples. What should I do to solve this problem? Thank you in advance.
Error message in console
Uncaught TypeError: Cannot read property ‘parentNode’ of undefined at Modal.renderIntoSubtree (webpack-internal:///./node_modules/reactstrap/dist/reactstrap.es.js:2518) at Modal.show (webpack-internal:///./node_modules/reactstrap/dist/reactstrap.es.js:2484) at Modal.togglePortal (webpack-internal:///./node_modules/reactstrap/dist/reactstrap.es.js:2438) at Modal.componentDidUpdate (webpack-internal:///./node_modules/reactstrap/dist/reactstrap.es.js:2378) at commitLifeCycles (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:11517) at commitAllLifeCycles (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:12294) at HTMLUnknownElement.callCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:1299) at Object.invokeGuardedCallbackDev (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:1338) at invokeGuardedCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:1195) at commitAllWork (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:12415)
Code
The code I was running is: https://reactstrap.github.io/components/modals/
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:6 (2 by maintainers)
@Heizyuan upgrade your reactstrap version to:
^5.0.0-alpha.3
it worked for me. I usedyarn add reactstrap@next
Although I also had to upgrade these since I used them:
Yes, this is an issue with portals in react 16. They do not return the reference needed for focus. You can disable the autoFocus by passing
autoFocus={false}
to theModal
, but it is best to just upgrade to 5.0.0-alpha.3 as A-Tokyo mentioned.The upgrade is also recommended since you are using bootstrap 4.0.0-beta.2, the 4.8.0 version you are on only supports 4.0.0-alpha.6. Plus, 4.8.0’s react peerDep does not allow react 16, so you are probably getting warning.