Skip to content
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

Enable ESlint rules for React Hooks #6651

Merged
merged 20 commits into from
May 13, 2024
Merged

Enable ESlint rules for React Hooks #6651

merged 20 commits into from
May 13, 2024

Conversation

VIKTORVAV99
Copy link
Member

@VIKTORVAV99 VIKTORVAV99 commented Apr 9, 2024

Issue

Closes: AVO-172

Description

Preview

Double check

  • I have tested my parser changes locally with poetry run test_parser "zone_key"
  • I have run pnpx prettier@2 --write . and poetry run format in the top level directory to format my changes.

@VIKTORVAV99
Copy link
Member Author

Turns out we hade quite few hook violations...

I'll fix them after #6263 is merged as they have a lot of overlap in the files they change.

@VIKTORVAV99 VIKTORVAV99 added the techdebt Unpleasantness that does (or may in future) affect development label Apr 9, 2024
Copy link
Collaborator

@tonypls tonypls left a comment

Choose a reason for hiding this comment

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

Thanks for taking on this one 💚

Looks really good, couple of small fixes:

  1. Solar layer can get stuck on
  2. The line on the charts that previous followed the selectedDatetime is now missing

This was quite a big PR 😅, could have been nice to isolate the hooks fixes from other fixes but overall very nice 🙌

web/src/api/getWeatherData.ts Show resolved Hide resolved
web/src/components/Accordion.tsx Outdated Show resolved Hide resolved
web/src/features/map/Map.tsx Show resolved Hide resolved
@@ -93,7 +93,7 @@ export default function SolarLayer({ map }: { map?: maplibregl.Map }) {
map.removeSource('solar');
}
};
}, [map, node, isVisibleReference.current]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe without this reference the solar lay can get stuck on

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added it back but ESlint throws a warning now:

React Hook useEffect has an unnecessary dependency: 'isVisibleReference.current'. Either exclude it or remove the dependency array. Mutable values like 'isVisibleReference.current' aren't valid dependencies because mutating them doesn't re-render the component.

However since it's just a warning we can adress it later.

@VIKTORVAV99
Copy link
Member Author

Thanks for taking on this one 💚

Looks really good, couple of small fixes:

  1. Solar layer can get stuck on

  2. The line on the charts that previous followed the selectedDatetime is now missing

This was quite a big PR 😅, could have been nice to isolate the hooks fixes from other fixes but overall very nice 🙌

They are all hook fixes (if we include the dependency arrays) 😅

Fix one thing and it complains about the next, it's all pretty simple but deep issues though.

I'll take a look at the solar layer and selectedDatetime though.

@@ -93,7 +93,7 @@
map.removeSource('solar');
}
};
}, [map, node, isVisibleReference.current]);
}, [map, node, setIsLoadingSolarLayer, isVisibleReference.current]);

Check warning

Code scanning / ESLint

verifies the list of dependencies for Hooks like useEffect and similar Warning

React Hook useEffect has an unnecessary dependency: 'isVisibleReference.current'. Either exclude it or remove the dependency array. Mutable values like 'isVisibleReference.current' aren't valid dependencies because mutating them doesn't re-render the component.
Copy link
Member Author

Choose a reason for hiding this comment

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

Solar layer don't appears to be working correctly without it. We should address that in another PR.

@VIKTORVAV99
Copy link
Member Author

I can't really figure out how to make the Estimation cards do what we want with these new restrictions without significant changes.

We could restore them and skip the changes in here, ESlint would error in this PR but let other PRs pass in the future. We would have to change how earthly works though as it also run ESLint for some reason?

@tonypls
Copy link
Collaborator

tonypls commented Apr 30, 2024

I can't really figure out how to make the Estimation cards do what we want with these new restrictions without significant changes.

We could restore them and skip the changes in here, ESlint would error in this PR but let other PRs pass in the future. We would have to change how earthly works though as it also run ESLint for some reason?

Could we address the fixes that don't require significant changes then turn the ESLint rule off until we want to address them?

@VIKTORVAV99
Copy link
Member Author

I can't really figure out how to make the Estimation cards do what we want with these new restrictions without significant changes.
We could restore them and skip the changes in here, ESlint would error in this PR but let other PRs pass in the future. We would have to change how earthly works though as it also run ESLint for some reason?

Could we address the fixes that don't require significant changes then turn the ESLint rule off until we want to address them?

We could, but then we run the risk of reintroducing some of them, but might be worth it anyway?

I would keep all the changes except for the estimation card stuff if we were to do this.

@tonypls
Copy link
Collaborator

tonypls commented Apr 30, 2024

I can't really figure out how to make the Estimation cards do what we want with these new restrictions without significant changes.
We could restore them and skip the changes in here, ESlint would error in this PR but let other PRs pass in the future. We would have to change how earthly works though as it also run ESLint for some reason?

Could we address the fixes that don't require significant changes then turn the ESLint rule off until we want to address them?

We could, but then we run the risk of reintroducing some of them, but might be worth it anyway?

I would keep all the changes except for the estimation card stuff if we were to do this.

It's a nice improvement even without the rule enabled. Yeah I think that's a logical split on what to include. Is it possible to exclude a line or file from the linting?

@VIKTORVAV99
Copy link
Member Author

It is, so we could also do that, which is probably preferable.

@VIKTORVAV99
Copy link
Member Author

VIKTORVAV99 commented May 2, 2024

Oh god now this PR have the same issue as #6697 ...

I'll try and fix it in that PR directly then we can hopefully merge this.

@tonypls
Copy link
Collaborator

tonypls commented May 13, 2024

Let me know when this needs review again 🚀

@VIKTORVAV99
Copy link
Member Author

Let me know when this needs review again 🚀

It does! (unless you want me to merge it without one 😉)
You are all listed for pending reviews.

Copy link
Collaborator

@tonypls tonypls left a comment

Choose a reason for hiding this comment

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

LGTM!

@VIKTORVAV99 VIKTORVAV99 merged commit 07900c0 into master May 13, 2024
21 checks passed
@VIKTORVAV99 VIKTORVAV99 deleted the vik/react_hook_rules branch May 13, 2024 09:54
@madsnedergaard
Copy link
Member

Kudos for getting this one through and making the codebase a better place ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend 🎨 techdebt Unpleasantness that does (or may in future) affect development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants