diff --git a/polaris-react/src/utilities/use-index-resource-state.ts b/polaris-react/src/utilities/use-index-resource-state.ts index 014e1e211c5..7f9288141bf 100644 --- a/polaris-react/src/utilities/use-index-resource-state.ts +++ b/polaris-react/src/utilities/use-index-resource-state.ts @@ -54,6 +54,8 @@ export function useIndexResourceState( const [dirty, setDirty] = useState(false); const prevPreCheckedResourcesRef = useRef(preCheckedResources); + const initialSelectedResources = useRef(selectedResources); + const initialUnselectedResources = useRef(unselectedResources); useEffect(() => { if (!isEqual(prevPreCheckedResourcesRef.current, preCheckedResources)) { @@ -68,6 +70,16 @@ export function useIndexResourceState( } }, [dirty, preCheckedResources, unselectedResources]); + useEffect(() => { + if ( + dirty && + isEqual(initialSelectedResources.current, selectedResources) && + isEqual(initialUnselectedResources.current, unselectedResources) + ) { + setDirty(false); + } + }, [dirty, selectedResources, unselectedResources]); + useEffect(() => { return () => { setDirty(false);