-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Enable the exhaustive-deps lint rule for useIsomorphicLayoutEffect #19169
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
Changes from all commits
c82ff6d
e7ee698
6ed8348
7fbad9b
dc1ab99
44c3e7d
c55f5ff
3fa5238
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "Enable exhaustive-deps rule for useIsomorphicLayoutEffect", | ||
| "packageName": "@fluentui/eslint-plugin", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "Fix issues flagged by the exhaustive-deps rule in useCheckbox", | ||
| "packageName": "@fluentui/react-checkbox", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "Fix issues flagged by the exhaustive-deps rule in usePopper", | ||
| "packageName": "@fluentui/react-positioning", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "Enable exhaustive-deps rule for useIsomorphicLayoutEffect", | ||
| "packageName": "@fluentui/react-theme", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -388,14 +388,22 @@ export function usePopper( | |
| popperInstanceRef.current?.destroy(); | ||
| popperInstanceRef.current = null; | ||
| }; | ||
| }, [options.enabled, options.target]); | ||
| useIsomorphicLayoutEffect(() => { | ||
| if (!isFirstMount) { | ||
| popperInstanceRef.current?.setOptions( | ||
| resolvePopperOptions(options.target || targetRef.current, containerRef.current, arrowRef.current), | ||
| ); | ||
| } | ||
| }, [resolvePopperOptions]); | ||
| }, [handlePopperUpdate, options.enabled, options.target]); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At a glance these look like cases where the omission of certain deps may be intentional, but it's hard for me to say since I'm not familiar with popper. So @ling1726 should definitely take another look at this before you merge.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, yes I was planning to ping @ling1726 once the build was working in case there were other errors (I guess I wasn't seeing them locally because the lint results were cached and it didn't get invalidated when I changed the config). Anyways, as far as I can tell, most of the omissions were probably intentional since (some) of these never change between renders. But it's also harmless to add them as deps in that case. I'll add a comment on the next one below since that does have some deps that could change functionality.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in this case you can keep |
||
| useIsomorphicLayoutEffect( | ||
| () => { | ||
| if (!isFirstMount) { | ||
| popperInstanceRef.current?.setOptions( | ||
| resolvePopperOptions(options.target || targetRef.current, containerRef.current, arrowRef.current), | ||
| ); | ||
| } | ||
| }, | ||
| // Missing deps: | ||
| // options.target - The useIsomorphicLayoutEffect before this will create a new popper instance if target changes | ||
| // isFirstMount - Should never change after mount | ||
| // arrowRef, containerRef, targetRef - Stable between renders | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| [resolvePopperOptions], | ||
| ); | ||
|
|
||
| if (process.env.NODE_ENV !== 'production') { | ||
| // This checked should run only in development mode | ||
|
|
||
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.
Largely a note to self, but also if you happen to do a lint plugin change again...I think to avoid the deluge of unnecessary version bumps (since this is only ever a dev dep), it would be a good idea to manually set
dependentChangeTypetonone. 🤦♀️ (Not saying you did anything wrong, you just happened upon a case I hadn't thought about in awhile which makes some tooling limitations obvious.)