Skip to content

Make useEffect(async) warning more verbose #14327

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

Merged
merged 2 commits into from
Nov 27, 2018

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Nov 26, 2018

Adds a more detailed message. People still get tripped over this:

New message:

screen shot 2018-11-26 at 3 53 12 pm

@sizebot
Copy link

sizebot commented Nov 26, 2018

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

Details of bundled changes.

Comparing: a7f270c...ea1a9f4

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js 0.0% +0.1% 718.19 KB 718.54 KB 166.16 KB 166.31 KB UMD_DEV
react-dom.production.min.js 0.0% -0.0% 97.79 KB 97.79 KB 31.84 KB 31.84 KB UMD_PROD
react-dom.profiling.min.js 0.0% -0.0% 100.68 KB 100.68 KB 32.52 KB 32.52 KB UMD_PROFILING
react-dom.development.js 0.0% +0.1% 713.5 KB 713.86 KB 164.79 KB 164.94 KB NODE_DEV
react-dom.production.min.js 0.0% -0.0% 97.79 KB 97.79 KB 31.38 KB 31.37 KB NODE_PROD
react-dom.profiling.min.js 0.0% -0.0% 100.78 KB 100.78 KB 31.97 KB 31.97 KB NODE_PROFILING
ReactDOM-dev.js +0.1% +0.1% 734.44 KB 734.95 KB 165.75 KB 165.91 KB FB_WWW_DEV
ReactDOM-prod.js 0.0% -0.0% 308.33 KB 308.33 KB 56.8 KB 56.79 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% -0.0% 44.87 KB 44.87 KB 12.3 KB 12.3 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.1% 9.97 KB 9.97 KB 3.71 KB 3.71 KB UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 44.59 KB 44.59 KB 12.24 KB 12.24 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.1% 9.74 KB 9.74 KB 3.65 KB 3.64 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.61 KB 60.61 KB 15.92 KB 15.92 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 11.01 KB 11.01 KB 3.81 KB 3.81 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.29 KB 60.29 KB 15.79 KB 15.79 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.75 KB 10.75 KB 3.71 KB 3.71 KB NODE_PROD
react-dom-server.browser.development.js 0.0% -0.0% 124.26 KB 124.26 KB 33.1 KB 33.1 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 16.99 KB 16.99 KB 6.53 KB 6.52 KB UMD_PROD
react-dom-server.browser.development.js 0.0% -0.0% 120.39 KB 120.39 KB 32.17 KB 32.17 KB NODE_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 16.9 KB 16.9 KB 6.52 KB 6.52 KB NODE_PROD
ReactDOMServer-dev.js 0.0% 0.0% 121.65 KB 121.65 KB 31.82 KB 31.82 KB FB_WWW_DEV
react-dom-server.node.development.js 0.0% -0.0% 122.42 KB 122.42 KB 32.7 KB 32.7 KB NODE_DEV
react-dom-server.node.production.min.js 0.0% -0.0% 17.76 KB 17.76 KB 6.83 KB 6.83 KB NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.1% +0.1% 498.59 KB 498.95 KB 110 KB 110.16 KB UMD_DEV
react-art.production.min.js 0.0% -0.0% 89.96 KB 89.96 KB 27.65 KB 27.65 KB UMD_PROD
react-art.development.js +0.1% +0.2% 430.34 KB 430.7 KB 92.95 KB 93.09 KB NODE_DEV
react-art.production.min.js 0.0% -0.0% 54.93 KB 54.93 KB 16.99 KB 16.98 KB NODE_PROD
ReactART-dev.js +0.1% +0.2% 438.11 KB 438.63 KB 91.89 KB 92.05 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% 562.82 KB 563.33 KB 122.43 KB 122.6 KB RN_FB_DEV
ReactNativeRenderer-prod.js 0.0% -0.0% 238.97 KB 238.97 KB 42.01 KB 42.01 KB RN_FB_PROD
ReactNativeRenderer-dev.js +0.1% +0.1% 562.52 KB 563.03 KB 122.35 KB 122.51 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 0.0% -0.0% 224.33 KB 224.33 KB 38.96 KB 38.96 KB RN_OSS_PROD
ReactFabric-dev.js +0.1% +0.1% 553.33 KB 553.84 KB 120 KB 120.17 KB RN_FB_DEV
ReactFabric-dev.js +0.1% +0.1% 553.36 KB 553.88 KB 120.02 KB 120.18 KB RN_OSS_DEV
ReactFabric-prod.js 0.0% -0.0% 218.51 KB 218.51 KB 37.71 KB 37.71 KB RN_OSS_PROD
ReactFabric-profiling.js 0.0% -0.0% 223.27 KB 223.27 KB 39.12 KB 39.12 KB RN_OSS_PROFILING

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.2% 443.03 KB 443.38 KB 95.65 KB 95.8 KB UMD_DEV
react-test-renderer.development.js +0.1% +0.2% 438.24 KB 438.6 KB 94.5 KB 94.64 KB NODE_DEV
react-test-renderer.production.min.js 0.0% -0.0% 55.82 KB 55.82 KB 17.09 KB 17.08 KB NODE_PROD
ReactTestRenderer-dev.js +0.1% +0.2% 446.12 KB 446.63 KB 93.71 KB 93.87 KB FB_WWW_DEV
react-test-renderer-shallow.development.js 0.0% -0.0% 25.79 KB 25.79 KB 7.04 KB 7.04 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% -0.1% 7.28 KB 7.28 KB 2.38 KB 2.37 KB UMD_PROD
react-test-renderer-shallow.development.js 0.0% -0.0% 20.18 KB 20.18 KB 5.61 KB 5.61 KB NODE_DEV
react-test-renderer-shallow.production.min.js 0.0% -0.0% 7.96 KB 7.96 KB 2.64 KB 2.64 KB NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.1% +0.2% 428.17 KB 428.53 KB 91.45 KB 91.6 KB NODE_DEV
react-reconciler.production.min.js 0.0% -0.0% 56.05 KB 56.05 KB 16.82 KB 16.82 KB NODE_PROD
react-reconciler-persistent.development.js +0.1% +0.2% 426.62 KB 426.98 KB 90.8 KB 90.95 KB NODE_DEV
react-reconciler-persistent.production.min.js 0.0% -0.0% 56.06 KB 56.06 KB 16.82 KB 16.82 KB NODE_PROD
react-reconciler-reflection.development.js 0.0% -0.0% 15.4 KB 15.4 KB 4.84 KB 4.83 KB NODE_DEV
react-reconciler-reflection.production.min.js 0.0% -0.1% 2.56 KB 2.56 KB 1.13 KB 1.13 KB NODE_PROD

