-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
chore(website): Enable react-hooks exhaustive deps rules #5663
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
chore(website): Enable react-hooks exhaustive deps rules #5663
Conversation
Thanks for the PR, @amorimr! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
@@ -22,7 +22,6 @@ module.exports = { | |||
'react/jsx-no-target-blank': 'off', | |||
'react/no-unescaped-entities': 'off', | |||
'@typescript-eslint/internal/prefer-ast-types-enum': 'off', | |||
'react-hooks/exhaustive-deps': 'off', // TODO: enable it later |
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.
Sets the rules to the default behaviour ("warn").
const onLoaded = useCallback( | ||
(ruleNames: RuleDetails[], tsVersions: readonly string[]): void => { | ||
setRuleNames(ruleNames); | ||
setTSVersion(tsVersions); | ||
setIsLoading(false); | ||
}, | ||
[], | ||
); | ||
|
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.
This small refactoring was necessary to fix an issue raised by updating one of the dependency arrays on useSandboxServices.ts:
Since the original onLoaded
was inlined, it was being recreated at every render, causing racing conditions on useSandboxServices
effects that crashed the page.
@@ -9,21 +9,23 @@ export interface PropertyNameProps { | |||
} | |||
|
|||
export default function PropertyName(props: PropertyNameProps): JSX.Element { | |||
const { onClick: onClickProps, onHover } = props; |
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.
Destructuring props to avoid stale values as suggested by: facebook/react#16265 (comment)
if (!checkboxRef.current) { | ||
return; | ||
} | ||
const checkboxRef = useCallback( |
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.
Small refactoring: Callback refs are generally the recommended way to interacting with the underlying DOM node:
https://reactjs.org/docs/hooks-faq.html#how-can-i-measure-a-dom-node
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, thanks for sending this in! My only note is that it's unfortunate how some of the deps arrays have so many entries. It'd be nice if we could split those up / reduce them a bit.
@armano2 has done a bunch of work on this so I'll defer approval to them if they have time to review. 🙂
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #5663 +/- ##
==========================================
+ Coverage 91.01% 93.82% +2.81%
==========================================
Files 365 134 -231
Lines 11962 1506 -10456
Branches 3483 226 -3257
==========================================
- Hits 10887 1413 -9474
+ Misses 781 60 -721
+ Partials 294 33 -261
Flags with carried forward coverage won't be shown. Click here to find out more. |
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.
Code looks great, thanks for sending this in! Just blocked on the introduced bug around AST property expansion.
@@ -47,7 +47,7 @@ export function ComplexItem({ | |||
if (selected && !isExpanded) { | |||
setIsExpanded(selected); | |||
} | |||
}, [selection, data]); | |||
}, [selection, data, level, isExpanded]); |
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.
Introduced bug somewhere around AST elements: you can no longer collapse an element that's visually focused.
See recording: the first 3/4 of time is in the deploy preview, where clicking a node in the source code to expand on the right, then trying to collapse, is not allowed.
Screen.Recording.2022-09-27.at.3.33.57.PM.mov
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.
Thank you for pointing it out. It should be fixed on commit 507c7a5.
useEffect( | ||
debounce(() => { | ||
useEffect(() => { | ||
const lintEditor = debounce(() => { |
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.
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.
Swell, thanks! 🙌
@JoshuaKGoldberg i missed this Pr, this change is not that great, there is alot of side effects and we are doing way to many updates now, eg, "constructor" and "destructor" is triggered way to often I noticed also that even if there are no changes to config or code we are triggering linting eg, when user resizes window, changes theme etc. |
🤔 @armano2 I'm not sold that we should completely revert this PR. #6335 is irksome and the excess linting is a little annoying, but I'm very hesitant to go against the rules of hooks. I think a larger issue with the playground code either way is that it sets up a lot of effects-driven logic in |
I agree, |
PR Checklist
Overview
react-hooks/exhaustive-deps
eslint rules in the website package.