From a10859079a65049e660a5482d9e73dcfbed316df Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Sat, 6 Jun 2026 19:47:44 +0200 Subject: [PATCH] Do not refresh profiles grid when going back to it without any filter change --- backend/api/src/get-profiles.ts | 2 +- web/components/profiles/profiles-home.tsx | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/api/src/get-profiles.ts b/backend/api/src/get-profiles.ts index 7123776e..e219197a 100644 --- a/backend/api/src/get-profiles.ts +++ b/backend/api/src/get-profiles.ts @@ -675,7 +675,7 @@ export const loadProfiles = async (props: profileQueryType) => { const profiles = await pg.map(query, [], convertRow) - console.debug('profiles:', profiles) + // console.debug('profiles:', profiles) const countQuery = renderSql(select(`count(*) as count`), ...tableSelection, ...filters) diff --git a/web/components/profiles/profiles-home.tsx b/web/components/profiles/profiles-home.tsx index 3b8f6b77..9d205b9f 100644 --- a/web/components/profiles/profiles-home.tsx +++ b/web/components/profiles/profiles-home.tsx @@ -2,6 +2,7 @@ import {debug} from 'common/logger' import {Profile} from 'common/profiles/profile' import {removeNullOrUndefinedProps} from 'common/util/object' import {DAY_MS} from 'common/util/time' +import {isEqual} from 'lodash' import {useRouter} from 'next/router' import {useCallback, useEffect, useRef, useState} from 'react' import toast from 'react-hot-toast' @@ -51,6 +52,10 @@ export function ProfilesHome() { undefined, 'profiles', ) + const [getProfilesArgs, setGetProfilesArgs] = usePersistentInMemoryState( + undefined, + 'get-profiles-args', + ) const [profileCount, setProfileCount] = usePersistentInMemoryState( undefined, 'profile-count', @@ -96,19 +101,23 @@ export function ProfilesHome() { setProfileCount(0) return } - setIsReloading(true) - const current = ++id.current const args = removeNullOrUndefinedProps({ limit: 20, compatibleWithUserId: user?.id, locale, ...filters, }) - debug('Refreshing profiles, filters:', args) + if (!!profiles?.length && isEqual(getProfilesArgs, args)) { + return + } + setIsReloading(true) + const current = ++id.current + debug('Refreshing profiles. Filters:', args) api('get-profiles', args as any) .then(({profiles, count}) => { if (current === id.current) { setProfiles(profiles) + setGetProfilesArgs(args) setProfileCount(count) } }) @@ -134,6 +143,7 @@ export function ProfilesHome() { return false } if (!profiles || isLoadingMore) return false + debug('Loading more profiles. Current:', profiles.length) if (fromSignup && isClearedFilters && sendScrollWarning) { setSendScrollWarning(false) toast(