Generated by 🚫 dangerJS

'supported, but you can call an async function inside an ' +
'effect.'
? '\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. ' +
'Instead, you may write an async function separately, ' +
Copy link
Collaborator

Choose a reason for hiding this comment

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

no comma after separately please

'and then call it from inside the effect:\n\n' +
'async function fetchComment(commentId) {\n' +
' // You can await here\n' +
'}\n\n' +
Copy link
Contributor

Choose a reason for hiding this comment

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

More of a question: would it be better to write this function inside the effect callback instead?

Supposedly, the engine would only have to evaluate the function declaration when the effect callback is called, but I'm not sure it'd help anyway as it'd still have to create the shared closure object.

At any rate, writing it outside the component entirely would definitely be better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't really have an opinion on this but it's nice to show it doesn't have to be inside.

@gaearon gaearon merged commit f93f340 into facebook:master Nov 27, 2018
jetoneza pushed a commit to jetoneza/react that referenced this pull request Jan 23, 2019
* Make useEffect(async) warning more verbose

* Nit
n8schloss pushed a commit to n8schloss/react that referenced this pull request Jan 31, 2019
* Make useEffect(async) warning more verbose

* Nit
@alippai
Copy link

alippai commented Feb 7, 2019

Is there a tracking bug for data fetching solution (possibly with error handling / timeout included)? Just being curious whether it will fit other use-cases too e.g Fetch API streaming body or Web Worker postMessage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants