Skip to content

Commit 0303d90

Browse files
[backport rh-test] fix: Handle vite:preloadError for graceful deployment asset updates (#6616)
Backport of #6609 to `rh-test` Automatically created by backport workflow. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6616-backport-rh-test-fix-Handle-vite-preloadError-for-graceful-deployment-asset-updates-2a36d73d365081ba813fca8d72492cac) by [Unito](https://www.unito.io) Co-authored-by: Jin Yi <[email protected]>
1 parent be942fb commit 0303d90

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
@@ -49,6 +55,26 @@ onMounted(() => {
4955
document.addEventListener('contextmenu', showContextMenu)
5056
}
5157
58+
// Handle Vite preload errors (e.g., when assets are deleted after deployment)
59+
window.addEventListener('vite:preloadError', async (_event) => {
60+
// Auto-reload if app is not ready or there are no unsaved changes
61+
if (!app.vueAppReady || !workflowStore.activeWorkflow?.isModified) {
62+
window.location.reload()
63+
} else {
64+
// Show confirmation dialog if there are unsaved changes
65+
await dialogService
66+
.confirm({
67+
title: t('g.vitePreloadErrorTitle'),
68+
message: t('g.vitePreloadErrorMessage')
69+
})
70+
.then((confirmed) => {
71+
if (confirmed) {
72+
window.location.reload()
73+
}
74+
})
75+
}
76+
})
77+
5278
// Initialize conflict detection in background
5379
// This runs async and doesn't block UI setup
5480
void conflictDetection.initializeConflictDetection()

src/locales/en/main.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"logoAlt": "ComfyUI Logo",
2828
"refresh": "Refresh",
2929
"refreshNode": "Refresh Node",
30+
"vitePreloadErrorTitle": "New Version Available",
31+
"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.",
3032
"terminal": "Terminal",
3133
"logs": "Logs",
3234
"videoFailedToLoad": "Video failed to load",

0 commit comments

Comments
 (0)