Skip to content

Commit 34155bc

Browse files
authored
fix: Handle vite:preloadError for graceful deployment asset updates (#6609)
## Summary - Implement graceful handling of Vite preload errors that occur when assets are deleted after new deployments - Auto-reload when safe (no unsaved changes), show confirmation dialog when user has unsaved work - Add i18n support for user-friendly error messages ## Implementation Details - Add `vite:preloadError` event listener in App.vue - Smart reload logic: check `app.vueAppReady` and `workflowStore.activeWorkflow?.isModified` - User confirmation dialog using existing `dialogService.confirm` - Comprehensive i18n keys for title and message ## Background This addresses the issue described in [Vite documentation](https://vite.dev/guide/build.html#load-error-handling) where users encounter import errors when hosting services delete old assets after new deployments. [screen-capture (1).webm](https://github.com/user-attachments/assets/beed3b8e-6f32-4288-a560-55da391a79a1) 🤖 Generated with [Claude Code](https://claude.ai/code) ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6609-fix-Handle-vite-preloadError-for-graceful-deployment-asset-updates-2a36d73d365081a0b3adeac9fcd1e1dc) by [Unito](https://www.unito.io)
1 parent 8849d54 commit 34155bc

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/App.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ import { computed, onMounted } from 'vue'
1616
1717
import GlobalDialog from '@/components/dialog/GlobalDialog.vue'
1818
import config from '@/config'
19+
import { t } from '@/i18n'
20+
import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
21+
import { app } from '@/scripts/app'
22+
import { useDialogService } from '@/services/dialogService'
1923
import { useWorkspaceStore } from '@/stores/workspaceStore'
2024
import { useConflictDetection } from '@/workbench/extensions/manager/composables/useConflictDetection'
2125
2226
import { electronAPI, isElectron } from './utils/envUtil'
2327
2428
const workspaceStore = useWorkspaceStore()
2529
const conflictDetection = useConflictDetection()
30+
const workflowStore = useWorkflowStore()
31+
const dialogService = useDialogService()
2632
const isLoading = computed<boolean>(() => workspaceStore.spinner)
2733
const handleKey = (e: KeyboardEvent) => {
2834
workspaceStore.shiftDown = e.shiftKey
@@ -48,6 +54,26 @@ onMounted(() => {
4854
document.addEventListener('contextmenu', showContextMenu)
4955
}
5056
57+
// Handle Vite preload errors (e.g., when assets are deleted after deployment)
58+
window.addEventListener('vite:preloadError', async (_event) => {
59+
// Auto-reload if app is not ready or there are no unsaved changes
60+
if (!app.vueAppReady || !workflowStore.activeWorkflow?.isModified) {
61+
window.location.reload()
62+
} else {
63+
// Show confirmation dialog if there are unsaved changes
64+
await dialogService
65+
.confirm({
66+
title: t('g.vitePreloadErrorTitle'),
67+
message: t('g.vitePreloadErrorMessage')
68+
})
69+
.then((confirmed) => {
70+
if (confirmed) {
71+
window.location.reload()
72+
}
73+
})
74+
}
75+
})
76+
5177
// Initialize conflict detection in background
5278
// This runs async and doesn't block UI setup
5379
void conflictDetection.initializeConflictDetection()

src/locales/en/main.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
"comfy": "Comfy",
4141
"refresh": "Refresh",
4242
"refreshNode": "Refresh Node",
43+
"vitePreloadErrorTitle": "New Version Available",
44+
"vitePreloadErrorMessage": "A new version of the app has been released. Would you like to reload?\nIf not, some parts of the app might not work as expected.\nFeel free to decline and save your progress before reloading.",
4345
"terminal": "Terminal",
4446
"logs": "Logs",
4547
"videoFailedToLoad": "Video failed to load",

0 commit comments

Comments
 (0)