mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
improvement(ux): skip reload warning for sync on auth routes
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = ''
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user