-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Make eslint-plugin validate dependencies in useSelect
and useSuspenseSelect
hooks
#49900
Make eslint-plugin validate dependencies in useSelect
and useSuspenseSelect
hooks
#49900
Conversation
The Static Analysis GitHub Actions failed because it has an ESLint error with a It is an ESLint error, not a warning, because it is set to Lines 353 to 364 in 7b8395e
|
That's a very unusual use of the cc @WordPress/native-mobile |
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.
I made an additional code change to fix the eslint error for now. See below.
// Disable eslint rule for now, to avoid introducing a regression | ||
// (see https://github.com/WordPress/gutenberg/pull/23922#discussion_r1170634879). | ||
// eslint-disable-next-line react-hooks/exhaustive-deps |
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.
As per #23922 (comment), I have temporarily disabled eslint rule for this line to suppress eslint error for now.
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.
Disabling the linter error on mobile-specific violations has been done in the past. I think this makes sense in this case to unblock this PR. Thanks for the ping!
Hi fellow reviewers @dcalhoun @gziolo @ntwb @nerrad @ajitbohra , may I have your review and approval on this PR please? 🙏 |
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.
Looks good to me. I don't see any new errors popping up when running linting JS locally and agree this should remain a warning for now in most contexts (although in general I think we should move towards this being an error for all hooks with dependency args at some point).
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.
LGTM. I did a quick test of the mobile Demo editor using an iPhone 14 Pro simulator, I did not encounter any issues. 🚀
Thanks again for involving the mobile team! 🙇🏻
@nerrad @dcalhoun , thanks so much for the approval. Apparently I am not authorized to merge the PR (see screenshot below). Are you able to grant me the permission? I made a request in WordPress Slack to join the Gutenberg github team last week. Or perhaps you could help to merge this? |
@ecgan I just realized, one thing that is missing here is an update to the eslint plugin changelog. Will you submit a followup to take care of that please? |
@nerrad , sure, I'll take care of that. Thank you for checking on it. 🙂 🙏 |
@nerrad @ecgan would it make sense to have a similar setup as the one used in the flaky test reporter to report open I'm not sure if it's worth it, but I can take a stab at it if this problem is something that comes up often enough and if tracking it would indeed be helpful (I'm not sure if it'd help or just be annoying :) ) |
🤔 I think it depends on how many issues would get created - I see the flaky test-reported issues do get handled but there are also quite a few older ones still lingering around. Probably a good first step would be to see how many warnings exist in the codebase and if small enough, try to fix them in one (or a set of) PR(s). |
yea @nerrad - I got a little overwhelmed by warnings (106 by react-hooks/exhaustive-deps) so I figured it may be a big enough issue that it makes sense for it to be tracked, but I'm not familiar enough yet with how things are handled in Gutenberg to really know if that's "normal" or common enough. The downside of such a tool may be accidentally incentivizing "leaving warnings for later" as a behavior instead of incentivizing fixing them promptly. edit: of course, right now we're more in the "leave it for later" situation since warnings are non-blocking for a merge. |
What?
Closes #49897. Builds on top of PR #24914 that was just merged recently in February 2023.
In this PR, we add
useSelect
anduseSuspenseSelect
as additional hooks in'react-hooks/exhaustive-deps'
eslint rule in eslint-plugin.Why?
This helps us to declare all the dependencies when we use
useSelect
anduseSuspenseSelect
hooks. When we miss a dependency, there will be an eslint warning. It allows us to make use of the editor's quick fix command to quickly fix the dependency issue.Testing Instructions
useSelect
hook with dependency. For example:gutenberg/packages/block-library/src/search/edit.js
Lines 83 to 93 in 361f257
clientId
in the dependency array: