-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
No error when element with ref created in another elements constructor in dev environment. #9635
Comments
I also encountered the same issue, originally posted as issue facebook/create-react-app#2460 in the CRA repo. DescriptionAccording to the docs Testing with Expected behavior
Actual behaviorNo error or warning under EnvironmentRun these commands in the project folder and fill in their results:
Then, specify:
Reproducible DemoSee project: https://github.com/LemonPi/cra-refs-bug with a readme on what it demonstrates |
This likely is a bug. I have a hunch it might be already fixed on master. I'd appreciate if somebody could confirm that by writing a failing test. |
@gaearon I've been following this thread and would be interested in verifying the bug and attempting to fix it if it does still exist. Unless either of the bug reporters would like to tackle it. |
Sure, go ahead! You'll need to look for assignments to ReactCurrentOwner.current which is what seems to deviate in production. I think deviation was intentional but we either didn't consider this case (breaking refs in constructor) or we had some protection against it that got lost at some point. |
@gaearon I've added a test to verify that this bug does still exist on master. I'll look into fixing the bug next. |
This was fixed with #10025 |
@iansu thanks, copy-paste error 😄 |
When creating an Element with a ref from inside of a constructor an error is thrown in production mode, but not in dev mode.
Here is a minimal sample:
https://jsfiddle.net/84v837e9/35/
An error, "Only a ReactOwner can have refs", should happen in dev and production modes.
This is happening in React 15.4
The text was updated successfully, but these errors were encountered: