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

ESLint: Remove explicit react-hooks/exhaustive-deps disabling #66461

Merged
merged 1 commit into from
Oct 25, 2024
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
Expand Up @@ -320,7 +320,6 @@ function BlockListBlock( {
name,
fontSizes || EMPTY_ARRAY
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
// It is crucial to keep the dependencies array minimal to prevent unnecessary calls that could negatively impact performance.
// JSON.stringify is used for the following purposes:
Expand All @@ -329,11 +328,8 @@ function BlockListBlock( {
// 2. To filter the attributes object, ensuring that only the relevant attributes (included in
// GlobalStylesContext.BLOCK_STYLE_ATTRIBUTES) are considered as dependencies. This reduces the likelihood of
// unnecessary useMemo calls when other, unrelated attributes change.
// eslint-disable-next-line react-hooks/exhaustive-deps
JSON.stringify( globalStyle ),
// eslint-disable-next-line react-hooks/exhaustive-deps
JSON.stringify( wrapperProps?.style ),
// eslint-disable-next-line react-hooks/exhaustive-deps
JSON.stringify(
Object.fromEntries(
Object.entries( attributes ?? {} ).filter( ( [ key ] ) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export function PatternCategoryPreviews( {
const { changePage } = pagingProps;

// Hide block pattern preview on unmount.
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect( () => () => onHover( null ), [] );

const onSetPatternSyncFilter = useCallback(
Expand Down
3 changes: 1 addition & 2 deletions packages/block-editor/src/components/list-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ function ListViewComponent(
if ( selectedClientIds?.length ) {
focusListItem( selectedClientIds[ 0 ], elementRef?.current );
}
// Disable reason: Only focus on the selected item when the list view is mounted.
// eslint-disable-next-line react-hooks/exhaustive-deps
// Only focus on the selected item when the list view is mounted.
}, [] );

const expand = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ export function RichTextWrapper(
selectionChangeEnd
);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[ clientId, identifier ]
);

Expand Down Expand Up @@ -368,7 +367,6 @@ export function RichTextWrapper(
onChange( insert( value, '\n' ) );
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[
onReplace,
onSplit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export default function useBlockDropZone( {
const getSortedBlocksLayouts = useCallback( () => {
return getBlockLayoutsOrderedByYCoord( blocksLayouts.current );
// We use the value of `blocksLayouts` as the dependency.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ blocksLayouts.current ] );

const isRTL = getSettings().isRTL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ function useMovingAnimation( { triggerAnimationOnChange, clientId } ) {
previous: ref.current && getAbsolutePosition( ref.current ),
prevRect: ref.current && ref.current.getBoundingClientRect(),
} ),
// eslint-disable-next-line react-hooks/exhaustive-deps
[ triggerAnimationOnChange ]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export function useSettings( ...paths ) {
clientId,
...paths
),
// eslint-disable-next-line react-hooks/exhaustive-deps
[ clientId, ...paths ]
);
}
Expand Down
1 change: 0 additions & 1 deletion packages/block-editor/src/hooks/contrast-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default function BlockColorContrastChecker( { clientId } ) {

// There are so many things that can change the color of a block
// So we perform this check on every render.
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect( () => {
if ( ! blockEl ) {
return;
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/src/cover/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ function CoverEdit( {
isUserOverlayColor: isUserOverlayColor || false,
} );
} )();
// Disable reason: Update the block only when the featured image changes.
// eslint-disable-next-line react-hooks/exhaustive-deps
// Update the block only when the featured image changes.
}, [ mediaUrl ] );

// instead of destructuring the attributes
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/src/file/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) {
downloadButtonText: _x( 'Download', 'button label' ),
} );
}
// Reason: This effect should only run on mount.
// eslint-disable-next-line react-hooks/exhaustive-deps
// This effect should only run on mount.
}, [] );

function onSelectFile( newMedia ) {
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/social-links/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export function SocialLinksEdit( props ) {
} else {
setAttributes( { ...backgroundBackupRef.current } );
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ logosOnly ] );

const SocialPlaceholder = (
Expand Down
1 change: 0 additions & 1 deletion packages/data/src/components/use-select/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ function useMappingSelect( suspense, mapSelect, deps ) {

// These are "pass-through" dependencies from the parent hook,
// and the parent should catch any hook rule violations.
// eslint-disable-next-line react-hooks/exhaustive-deps
const selector = useCallback( mapSelect, deps );
const { subscribe, getValue } = store( selector, isAsync );
const result = useSyncExternalStore( subscribe, getValue, getValue );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ function useNavigateToPreviousEntityRecord() {
previousLocation?.params.canvas === 'edit';
const showBackButton = isFocusMode && didComeFromEditorCanvas;
return showBackButton ? () => history.back() : undefined;
// Disable reason: previousLocation changes when the component updates for any reason, not
// `previousLocation` changes when the component updates for any reason, not
// just when location changes. Until this is fixed we can't add it to deps. See
// https://github.com/WordPress/gutenberg/pull/58710#discussion_r1479219465.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ location, history ] );
return goBack;
}
Expand Down
1 change: 0 additions & 1 deletion packages/edit-site/src/components/layout/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ function useMovingAnimation( { triggerAnimationOnChange } ) {
previous: ref.current && getAbsolutePosition( ref.current ),
prevRect: ref.current && ref.current.getBoundingClientRect(),
} ),
// eslint-disable-next-line react-hooks/exhaustive-deps
[ triggerAnimationOnChange ]
);

Expand Down
1 change: 0 additions & 1 deletion packages/edit-site/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export default function Layout( { route } ) {
toggleRef.current?.focus();
}
// Should not depend on the previous canvas mode value but the next.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ canvas ] );

return (
Expand Down
1 change: 0 additions & 1 deletion packages/edit-widgets/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ function SidebarContent( {
// We're intentionally leaving `currentArea` and `isGeneralSidebarOpen`
// out of the dep array because we want this effect to run based on
// block selection changes, not sidebar state changes.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ hasSelectedNonAreaBlock, enableComplementaryArea ] );

const tabsContextValue = useContext( Tabs.Context );
Expand Down
Loading