Skip to content

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

Merged

Conversation

amorimr
Copy link
Contributor

@amorimr amorimr commented Sep 15, 2022

PR Checklist

Overview

  • Enables the react-hooks/exhaustive-deps eslint rules in the website package.
  • Fixes warnings in the package

@nx-cloud
Copy link

nx-cloud bot commented Sep 15, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 507c7a5. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 40 targets

Sent with 💌 from NxCloud.

@typescript-eslint
Copy link
Contributor

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.

@netlify
Copy link

netlify bot commented Sep 15, 2022

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 507c7a5
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/63339d0210ae8c00073bf332
😎 Deploy Preview https://deploy-preview-5663--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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
Copy link
Contributor Author

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").

Comment on lines +88 to +96
const onLoaded = useCallback(
(ruleNames: RuleDetails[], tsVersions: readonly string[]): void => {
setRuleNames(ruleNames);
setTSVersion(tsVersions);
setIsLoading(false);
},
[],
);

Copy link
Contributor Author

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;
Copy link
Contributor Author

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(
Copy link
Contributor Author

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

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a 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
Copy link

codecov bot commented Sep 25, 2022

Codecov Report

Merging #5663 (507c7a5) into main (84e316b) will increase coverage by 2.81%.
The diff coverage is n/a.

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     
Flag Coverage Δ
unittest 93.82% <ø> (+2.81%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/utils/src/eslint-utils/RuleCreator.ts
...-plugin/src/rules/restrict-template-expressions.ts
...ages/eslint-plugin/src/rules/unified-signatures.ts
...plugin/src/rules/explicit-module-boundary-types.ts
...s/eslint-plugin/src/rules/no-implicit-any-catch.ts
...int-plugin/src/rules/strict-boolean-expressions.ts
...es/eslint-plugin/src/rules/prefer-function-type.ts
packages/utils/src/ast-utils/helpers.ts
packages/utils/src/ts-eslint-scope/ScopeManager.ts
.../eslint-plugin/src/rules/prefer-ts-expect-error.ts
... and 221 more

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a 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]);
Copy link
Member

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

Copy link
Contributor Author

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.

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Sep 27, 2022
useEffect(
debounce(() => {
useEffect(() => {
const lintEditor = debounce(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated this hook because otherwise ESLint cannot parse correctly its dependencies and throws a warning. The functionality remains the same:

Screen Shot 2022-09-27 at 9 03 04 PM

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Swell, thanks! 🙌

@JoshuaKGoldberg JoshuaKGoldberg merged commit fab9974 into typescript-eslint:main Sep 28, 2022
@amorimr amorimr deleted the enable-react-exaustive-deps branch September 28, 2022 14:57
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2022
@armano2
Copy link
Collaborator

armano2 commented Jan 22, 2023

@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.

@JoshuaKGoldberg
Copy link
Member

🤔 @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 LoadedEditor & co. that IMO ideally should be more events-driven. What do you think?

@armano2
Copy link
Collaborator

armano2 commented Jan 28, 2023

ideally should be more events-driven. What do you think?

I agree,

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Repo: Enable react-hooks/exhaustive-deps in website ESLint config
3 participants