-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs #606
Comments
I encounter this problem few days ago with the same message as you got from the console... The reason was React module was loaded twice. I had an html file that contains
and subcontract.js is generated by webpack. |
Yeah, I was trying to explore the same possibility. How did you end up resolving it? Right now we have a version |
I'm getting the same error, with no indication that I'm loading React more than once. I'm trying to render This project has figured if they removed refs, it might be easier to nest this component inside another component: https://github.com/bebraw/reactabular/issues/41 |
I'm also getting this error. I will attempt to reproduce this issue in a new application. |
In the end, it really was React being loaded too many times. I don't believe the browserify shimming applies to installed node modules. Therefore instead of using the global React, it imports another one. I don't feel like this is an issue with react-select. At least for me, it's an issue with browserify loading multiple copies of the same library (React) when requested more than once by other modules. If I assign React to |
Is it possible |
Dug in a little deeper and there are two versions of
and
I modified the |
I updated |
try switching to webpack.. i did not encounter the problem anymore after i remove the
|
I encounter same problem, but it's not caused by duplicate react dependecy. I'm Implementing a separate form library and React say that I can't use refs outside of ReactOwner. This is how I wrap import React, { PropTypes, Component } from 'react';
import Select from 'react-select';
import styles from './select.scss';
import withStyles from '../../decorators/withStyles';
import {connect} from 'react-redux';
import { setValue } from '../../actions/validation';
@withStyles(styles)
class Container extends Component {
render() {
return (
<div>
<Select ref="selectbox" {...this.props} />
</div>
);
}
}
export default connect(state => ({
validation: state.validation,
}))(Container); |
I am running into this issue too, using browserify-shim with the following external config:
(As we had to load React on the page itself because other code on the page outside of the component I am trying to build relies on it). That was all working fine, until we did the following:
Has anyone resolved or worked around this issue while still using browserify-shim for React? It seems like browserify should be using the same configuration when resolving the requires down in a node_module package. |
We ended up giving up on |
Anyone figured this out? I am still having same issue. |
I tried with a simple component (cjsx syntax)
But I still get the same error. I tried to remove all I will have to give up on |
I guess it's caused by the refs used in the methods of the mixins. |
Just for an information, I receive this error when I add a new dependency to the project. If I delete |
same as cubbuk. I deleted node_modules and reinstalled all dependencies. The error went away |
Reinstalling node_modules unfortunately didn't work for me. Please fix this |
Ok, soled it. Got separate file with React. Stop requiring packages locally and require them with npm (from node_modules) solved it. |
@kesha-antonov I am having the same problem. I deleted node_modules and reinstalled by running |
I had file ".../my_directory/react.js" And in package.json
I removed that line from "browser" block and also "react-dom", "formsy-react" and did And then I succeed |
More solutions here in case anyone needs |
For me this issue was caused by using turbolinks with react-select. I didn't have time to get to figure out exactly what turbolinks was doing to cause the issue but (based on the other comments in this thread) I suspect it was reloading react when I changed pages. Removing turbolinks stopped this from happening (although there probably is a way to successfully use react-select alongside turbolinks). |
I found a hacky solution. In the dependent component instead of just exporting the React component I am exporting a function which returns the React component select.jsx module.exports = function (React) {
var Select = React.createClass({
render: function () {
return (
<div className="select">
<select ref="select"></select>
</div>
);
}
});
return Select;
}; And when importing do something like this: someFile.jsx import React from 'react';
var Select = require('select')(React); This would prevent the child component from having it's own React dependency. |
I've installed |
@nburwell – Same setup as you and I'm running into the same issue. Did you ever discover a fix for this? |
We had this same issue but found a fix that has not been mentioned thus far. In our webpack setup we had a DLLs config with several entry points that was responsible for outputting 5-6 DLLs to be referenced in the main config. 'react-select' was in one and 'react-modal' was in another. Upon further inspection I realized that each of the DLL bundles was getting it's own copy of react. The bug only surfaced when a react-select box was nested inside of a react modal, but both libraries worked independently. Solution was to have a multi-layered dll build process where a dll bundle containing just react and friends is created first, then referenced by the "level 2" dll bundles that contain things like react-select, then all the resulting dll bundles are referenced by the main build file. Use the webpack analyze tool to inspect the stats from your bundles, it should provide some insight into how and why webpack is inserting multiple bundles. Another solution that has worked in the past for me with the 'multiple copies of react' issue is to use the resolve section of the webpack config to point to a particular single copy of react. |
I hit this when implementing browserify-rails. Defining |
I had in my HTML file. I deleted these lines and it worked |
Should I give up???I spent a couple of hours building this use case in isolation and after that, I decided the release a reusable component. However, after hours and hours and days trying to get this to work I'm finally in the step of making a decision... I based my example on the sample from http://jedwatson.github.io/react-select/.
Running in isolation: WorksRunning as a Shared ComponentThe component above then was placed in an isolated NPM Module/component and published to our private NPM registry. Then, when trying to see the component, I get the following error... Running as a Share Library: Arrows keys partially work...As a consequence, the UI can't render the properties right, but I can still use the up-down arrows to select my options, but without the nice UI experience... Still work although it does not render properly..Events don't work anymoreNo duplicate react Dependency$ npm ls | grep react@
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
│ │ ├─┬ [email protected]
│ └─┬ [email protected]
├─┬ [email protected]
├─┬ [email protected]
npm info ok |
I had this issue for weeks and just installed the latest version of react select |
After weeks of digging, the root cause of my issue is with http://fb.me/react-warning-keys. Had a lot of trial and error by removing codes/debugging but |
@cubbuk's suggestion worked for me. The way I ended up with 2 copies of react was by debugging and rebuilding the |
I'm going to close this, as it's not really a react-select issue (and almost always related to having two copies of react loaded). Some great causes and solutions above 👍 |
Trying to integrate
react-select
into our application and we're seeing the following error. There may be something in our workflow that is causing it. We're usingReactDOM
to render react components into our page.An example:
The text was updated successfully, but these errors were encountered: