Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"

Copy link
Copy Markdown
Member

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 dependentChangeType to none. 🤦‍♀️ (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.)

}
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"
}
7 changes: 6 additions & 1 deletion packages/eslint-plugin/src/configs/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ const config = {
],
'react/no-string-refs': 'error',
'react/self-closing-comp': 'error',
'react-hooks/exhaustive-deps': 'error',
'react-hooks/exhaustive-deps': [
'error',
{
additionalHooks: 'useIsomorphicLayoutEffect',
},
],
'react-hooks/rules-of-hooks': 'error',

// airbnb or other config overrides (some temporary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const useCheckbox = (
if (inputRef.current) {
inputRef.current.indeterminate = isMixed;
}
}, [isMixed]);
}, [inputRef, isMixed]);

return state;
};
24 changes: 16 additions & 8 deletions packages/react-positioning/src/usePopper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

in this case you can keep handlePopperUpdate in the deps, since it is created with useEventCallback and will always be referentially stable

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
Expand Down
2 changes: 1 addition & 1 deletion packages/react-theme/src/themes/ColorRamp.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// @ts-nocheck

import * as React from 'react';
// eslint-disable-next-line import/no-extraneous-dependencies
import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
import { TinyColor } from '@ctrl/tinycolor';

Expand Down Expand Up @@ -35,6 +34,7 @@ export const ColorRampItem: React.FunctionComponent<ColorRampItemProps> = props

cssVar.current = props.value?.match(/^var\((.+)\)$/)?.[1];

// eslint-disable-next-line react-hooks/exhaustive-deps -- intended to run every render
useIsomorphicLayoutEffect(() => {
const computedStyle = window.getComputedStyle(divRef.current);
const elementColor = computedStyle.getPropertyValue('background-color');
Expand Down