-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Creating element with ref in constructor does not throw error in dev mode (#9635) #10025
Conversation
I've managed to fix this bug but, to be perfectly honest, I don't fully understand what's going on here. Previously when constructing a component in dev mode |
Can you also check if this ever worked with previous versions of React? Specifically 0.13 and 0.14? |
@gaearon I had a bit of trouble getting 0.13 installed but I think I got it working enough to run the tests. It looks like the error is thrown in 0.13 when |
src/renderers/__tests__/refs-test.js
Outdated
ReactTestUtils.renderIntoDocument(<RefTest />); | ||
}).toThrowError(); | ||
|
||
__DEV__ = originalDev; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be in a finally
block so that it happens regardless.
src/renderers/__tests__/refs-test.js
Outdated
|
||
expect(function() { | ||
ReactTestUtils.renderIntoDocument(<RefTest />); | ||
}).toThrowError(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to assert a specific error message here. I don't think Fiber currently has a nice message in this case. Can you look into it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally tried checking for the specific error message. I copy/pasted the message but it said actual vs. expected message didn't match, even though they appeared identical. I'll give it another try.
I've updated the tests to check for the specific error message. This breaks the tests in Fiber since the error message is different. @gaearon you're correct that this error does not have a nice message in Fiber, it just results in a
|
I have a potential fix for this in Fiber. Currently on line 559 of |
@gaearon I've made the requested changes here and pushed a commit but I'm not sure if there's some way I can request another review or otherwise confirm that I've made the changes. I assume you've just got your hands full but I want to make sure you're not waiting on me. Also let me know about the Fiber fix in my previous comment. |
Sorry this slipped through the cracks. We were focused on getting 16 beta out. Can you rebase on master? I think the change to Fiber code is now not necessary because we have a better check there. |
I rebased upstream/master into my branch and now it's showing all the commits that have happened since then as part of my pull request. I'm not exactly sure how to fix that. 😬 Looking at |
I tried running the tests I added for this issue with the version of Also, no need to apologize, I understand that React 16 is high priority. I want it to be released too. 😀 UPDATE: It looks like the error is being caught but with a different error message which is why the tests are failing. |
I've reverted the changes in |
The extra commits look weird. Let's just do
And then force push. This will turn it into a single commit on top of current master. |
|
… Only set ReactCurrentOwner.current in dev mode when the component has no constructor.
Done! GitHub was still showing all the commits on the pull request for a minute there and I thought I effed it up again but it looks good now. Thanks for the help Dan! |
Sweet. Thanks. |
… Only set ReactCurrentOwner.current in dev mode when the component has no constructor. (#10025) nhunzaker: I've added an additional line to the ref test that sets the NODE_ENV invironment variable. This allows the test to pass.
… Only set ReactCurrentOwner.current in dev mode when the component has no constructor. (#10025) nhunzaker: I've added an additional line to the ref test that sets the NODE_ENV invironment variable. This allows the test to pass.
… Only set ReactCurrentOwner.current in dev mode when the component has no constructor. (#10025) nhunzaker: I've added an additional line to the ref test that sets the NODE_ENV invironment variable. This allows the test to pass.
Currently just a failing test to show that this issue does exist. Next step is to fix the issue. See issue #9635.