Line data Source code
1 : <template>
2 : <TooltipProvider>
3 : <router-view />
4 : <GlobalDialog />
5 : <SessionReconnecting v-if="isCloud" />
6 : </TooltipProvider>
7 : <div
8 : v-show="isLoading"
9 : data-testid="app-loading-overlay"
10 : class="fixed inset-0 z-blocking bg-black/10"
11 : :aria-busy="isLoading"
12 : />
13 : </template>
14 :
15 : <script setup lang="ts">
16 : import { useEventListener } from '@vueuse/core'
17 : import { computed, onMounted, watch } from 'vue'
18 :
19 : import GlobalDialog from '@/components/dialog/GlobalDialog.vue'
20 : import { useAgentExtensionNotices } from '@/composables/useAgentExtensionNotices'
21 : import config from '@/config'
22 : import TooltipProvider from '@comfyorg/design-system/tooltip/TooltipProvider'
23 : import SessionReconnecting from '@/platform/auth/session/components/SessionReconnecting.vue'
24 : import { isCloud, isDesktop } from '@/platform/distribution/types'
25 : import {
26 : reportPreloadError,
27 : reportPreloadErrorUnlessExtensionImport,
28 : reportResourceLoadError
29 : } from '@/platform/telemetry/assetLoadErrorReporting'
30 : import { app } from '@/scripts/app'
31 : import { registerExtensionDialogService } from '@/services/dialogService'
32 : import { createExtensionDialogService } from '@/services/extensionDialogService'
33 : import { useWorkspaceStore } from '@/stores/workspaceStore'
34 : import { electronAPI } from '@/utils/envUtil'
35 : import { parsePreloadError } from '@/utils/preloadErrorUtil'
36 : import { useConflictDetection } from '@/platform/customNodes/manager/composables/useConflictDetection'
37 :
38 2355 : registerExtensionDialogService(createExtensionDialogService())
39 2355 : const workspaceStore = useWorkspaceStore()
40 2355 : app.extensionManager = useWorkspaceStore()
41 :
42 2355 : const conflictDetection = useConflictDetection()
43 2355 : useAgentExtensionNotices()
44 2355 : const isLoading = computed<boolean>(() => workspaceStore.spinner)
45 :
46 2355 : watch(
47 : isLoading,
48 : (loading, prevLoading) => {
49 4786 : if (prevLoading && !loading) {
50 2393 : document.getElementById('splash-loader')?.remove()
51 : }
52 : },
53 : { flush: 'post' }
54 : )
55 :
56 : const showContextMenu = (event: MouseEvent) => {
57 : const { target } = event
58 : switch (true) {
59 : case target instanceof HTMLTextAreaElement:
60 : case target instanceof HTMLInputElement && target.type === 'text':
61 : // TODO: Context input menu explicitly for text input
62 : electronAPI()?.showContextMenu({ type: 'text' })
63 : return
64 : }
65 : }
66 :
67 2355 : onMounted(() => {
68 2355 : window['__COMFYUI_FRONTEND_VERSION__'] = config.app_version
69 :
70 : if (isDesktop) {
71 : document.addEventListener('contextmenu', showContextMenu)
72 : }
73 :
74 : // Handle preload errors that occur during dynamic imports (e.g., stale chunks after deployment)
75 : // See: https://vite.dev/guide/build#load-error-handling
76 2355 : useEventListener(window, 'vite:preloadError', (event) => {
77 0 : if (parsePreloadError(event.payload).url === null) {
78 0 : reportPreloadErrorUnlessExtensionImport(event.payload)
79 0 : return
80 : }
81 0 : event.preventDefault()
82 0 : reportPreloadError(event.payload)
83 : // No toast: third-party custom node extensions frequently trigger this
84 : // (e.g., bare "vue" imports, wrong relative paths to scripts/app.js, missing
85 : // core dependencies). These are plugin bugs, not ComfyUI core failures, but
86 : // the generic error message alarms users and offers no actionable guidance.
87 : // The reporter above still logs the details for developers to debug.
88 : })
89 :
90 : // Capture resource load failures (CSS, scripts) in non-localhost distributions
91 : if (__DISTRIBUTION__ !== 'localhost') {
92 : window.addEventListener(
93 : 'error',
94 : (event) => {
95 : const target = event.target
96 : if (target instanceof HTMLScriptElement) {
97 : reportResourceLoadError(target.src, 'script')
98 : } else if (
99 : target instanceof HTMLLinkElement &&
100 : target.rel === 'stylesheet'
101 : ) {
102 : reportResourceLoadError(target.href, 'link')
103 : }
104 : },
105 : true
106 : )
107 : }
108 :
109 : // Initialize conflict detection in background
110 : // This runs async and doesn't block UI setup
111 2355 : void conflictDetection.initializeConflictDetection()
112 : })
113 : </script>
|