Skip to content
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

Fixed Uncaught Invariant Violation in React v15.0.2 #5

Closed
wants to merge 1 commit into from

Conversation

danljs
Copy link

@danljs danljs commented May 18, 2016

After I updated React to v15.0.2 it gives the following error:

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).

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).
@NdYAG
Copy link
Owner

NdYAG commented May 19, 2016

opps... then I must wrongly closed the issue #4
I'll try to find out that, thanks for bug reporting.

@NdYAG
Copy link
Owner

NdYAG commented May 19, 2016

Hi @danielliu1973
The changes you made is the way I decide if a child component is disabled or not before. b62d02f#diff-1fdf421c05c1140f6d71444ea2b27638L26
For customized child element, we cannot guarantee it would add a is-disabled className or not.
So instead I use ref to get the isDisabled property.

And I've update react to 15.0.2, right now I cannot reproduce the error.
Could you tell me how to reproduce the error?

@danljs
Copy link
Author

danljs commented May 19, 2016

Here is my test code, please refer to.
https://github.com/danielliu1973/react-rater-test

@NdYAG
Copy link
Owner

NdYAG commented May 20, 2016

@danielliu1973 Thank you so much for the detailed repo!

Finally I found the reason causing this problem: by comparing the call stack, this._currentElement._owner is null due to multiple React version in the compiled app.js in this repo.

After cat app.js | grep 0.14 and cat app.js | grep 15.0, surprising I found that the compiled file contain both versions of React. It's my bad adding react as a dependency in my package.json.

Now I've moved react & react-dom to peerDependencies, and updated version to 0.3.2 on npm.

Please update to the new version, and I believe you'll not encounter the error message again!

Again, thank you so much for reporting this bug! 😘

A nearly same problem is here, for reference facebook/react#5631

@danljs
Copy link
Author

danljs commented May 20, 2016

Excellent!

@danljs danljs closed this May 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants