@@ -138,23 +138,47 @@ export const useListParams = ({
138138 // the categories products on the demo), we need to persist them in the
139139 // store as well so that we don't lose them after a redirection back
140140 // to the list
141- useEffect ( ( ) => {
142- if ( disableSyncWithLocation ) {
143- return ;
144- }
145- if (
146- ! isEqual ( query , queryFromLocation ) &&
147- Object . keys ( queryFromLocation ) . length === 0
148- ) {
141+ useEffect (
142+ ( ) => {
143+ if ( disableSyncWithLocation ) {
144+ return ;
145+ }
146+ const defaultParams = {
147+ filter : filterDefaultValues || { } ,
148+ page : 1 ,
149+ perPage,
150+ sort : sort . field ,
151+ order : sort . order ,
152+ } ;
153+ if (
154+ // The location params are not empty (we don't want to override them if provided)
155+ Object . keys ( queryFromLocation ) . length > 0 ||
156+ // or the stored params are different from the location params
157+ isEqual ( query , queryFromLocation ) ||
158+ // or the stored params are not different from the default params (to keep the URL simple when possible)
159+ isEqual ( query , defaultParams )
160+ ) {
161+ return ;
162+ }
149163 navigate ( {
150164 search : `?${ stringify ( {
151165 ...query ,
152166 filter : JSON . stringify ( query . filter ) ,
153167 displayedFilters : JSON . stringify ( query . displayedFilters ) ,
154168 } ) } `,
155169 } ) ;
156- }
157- } , [ disableSyncWithLocation , query , location . search ] ) ; // eslint-disable-line
170+ } ,
171+ // eslint-disable-next-line react-hooks/exhaustive-deps
172+ [
173+ navigate ,
174+ disableSyncWithLocation ,
175+ filterDefaultValues ,
176+ perPage ,
177+ sort ,
178+ query ,
179+ location . search ,
180+ ]
181+ ) ;
158182
159183 const changeParams = useCallback (
160184 action => {
0 commit comments