-
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
Add different string ref warning when owner and self are different #17864
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ff93a34:
|
Details of bundled changes.Comparing: 29b4d07...ff93a34 react
react-test-renderer
react-native-renderer
react-art
react-dom
react-reconciler
ReactDOM: size: 0.0%, gzip: -0.0% React: size: 0.0%, gzip: -0.0% Size changes (experimental) |
Details of bundled changes.Comparing: 29b4d07...ff93a34 react
react-native-renderer
react-reconciler
react-dom
react-art
react-test-renderer
ReactDOM: size: 0.0%, gzip: -0.0% React: size: 0.0%, gzip: -0.0% Size changes (stable) |
8da85b2
to
3bd634a
Compare
mixedRef, | ||
getStackByFiberInDevAndProd(returnFiber), | ||
); | ||
if ( |
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.
The warnAboutStringRefs
flag just says to turn on a warning for all string refs, regardless if it's in strict mode or not. That's a very aggressive flag. If you're getting warnings for everything then it's not much better to get a slightly different message (unless filtering but nobody does that).
I think we'll want to add this warning much more aggressively. I.e. not behind a flag at all and also fire it outside strict mode.
element._self && | ||
element._owner.stateNode !== element._self | ||
) { | ||
console.error( |
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.
The reason we put the other warning in this file is because it's the only way to know if you're in StrictMode or not.
However, it's a sub-optimal place to put it because the error stack isn't as good. It doesn't point out the exact callsite. Since we don't need to check for StrictMode and can just always warn, you can instead put this in React.jsx and React.createElement so that we get better error stacks.
You can disable the warning here for that case to avoid the duplicate.
element._owner.stateNode !== element._self | ||
) { | ||
console.error( | ||
'Owner and self do not match for the string ref "%s". Support for ' + |
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.
This doesn't really tell the user anything. They don't know what owner and self not matching means. How about:
Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://fb.me/react-strict-mode-string-ref%s
3bd634a
to
6cb196b
Compare
packages/react-dom/src/__tests__/ReactDeprecationWarnings-test.internal.js
Show resolved
Hide resolved
75a0552
to
d8a2020
Compare
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.
Typo but otherwise looks good.
packages/react/src/ReactElement.js
Outdated
'Component "%s" contains the string ref "%s". ' + | ||
'Support for string refs will be removed in a future major release. ' + | ||
'This case cannot be automatically converted to an arrow function. ' + | ||
'We as you to manually fix this case by using useRef() or createRef() instead. ' + |
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.
*We ask
d8a2020
to
debdb1b
Compare
debdb1b
to
ff93a34
Compare
When owner and self are different for string refs, we can't easily convert them to callback refs. This PR adds a warning for string refs for everyone when owner and self are different to tell users to manually update these refs.