Fix UI loop when sorting by random without seed (#6167)

This commit is contained in:
WithoutPants
2025-10-22 11:31:42 +11:00
committed by GitHub
parent 71e4071871
commit 947a17355c

View File

@@ -24,6 +24,7 @@ export function useFilterURL(
const history = useHistory(); const history = useHistory();
const location = useLocation(); const location = useLocation();
const prevLocation = usePrevious(location);
// when the filter changes, update the URL // when the filter changes, update the URL
const updateFilter = useCallback( const updateFilter = useCallback(
@@ -47,7 +48,8 @@ export function useFilterURL(
// and updates the filter accordingly. // and updates the filter accordingly.
useEffect(() => { useEffect(() => {
// don't apply if active is false // don't apply if active is false
if (!active) return; // also don't apply if location is unchanged
if (!active || prevLocation === location) return;
// re-init to load default filter on empty new query params // re-init to load default filter on empty new query params
if (!location.search) { if (!location.search) {
@@ -73,7 +75,8 @@ export function useFilterURL(
}); });
}, [ }, [
active, active,
location.search, prevLocation,
location,
defaultFilter, defaultFilter,
setFilter, setFilter,
updateFilter, updateFilter,