From ff1166cfa3872d6a268fdca76b00f5df9822ed95 Mon Sep 17 00:00:00 2001 From: Emir Karabeg Date: Thu, 10 Apr 2025 00:43:36 -0700 Subject: [PATCH] improvement(ux): skip reload warning for sync on auth routes --- sim/stores/index.ts | 9 +++++++++ sim/stores/sync.ts | 9 +++++++++ sim/stores/workflows/persistence.ts | 13 ++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/sim/stores/index.ts b/sim/stores/index.ts index 06fc4e3607..810554abcb 100644 --- a/sim/stores/index.ts +++ b/sim/stores/index.ts @@ -118,6 +118,15 @@ function initializeWorkflowState(workflowId: string): void { * Handle application cleanup before unload */ function handleBeforeUnload(event: BeforeUnloadEvent): void { + // Check if we're on an authentication page and skip confirmation if we are + if (typeof window !== 'undefined') { + const path = window.location.pathname; + // Skip confirmation for auth-related pages + if (path === '/login' || path === '/signup' || path === '/reset-password' || path === '/verify') { + return; + } + } + // 1. Persist current state const currentId = useWorkflowRegistry.getState().activeWorkflowId if (currentId) { diff --git a/sim/stores/sync.ts b/sim/stores/sync.ts index ddc2356795..d20b09921c 100644 --- a/sim/stores/sync.ts +++ b/sim/stores/sync.ts @@ -89,6 +89,15 @@ export function initializeSyncSystem(): () => void { } const handleBeforeUnload = (event: BeforeUnloadEvent) => { + // Check if we're on an authentication page and skip confirmation if we are + if (typeof window !== 'undefined') { + const path = window.location.pathname; + // Skip confirmation for auth-related pages + if (path === '/login' || path === '/signup' || path === '/reset-password' || path === '/verify') { + return; + } + } + // Find managers that need exit sync const exitSyncManagers = Array.from(syncManagerRegistry.values()).filter( (manager) => manager.config.syncOnExit diff --git a/sim/stores/workflows/persistence.ts b/sim/stores/workflows/persistence.ts index bae15c20a3..490ac27423 100644 --- a/sim/stores/workflows/persistence.ts +++ b/sim/stores/workflows/persistence.ts @@ -140,7 +140,14 @@ export function initializeStores(): void { export function setupUnloadPersistence(): void { if (typeof window === 'undefined') return - window.addEventListener('beforeunload', () => { + window.addEventListener('beforeunload', (event) => { + // Check if we're on an authentication page and skip confirmation if we are + const path = window.location.pathname; + // Skip confirmation for auth-related pages + if (path === '/login' || path === '/signup' || path === '/reset-password' || path === '/verify') { + return; + } + const currentId = useWorkflowRegistry.getState().activeWorkflowId if (currentId) { // Save workflow state @@ -166,5 +173,9 @@ export function setupUnloadPersistence(): void { // Save registry saveRegistry(useWorkflowRegistry.getState().workflows) + + // Only prevent navigation on non-auth pages + event.preventDefault() + event.returnValue = '' }) }