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

Add different string ref warning when owner and self are different #17864

Merged
merged 1 commit into from
Jan 22, 2020

Conversation

lunaruan
Copy link
Contributor

@lunaruan lunaruan commented Jan 18, 2020

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.

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Jan 18, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 18, 2020

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:

Sandbox Source
modern-star-4jp2z Configuration

@sizebot
Copy link

sizebot commented Jan 18, 2020

Details of bundled changes.

Comparing: 29b4d07...ff93a34

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js +0.9% +0.8% 112.29 KB 113.31 KB 28.73 KB 28.97 KB UMD_DEV
react.production.min.js 0.0% -0.0% 12.67 KB 12.67 KB 4.94 KB 4.94 KB UMD_PROD
react.profiling.min.js 0.0% -0.0% 16.2 KB 16.2 KB 6.05 KB 6.05 KB UMD_PROFILING
react.development.js +1.4% +1.3% 71.8 KB 72.82 KB 19.06 KB 19.32 KB NODE_DEV
react.production.min.js 0.0% -0.0% 6.96 KB 6.96 KB 2.86 KB 2.86 KB NODE_PROD
React-dev.js +1.6% +1.6% 72.29 KB 73.43 KB 18.41 KB 18.71 KB FB_WWW_DEV

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +0.1% +0.1% 615.33 KB 615.65 KB 131.18 KB 131.29 KB UMD_DEV
react-test-renderer.production.min.js 0.0% -0.0% 71.5 KB 71.5 KB 21.91 KB 21.91 KB UMD_PROD
react-test-renderer-shallow.development.js 0.0% -0.0% 37.83 KB 37.83 KB 9.81 KB 9.81 KB UMD_DEV
react-test-renderer-shallow.development.js 0.0% -0.0% 32.37 KB 32.37 KB 8.5 KB 8.5 KB NODE_DEV
react-test-renderer.development.js +0.1% +0.1% 610.59 KB 610.91 KB 129.99 KB 130.1 KB NODE_DEV
react-test-renderer.production.min.js 0.0% -0.0% 71.19 KB 71.19 KB 21.53 KB 21.52 KB NODE_PROD
ReactTestRenderer-dev.js +0.1% +0.1% 626.4 KB 626.78 KB 130.8 KB 130.92 KB FB_WWW_DEV

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.1% +0.1% 743.4 KB 743.78 KB 157.62 KB 157.74 KB RN_OSS_DEV
ReactFabric-dev.js +0.1% +0.1% 734.02 KB 734.4 KB 155.41 KB 155.53 KB RN_OSS_DEV
ReactNativeRenderer-dev.js +0.1% +0.1% 743.58 KB 743.96 KB 157.71 KB 157.83 KB RN_FB_DEV
ReactNativeRenderer-prod.js 0.0% -0.0% 273.4 KB 273.4 KB 47.01 KB 47.01 KB RN_OSS_PROD
ReactFabric-dev.js +0.1% +0.1% 734.2 KB 734.58 KB 155.5 KB 155.61 KB RN_FB_DEV
ReactFabric-prod.js 0.0% -0.0% 266.18 KB 266.18 KB 45.83 KB 45.83 KB RN_FB_PROD
ReactFabric-profiling.js 0.0% -0.0% 277.3 KB 277.3 KB 47.94 KB 47.94 KB RN_FB_PROFILING

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactART-dev.js +0.1% +0.1% 614.81 KB 615.19 KB 128.27 KB 128.39 KB FB_WWW_DEV
react-art.development.js 0.0% +0.1% 670.29 KB 670.62 KB 145.56 KB 145.67 KB UMD_DEV
react-art.production.min.js 0.0% -0.0% 106.83 KB 106.83 KB 32.5 KB 32.49 KB UMD_PROD
react-art.development.js +0.1% +0.1% 600.97 KB 601.29 KB 128.15 KB 128.26 KB NODE_DEV
react-art.production.min.js 0.0% -0.0% 71.78 KB 71.78 KB 21.64 KB 21.64 KB NODE_PROD

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js 0.0% -0.0% 123.16 KB 123.16 KB 38.74 KB 38.74 KB NODE_PROFILING
react-dom-server.browser.development.js 0.0% -0.0% 137.73 KB 137.73 KB 36.6 KB 36.6 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 20.47 KB 20.47 KB 7.5 KB 7.5 KB UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 54.5 KB 54.5 KB 15.32 KB 15.32 KB UMD_DEV
ReactDOMServer-prod.js 0.0% 0.0% 49.02 KB 49.02 KB 11.19 KB 11.19 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.88 KB 3.88 KB 1.55 KB 1.55 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.1% 11.18 KB 11.18 KB 4.15 KB 4.15 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.3% 1.21 KB 1.21 KB 712 B 710 B UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 52.77 KB 52.77 KB 14.99 KB 14.99 KB NODE_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.71 KB 3.71 KB 1.5 KB 1.5 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 10.95 KB 10.95 KB 4.09 KB 4.09 KB NODE_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.3% 1.05 KB 1.05 KB 643 B 641 B NODE_PROD
react-dom.development.js 0.0% +0.1% 948.97 KB 949.29 KB 214.69 KB 214.79 KB UMD_DEV
react-dom.production.min.js 0.0% -0.0% 119.18 KB 119.18 KB 38.29 KB 38.29 KB UMD_PROD
react-dom.profiling.min.js 0.0% -0.0% 122.92 KB 122.92 KB 39.52 KB 39.51 KB UMD_PROFILING
react-dom.development.js 0.0% +0.1% 943.03 KB 943.35 KB 212.96 KB 213.08 KB NODE_DEV
react-dom-server.node.development.js 0.0% -0.0% 134.77 KB 134.77 KB 35.81 KB 35.81 KB NODE_DEV
react-dom-server.node.production.min.js 0.0% -0.0% 20.8 KB 20.8 KB 7.63 KB 7.63 KB NODE_PROD
ReactDOM-dev.js 0.0% +0.1% 970.82 KB 971.2 KB 215.93 KB 216.04 KB FB_WWW_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 20.39 KB 20.39 KB 7.47 KB 7.47 KB NODE_PROD
ReactDOM-prod.js 0.0% -0.0% 392.95 KB 392.95 KB 71.97 KB 71.97 KB FB_WWW_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.91 KB 60.91 KB 16.07 KB 16.07 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.23 KB 10.23 KB 3.47 KB 3.47 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.61 KB 60.61 KB 16 KB 15.99 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 4.42 KB 4.42 KB 1.65 KB 1.65 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 9.97 KB 9.97 KB 3.37 KB 3.37 KB NODE_PROD
ReactDOMServer-dev.js 0.0% -0.0% 139.4 KB 139.4 KB 35.43 KB 35.43 KB FB_WWW_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.3% 1.21 KB 1.21 KB 699 B 697 B NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler-persistent.development.js +0.1% +0.1% 599.42 KB 599.75 KB 126.2 KB 126.31 KB NODE_DEV
react-reconciler-reflection.development.js 0.0% -0.0% 19.27 KB 19.27 KB 6.33 KB 6.33 KB NODE_DEV
react-reconciler-persistent.production.min.js 0.0% -0.0% 72.09 KB 72.09 KB 21.24 KB 21.24 KB NODE_PROD
react-reconciler-reflection.production.min.js 0.0% -0.2% 2.86 KB 2.86 KB 1.24 KB 1.24 KB NODE_PROD
react-reconciler.development.js +0.1% +0.1% 601.97 KB 602.29 KB 127.31 KB 127.42 KB NODE_DEV
react-reconciler.production.min.js 0.0% -0.0% 74.79 KB 74.79 KB 21.91 KB 21.91 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: -0.0%

