perf: Optimize profile data fetching by preventing re-showing loading spinner and unnecessary re-fetches on subsequent session changes.
This commit is contained in:
@@ -54,12 +54,17 @@ export function ProfileSettingsForm({
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
// Store original data for cancel/reset functionality
|
||||
const [originalData, setOriginalData] = useState<typeof formData | null>(null);
|
||||
// Track if initial profile fetch is done to avoid re-showing loading spinner
|
||||
const hasFetchedRef = useRef(false);
|
||||
|
||||
// Fetch profile data on mount based on user role
|
||||
useEffect(() => {
|
||||
const fetchProfile = async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
// Only show loading spinner on initial fetch, not on session-triggered re-fetches
|
||||
if (!hasFetchedRef.current) {
|
||||
setIsLoading(true);
|
||||
}
|
||||
const role = (session?.user as any)?.role;
|
||||
|
||||
if (role === 'AGENT') {
|
||||
@@ -122,10 +127,13 @@ export function ProfileSettingsForm({
|
||||
}
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
hasFetchedRef.current = true;
|
||||
}
|
||||
};
|
||||
|
||||
if (session) {
|
||||
// Skip re-fetching on session changes after initial load (e.g. after updateSession in handleSave)
|
||||
if (hasFetchedRef.current) return;
|
||||
fetchProfile();
|
||||
}
|
||||
}, [session]);
|
||||
|
||||
Reference in New Issue
Block a user