feat: Add diagnostic logging for tab focus issue

This commit is contained in:
gpt-engineer-app[bot]
2025-10-12 23:57:23 +00:00
parent f45a100648
commit e7aa74287a
2 changed files with 48 additions and 13 deletions

View File

@@ -335,16 +335,24 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
// Handle page visibility changes - only verify if inactive for >5 minutes
const handleVisibilityChange = () => {
const timeSinceLastCheck = Date.now() - lastVisibilityVerificationRef.current;
const FIVE_MINUTES = 5 * 60 * 1000;
console.log('🔐 [AUTH] Visibility changed', {
state: document.visibilityState,
timeSinceLastCheck: Math.round(timeSinceLastCheck / 1000) + 's',
willVerifySession: document.visibilityState === 'visible' && timeSinceLastCheck > FIVE_MINUTES
});
if (document.visibilityState === 'visible') {
const timeSinceLastCheck = Date.now() - lastVisibilityVerificationRef.current;
const FIVE_MINUTES = 5 * 60 * 1000;
if (timeSinceLastCheck > FIVE_MINUTES) {
authLog('[Auth] Tab visible after 5+ minutes, verifying session');
console.log(' ⚠️ Verifying session - this may cause component re-renders');
lastVisibilityVerificationRef.current = Date.now();
verifySession();
} else {
authLog('[Auth] Tab visible, session recently verified, skipping');
console.log(' ✅ Session recently verified, skipping verification');
}
}
};