React: size: 0.0%, gzip: -0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against ff93a34

@sizebot
Copy link

sizebot commented Jan 18, 2020

Details of bundled changes.

Comparing: 29b4d07...ff93a34

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js +0.9% +0.8% 112.27 KB 113.28 KB 28.73 KB 28.96 KB UMD_DEV
react.production.min.js 0.0% -0.0% 12.33 KB 12.33 KB 4.84 KB 4.84 KB UMD_PROD
react.profiling.min.js 0.0% -0.0% 15.85 KB 15.85 KB 5.94 KB 5.94 KB UMD_PROFILING
react.development.js +1.4% +1.3% 71.78 KB 72.8 KB 19.06 KB 19.31 KB NODE_DEV

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFabric-dev.js +0.1% +0.1% 734.01 KB 734.39 KB 155.4 KB 155.52 KB RN_OSS_DEV
ReactNativeRenderer-dev.js +0.1% +0.1% 743.39 KB 743.77 KB 157.62 KB 157.73 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 0.0% -0.0% 273.39 KB 273.39 KB 47.01 KB 47 KB RN_OSS_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.1% +0.1% 601.96 KB 602.28 KB 127.31 KB 127.42 KB NODE_DEV
react-reconciler.production.min.js 0.0% -0.0% 72.06 KB 72.06 KB 21.23 KB 21.23 KB NODE_PROD
react-reconciler-reflection.development.js 0.0% -0.0% 19.25 KB 19.25 KB 6.33 KB 6.33 KB NODE_DEV
react-reconciler-reflection.production.min.js 0.0% -0.1% 2.85 KB 2.85 KB 1.24 KB 1.24 KB NODE_PROD
react-reconciler-persistent.development.js +0.1% +0.1% 599.41 KB 599.73 KB 126.19 KB 126.31 KB NODE_DEV

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-server.browser.production.min.js 0.0% -0.0% 19.94 KB 19.94 KB 7.4 KB 7.39 KB NODE_PROD
react-dom-test-utils.development.js 0.0% -0.0% 52.76 KB 52.76 KB 14.99 KB 14.99 KB NODE_DEV
react-dom.production.min.js 0.0% -0.0% 115.35 KB 115.35 KB 37.18 KB 37.17 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.59 KB 60.59 KB 15.99 KB 15.99 KB NODE_DEV
react-dom.profiling.min.js 0.0% -0.0% 118.98 KB 118.98 KB 38.36 KB 38.36 KB UMD_PROFILING
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 9.96 KB 9.96 KB 3.37 KB 3.36 KB NODE_PROD
react-dom.development.js 0.0% +0.1% 943.01 KB 943.33 KB 212.94 KB 213.05 KB NODE_DEV
react-dom.production.min.js 0.0% -0.0% 115.41 KB 115.41 KB 36.54 KB 36.54 KB NODE_PROD
react-dom.profiling.min.js 0.0% -0.0% 119.18 KB 119.18 KB 37.66 KB 37.66 KB NODE_PROFILING
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.3% 1.2 KB 1.2 KB 704 B 702 B UMD_PROD
react-dom-server.browser.development.js 0.0% -0.0% 137.71 KB 137.71 KB 36.6 KB 36.6 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.7 KB 3.7 KB 1.5 KB 1.49 KB NODE_DEV
react-dom-test-utils.development.js 0.0% -0.0% 54.48 KB 54.48 KB 15.31 KB 15.31 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.3% 1.04 KB 1.04 KB 635 B 633 B NODE_PROD
react-dom-test-utils.production.min.js 0.0% -0.0% 11.17 KB 11.17 KB 4.14 KB 4.14 KB UMD_PROD
react-dom-test-utils.production.min.js 0.0% 0.0% 10.94 KB 10.94 KB 4.08 KB 4.08 KB NODE_PROD
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 4.4 KB 4.4 KB 1.64 KB 1.64 KB NODE_DEV
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.89 KB 60.89 KB 16.06 KB 16.06 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.3% 1.2 KB 1.2 KB 691 B 689 B NODE_PROD
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.22 KB 10.22 KB 3.47 KB 3.47 KB UMD_PROD
react-dom.development.js 0.0% +0.1% 948.95 KB 949.27 KB 214.66 KB 214.77 KB UMD_DEV

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.production.min.js 0.0% -0.0% 104.33 KB 104.33 KB 31.8 KB 31.8 KB UMD_PROD
react-art.development.js 0.0% +0.1% 670.27 KB 670.59 KB 145.55 KB 145.67 KB UMD_DEV
react-art.development.js +0.1% +0.1% 600.95 KB 601.27 KB 128.14 KB 128.25 KB NODE_DEV
react-art.production.min.js 0.0% -0.0% 69.33 KB 69.33 KB 20.96 KB 20.96 KB NODE_PROD

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer-shallow.development.js 0.0% -0.0% 37.81 KB 37.81 KB 9.8 KB 9.8 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% -0.0% 11.64 KB 11.64 KB 3.59 KB 3.59 KB UMD_PROD
react-test-renderer-shallow.development.js 0.0% -0.0% 32.35 KB 32.35 KB 8.49 KB 8.49 KB NODE_DEV
react-test-renderer-shallow.production.min.js 0.0% -0.0% 11.78 KB 11.78 KB 3.7 KB 3.7 KB NODE_PROD
react-test-renderer.development.js +0.1% +0.1% 615.3 KB 615.62 KB 131.16 KB 131.28 KB UMD_DEV
react-test-renderer.production.min.js 0.0% -0.0% 71.48 KB 71.48 KB 21.89 KB 21.89 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.1% 610.57 KB 610.89 KB 129.98 KB 130.09 KB NODE_DEV
react-test-renderer.production.min.js 0.0% -0.0% 71.17 KB 71.17 KB 21.51 KB 21.51 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: -0.0%

React: size: 0.0%, gzip: -0.0%

Size changes (stable)

Generated by 🚫 dangerJS against ff93a34

mixedRef,
getStackByFiberInDevAndProd(returnFiber),
);
if (
Copy link
Collaborator

@sebmarkbage sebmarkbage Jan 18, 2020

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(
Copy link
Collaborator

@sebmarkbage sebmarkbage Jan 18, 2020

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 ' +
Copy link
Collaborator

@sebmarkbage sebmarkbage Jan 18, 2020

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

@lunaruan lunaruan force-pushed the string_ref_warn branch 2 times, most recently from 75a0552 to d8a2020 Compare January 21, 2020 21:57
Copy link
Collaborator

@sebmarkbage sebmarkbage left a 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.

'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. ' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*We ask

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants