-
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
Data: Fix ESLint warnings for the 'useSelect' hook #55916
Conversation
Size Change: +655 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
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.
() => Store( registry, suspense ), | ||
[ registry, suspense ] | ||
); | ||
// 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.
🤔 Why do we run into yet another ESLint warning here? Is it because ESLint thinks mapSelect
needs to be part of the deps
too? If that's the case, should we add a comment explaining why this is alright?
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.
While technically valid, this pattern confuses ESList React hook rules. Even when you have something like the code below, you still get the following warning - React Hook useCallback was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.
.
I'll try to come up with a short explanation and include the reason for disabling.
function useFauxSelect( deps ) {
return useCallback( () => {}, 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.
@tyxla, what do you think about something like this?
These are "pass-through" dependencies from the parent hook,
and the parent should catch any hook rule violations.
P.S. There's probably a React/technical term for a similar pattern, but I couldn't find one 😅
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 think this is well described 👍 I can think of other ways to say it, but they are less direct, while your suggestion immediately clicked.
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.
Thanks for double-checking!
const store = useMemo( () => Store( registry, suspense ), [ registry ] ); | ||
const store = useMemo( | ||
() => Store( registry, suspense ), | ||
[ registry, suspense ] |
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.
👍
Flaky tests detected in 9fed8e4. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6785722981
|
What?
PR fixes
react-hooks/exhaustive-deps
warnings for theuseSelect
hook.Why?
I had to patch the hooks a few times last week for debugging and noticed the ESLint warnings that can be easily fixed.
How?
suspense
is a boolean that won't change during the runtime. It's safe to pass it to the dependency array.selector
callback warnings, as arguments come from the main hook and will adhere to the same rules.Testing Instructions
CI checks should be green.