react-modal icon indicating copy to clipboard operation
react-modal copied to clipboard

owner ref errors on open/close

Open mgenev opened this issue 10 years ago • 8 comments

I implemented by copy/pasting the docs, but when I open I get this error and it does open.

Uncaught Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's `render` method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).

and when I try to I get this error, and it fails to close:

Uncaught Invariant Violation: removeComponentAsRefFrom(...): Only a ReactOwner can have refs. You might be removing a ref to a component that was not created inside a component's `render` method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).

mgenev avatar Jan 21 '16 00:01 mgenev

@mgenev I have same errors in react v0.14.6. And #89 have not worked for me. This problems looks being caused by other components. In my case, I just solved it to arrange package dependencies. Especially, I removed react by npm remove --save react. After that, It worked well.

JeffGuKang avatar Jan 22 '16 04:01 JeffGuKang

@mgenev Did you manage to resolve this in the end?

Deleting the modules didn't work for me, nor did moving the package to peerDependencies.

davidwadge avatar Mar 23 '16 11:03 davidwadge

https://github.com/reactjs/react-modal/issues/146 is a duplicate of this but I commented on there about a potential fix (upgrading to [email protected] and [email protected] seemed to solve it for me)

danbovey avatar Apr 22 '16 20:04 danbovey

Hey, I'm running on [email protected] and [email protected] and still getting this bug on some modals. It's particularly weird because it doesn't happen everywhere, only on one particular modal. Based on how other people resolved this, any ideas on how I can fix it?

EDIT: Did some more debugging, removing another React component I had defined got rid of the error. The other working modals use a number of React components which are coming from npm packages, it's specifically using components I've defined that caused the issue. Not sure why removing them fixed things, but now I've at least got a workaround!

john-osullivan avatar Jun 04 '16 00:06 john-osullivan

Same here with react 15.1.0 and react-modal 1.3.0, if I put in modal one of my own Component (statefull) I have this error (Only a ReactOwner can have refs…), not found any workaround…

dcaillibaud avatar Jun 22 '16 12:06 dcaillibaud

In my case, I had loaded multiple versions of react without knowing. I had separated react into a vendor bundle and using browserify-shim to resolve the requires. react-modal also requires react and so it was loading it's own react since browserify does not execute transforms for required modules.

Simply put, I changed transform('browserify-shim') to transform({global: true}, 'browserify-shim') and everything was fine. You could also add the specific transform to react-modal's package.json and it would work.

jovinbm avatar Aug 21 '16 11:08 jovinbm

Hi, I'm using react 15.4.0 and react-modal 1.6.5, same thing here.

What is causing this ? Isn't there any fix ?

GBarthos avatar Jan 31 '17 19:01 GBarthos

This issue must be fixed on current version v2+.

I'm closing this issue for clean up. Please, feel free to reopen this issue if needed. Thank you!

diasbruno avatar Jun 24 '17 17:06 diasbruno