Topic: My app breaks when I update to 4.12 or later
mpcooke4 pro asked 5 years ago
I have been puzzling over this issues all day, so thought I'd ask in case it's related to a change that you know about.
Expected behavior I am using react-scripts to start and build my react app and usually it all runs ok with a mdbreact pro github dependancy in my package.json script
Actual behavior
On npm start, the app starts up but in the browser I get an error related to the react object being undefined in an mdbreact script.
TypeError: Cannot read property 'type' of undefined (anonymous function) node_modules/mdbreact/dist/mdbreact.esm.js:6552 6549 | var contentClasses = classNames(!popover && "tooltip-inner"); 6550 | return React.createElement(Manager, null, React.createElement(Reference, null, function (_ref2) { 6551 | var ref = _ref2.ref;
6552 | return !domElement ? React.createElement(Wrapper.type, _extends({}, Wrapper.props, { | ^ 6553 | onMouseEnter: function onMouseEnter() { 6554 | return !clickable && setVisible(true); 6555 | },
Resources (screenshots, code snippets etc.)
I have "react": "^16.8.2" in my dependancies and I am using the github URL in my package.json file to load mdbreact and I can switch between a working (for me) version of mdbreact and the latest version that doesn't work by switching from:
git.mdbootstrap.com/mdb/react/re-pro.git#fcdbb72d <- Working git.mdbootstrap.com/mdb/react/re-pro.git#9c308706 <- Broken git.mdbootstrap.com/mdb/react/re-pro.git <- Broken
I don't really know how the magic of webpack works and what might have changed that react is included in one version okay but doesn't get included in the later version.
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Opened
- ForumUser: Pro
- Premium support: No
- Technology: MDB React
- MDB Version: 4.12.0
- Device: Mac
- Browser: Chrome
- OS: osX
- Provided sample code: No
- Provided link: No
mpcooke4 pro commented 5 years ago
Just to follow up, I have a looked a bit closer at the changes around the time it stopped working for me and in the mdbreact package.json file, react and reactdom were both moved to devDependencies. What I don't understand is why that is causing me problems and no one else!
mpcooke4 pro commented 5 years ago
Should react be a peer dependancy rather than a dev dependancy to ensure the react library is available?
Jakub Mandra staff commented 5 years ago
Hi,
react should be in your dependencies, so as react-dom. Please try to use React 16.8.6. Error msg tells that the problem is caused by Popover/Tootlip component which is built using hooks.
If it won't help, please contact me for further assistance.
Best,
Jakub
mpcooke4 pro commented 5 years ago
I have react and react-dom in my package.json dependancies: "react": "^16.8.6", "react-dom": "^16.8.6",
I also tried deleting nodemodules and running npm install again. react is downloaded into my nodemodules. I don't understand why it still doesn't work after adding it and re-installing everything, perhaps it's something to do with webpack although I am just using react-scripts.
What I do know for sure is I can make it work if I pin the mdbreact version to before you moved the dependancies into dev.
Here is the error, after ensuring package.json has react 16.8.6, deleting nodemodules and a fresh npm install × ←→1 of 8 errors on the page TypeError: Cannot read property 'type' of undefined (anonymous function) node_modules/mdbreact/dist/mdbreact.esm.js:6749 6746 | var contentClasses = classNames(!popover && "tooltip-inner"); 6747 | return React.createElement(Manager, null, React.createElement(Reference, null, function (_ref2) { 6748 | var ref = _ref2.ref;
mpcooke4 pro commented 5 years ago
The full error trace shows that this error happens due to a setState call which I make after loading some data in the componentDidMount() method. I thought it was suppose to be okay to do this, but it seems to fail after MDBreact version fcdbb72d with this strange type error. I'll look into it further tomorrow. My react app renders okay when I remove this setState line, albeit without any loaded data of course...
full stack:
× ←→1 of 8 errors on the page TypeError: Cannot read property 'type' of undefined (anonymous function) node_modules/mdbreact/dist/mdbreact.esm.js:6749 6746 | var contentClasses = classNames(!popover && "tooltip-inner"); 6747 | return React.createElement(Manager, null, React.createElement(Reference, null, function (_ref2) { 6748 | var ref = _ref2.ref;
Jakub Mandra staff commented 5 years ago
Can you share your project with us so we could see what is going on there?
You can invite me (@Rotarepmi) on private GitHub repo.
Best,
Jakub
mpcooke4 pro commented 5 years ago
Thanks the project using mdbreact is in cowfoo/new-react-web-client
mpcooke4 pro commented 5 years ago
You probaby read the stack trace better than me, but it isn't React that was undefined, it is wrapper. I still don't understand why upgrading mdbreact would cause that error though.
mpcooke4 pro commented 5 years ago
Let me know if you have any problems reproducing it. I left the breakage in head and granted you access...
Jakub Mandra staff commented 5 years ago
Hi there,
Sorry it took so long, I had problems with installation, caused by "synchronize" package (took some time to find out).
I've checked your project and found what is going on - you're using Popovers/Tooltips old syntax. They were completely rebuilt in 4.13.0 version and their syntax had to be changed.
Check new docs: https://mdbootstrap.com/docs/react/advanced/popovers/
Hope this will help.
Best,
Jakub
mpcooke4 pro commented 5 years ago
Many thanks for identifying the problem!
Does the new syntax support wrapping a popup around an arbitrary element? I can see it can wrap a button okay but it doesn't seem to work on a div - does the wrapped element need to have certain properties?
Jakub Mandra staff commented 5 years ago
Try below code, you just need to add
domElement
property to you Popover/Tooltip, so it will go on with native elements: