-
Notifications
You must be signed in to change notification settings - Fork 50.5k
Closed
Description
See this test case:
react/packages/react-dom/src/__tests__/ReactStatelessComponent-test.js
Lines 142 to 157 in 323efbc
| it('should throw on string refs in pure functions', () => { | |
| function Child() { | |
| return <div ref="me" />; | |
| } | |
| expect(function() { | |
| ReactTestUtils.renderIntoDocument(<Child test="test" />); | |
| }).toThrowError( | |
| __DEV__ | |
| ? 'Stateless function components cannot have refs.' | |
| : // TODO: the different message in production seems like a bug. | |
| // It happens because we don't save _owner in production for | |
| // functional components. We should probably show a better message. | |
| 'Element ref was specified as a string (me) but no owner was set.', | |
| ); | |
| }); |
Pretty sure the different message in production wasn't intentional, but is a consequence of ReactCurrentOwner.current not being set in production for functional components.
We need to see if it's possible to emit the same (useful) message both in development in production. If it's not possible, we need to change the production message to be more ambiguous instead of suggesting the wrong reason for the problem.