Guard against empty-filter fetch on mount and premature URL sync

The lastFetchParamsRef starts as undefined, so the initial debounce
would have fetched with an empty filter (returning every entity in
the catalog). Guard against this by skipping the fetch when no filter
components have registered yet.

Also skip the URL sync effect until at least one filter has been set,
to avoid briefly clearing filter query params from the URL bar before
filter components initialize.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2026-05-20 17:57:33 +02:00
parent 4694eb16e3
commit 779749fbd7
@@ -301,6 +301,13 @@ export const EntityListProvider = <EntityFilters extends DefaultEntityFilters>(
};
}
// No filters registered yet — wait for filter components to
// call updateFilters before making the first request.
if (compacted.length === 0 && lastFetchParamsRef.current === undefined) {
setLoading(false);
return;
}
if (isEqual(fetchParams, lastFetchParamsRef.current)) {
return;
}
@@ -351,7 +358,7 @@ export const EntityListProvider = <EntityFilters extends DefaultEntityFilters>(
// to replace the state rather than pushing, since we don't want
// there to be back/forward slots for every single filter change.
useEffect(() => {
if (!isMounted()) {
if (!isMounted() || Object.keys(requestedFilters).length === 0) {
return;
}
const queryParams = Object.keys(requestedFilters).reduce((params, key) => {