Skip to content

Added invariant for null/undefined create in useEffect, useLayoutEffect #15197

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

Closed
wants to merge 8 commits into from
Closed

Added invariant for null/undefined create in useEffect, useLayoutEffect #15197

wants to merge 8 commits into from

Conversation

JoshuaKGoldberg
Copy link
Contributor

I considered putting this somewhere closer to where create is used, but also wanted the complaint to be specific to the function & parameter name...

Fixes #15194.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@JoshuaKGoldberg
Copy link
Contributor Author

okie dokie, following up now...

image

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@sizebot
Copy link

sizebot commented Mar 22, 2019

Details of bundled changes.

Comparing: 5c2b2c0...6c0fb09

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js +0.3% +0.2% 101.38 KB 101.67 KB 26.3 KB 26.35 KB UMD_DEV
react.development.js +0.5% +0.3% 63.92 KB 64.22 KB 17.2 KB 17.25 KB NODE_DEV
React-dev.js +0.6% +0.4% 62.31 KB 62.69 KB 16.53 KB 16.59 KB FB_WWW_DEV

Generated by 🚫 dangerJS

@gaearon
Copy link
Collaborator

gaearon commented Mar 23, 2019

We try to avoid DEV-only invariants because they can lead to inconsistent behavior between dev and prod. Ideally we would throw right before it would throw anyway. In that case maybe it’s accepable.

@JoshuaKGoldberg
Copy link
Contributor Author

@gaearon I'm not super sure if there's a change you wanted, but I'm interpreting that to mean that this should remove the if (__DEV__)? Applied in the latest commit 😄

@acdlite
Copy link
Collaborator

acdlite commented Mar 25, 2019

Could you make it a dev-only warning, instead of an invariant? The idea is to avoid an extra check in production, and to make sure the behavior is consistent across dev and prod.

@JoshuaKGoldberg
Copy link
Contributor Author

@acdlite sure - how would you like me to do that? I'm not familiar with the terminology here; does a dev-only warning mean using the warning from shared/warming?

@alexanderkjeldaas
Copy link

#15369 is somewhat related to more error checking, but for the return value.

@stale
Copy link

stale bot commented Jan 10, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 10, 2020
@JoshuaKGoldberg
Copy link
Contributor Author

Oh, I forgot about this! I'll tackle it soon. 🚀

@stale stale bot removed the Resolution: Stale Automatically closed due to inactivity label Jan 10, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 11, 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 236385b:

Sandbox Source
festive-joliot-9u8p4 Configuration

@sizebot
Copy link

sizebot commented Jan 11, 2020

Details of bundled changes.

Comparing: 64aae7b...236385b

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js +0.4% +0.3% 112.29 KB 112.75 KB 28.73 KB 28.83 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-prod.js 0.0% 0.0% 18.01 KB 18.01 KB 4.69 KB 4.69 KB FB_WWW_PROD
React-profiling.js 0.0% 0.0% 18.01 KB 18.01 KB 4.69 KB 4.69 KB FB_WWW_PROFILING
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 +0.6% +0.5% 71.8 KB 72.27 KB 19.06 KB 19.16 KB NODE_DEV
react.production.min.js 0.0% 🔺+0.1% 6.96 KB 6.96 KB 2.86 KB 2.86 KB NODE_PROD
React-dev.js +0.7% +0.6% 72.29 KB 72.78 KB 18.41 KB 18.51 KB FB_WWW_DEV

React: size: 0.0%, gzip: 0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against 236385b

@sizebot
Copy link

sizebot commented Jan 11, 2020

Details of bundled changes.

Comparing: 64aae7b...236385b

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js +0.4% +0.3% 112.27 KB 112.73 KB 28.73 KB 28.82 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.development.js +0.6% +0.5% 71.78 KB 72.25 KB 19.05 KB 19.15 KB NODE_DEV
react.production.min.js 0.0% 0.0% 6.54 KB 6.54 KB 2.72 KB 2.72 KB NODE_PROD

React: size: 0.0%, gzip: 0.0%

Size changes (stable)

Generated by 🚫 dangerJS against 236385b

@JoshuaKGoldberg
Copy link
Contributor Author

Mmhh, no, I don't have time to push this through. Best of wishes!

poteto added a commit that referenced this pull request Feb 11, 2025
## Summary

Fixes #32354.

Re-creation of #15197: adds a dev-only warning if `create == null` to
the three `use*Effect` functions:

* `useEffect`
* `useInsertionEffect`
* `useLayoutEffect`

Updates the warning to match the same text given in the
`react/exhaustive-deps` lint rule.

## How did you test this change?

I applied the changes manually within `node_modules/` on a local clone
of
https://github.com/JoshuaKGoldberg/repros/tree/react-use-effect-no-arguments.

Please pardon me for opening a PR addressing a not-accepted issue. I was
excited to get back to #15194 -> #15197 now that I have time. 🙂

---------

Co-authored-by: lauren <[email protected]>
github-actions bot pushed a commit that referenced this pull request Feb 11, 2025
## Summary

Fixes #32354.

Re-creation of #15197: adds a dev-only warning if `create == null` to
the three `use*Effect` functions:

* `useEffect`
* `useInsertionEffect`
* `useLayoutEffect`

Updates the warning to match the same text given in the
`react/exhaustive-deps` lint rule.

## How did you test this change?

I applied the changes manually within `node_modules/` on a local clone
of
https://github.com/JoshuaKGoldberg/repros/tree/react-use-effect-no-arguments.

Please pardon me for opening a PR addressing a not-accepted issue. I was
excited to get back to #15194 -> #15197 now that I have time. 🙂

---------

Co-authored-by: lauren <[email protected]>

DiffTrain build for [192555b](192555b)
github-actions bot pushed a commit that referenced this pull request Feb 11, 2025
## Summary

Fixes #32354.

Re-creation of #15197: adds a dev-only warning if `create == null` to
the three `use*Effect` functions:

* `useEffect`
* `useInsertionEffect`
* `useLayoutEffect`

Updates the warning to match the same text given in the
`react/exhaustive-deps` lint rule.

## How did you test this change?

I applied the changes manually within `node_modules/` on a local clone
of
https://github.com/JoshuaKGoldberg/repros/tree/react-use-effect-no-arguments.

Please pardon me for opening a PR addressing a not-accepted issue. I was
excited to get back to #15194 -> #15197 now that I have time. 🙂

---------

Co-authored-by: lauren <[email protected]>

DiffTrain build for [192555b](192555b)
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.

Better error message when useEffect is called with no parameters
6 participants